# Finite Element Method for 1D Poisson Equation with Inhomogeneous Boundary Conditions

Im trying to solve the Poisson equation in 1D: $$-u_{xx} = f(x), \hspace{6mm} u(a) = d1, \hspace{2mm} u(b) = d2$$Assuming a uniform partition such that $$x_n = a + nh$$, where $$h = (b-a)/N$$ and $$n \in [0,N]$$, and then discretising the problem with linear finite elements to obtain a linear equation system $$\mathbf{A u} = \mathbf{f}$$. I Want to find the analytical expressions for $$\mathbf{A}$$ and $$\mathbf{f}$$.

I found the general expression for $$\mathbf{A}$$ before incorporating boundary conditions to be $$\mathbf{A} = \frac{1}{h}\begin{bmatrix} 1 & -1 & 0 & \ldots & \ldots & 0 \\ -1 & 2 & -1 & \ddots & & 0 \\ 0 & -1 & 2 & \ddots & \ddots & 0 \\ \vdots & \ddots & \ddots & \ddots & \ddots & 0 \\ \vdots & & \ddots & -1 & 2 & -1 \\ 0 & \ldots & \ldots & 0 & -1 & 1 \end{bmatrix}$$ and correspondingly for $$\mathbf{f}$$: $$\mathbf{f} = \big[\frac{1}{2}f(x_0), f(x_1), f(x_2), ... , \frac{1}{2}f(x_{N+1}) \big]^T$$ My trouble is with incorporating the inhomogeneous boundary conditions, I can't find any clear examples of how to do this online despite looking up a ton of sources. Is anyone able to help?

• You can change the first and last row so that $u_0 = d_1$ and $u_N=d_2$. Basically, just zero-out everything except the entries $(0,0)$ and $(N,N)$. Also, your r.h.s $f$ must be changed accordingly. – VoB Apr 8 at 12:01
• If you are only interested in some basic tests, then you can simply use the penalty method. Accordingly, you apply $u=u_s$, where $u_s$ is the specified value in a least-squares sense, i.e. $\Pi=\frac{1}{2} \alpha (u-us)^2$ with $\alpha$ as the penalty parameter. You need to use very high values ($>10^3$) for $\alpha$. – Chenna K Apr 8 at 22:39

## 1 Answer

If you want to know the why and the how, you probably want to watch lecture 21.65 here: https://www.math.colostate.edu/~bangerth/videos.html Which you probably want to do after you've watched lecture 21.6.

Disclaimer: I'm the one in these videos.