# Solving 1D Poisson equation using finite element method and understanding the Galerkin orthogonality

Let's consider the following test problem $$u'' = 12x^2 - 36x + 18 \qquad u(0) = u(3) = 0$$

Analytical solution is $$u(x) = (x-3)^2 x^2$$

I'm solving this using the finite element method, discretizing the interval $$I = [0, 3]$$ to $$I_1 = [0, 2]$$ and $$I_2 = [2, 3]$$. So we have a linear basis function defined piecewise, $$v\left(x\right)=\begin{cases} \frac{1}{2}x & x\in I_{1}\\ 3-x & x\in I_{2}. \end{cases}$$

Weak form is $$\int u' v'\,\mathrm{d}x=\int fv\,\mathrm{d}x$$

If I denote the only unknown in the problem as $$u_2$$, this leads to the equation ($$k = \frac{1}{2}+1, f = 6 + 0$$) $$\frac{3}{2}u_{2}=6$$ and thus $$u_2 = 4$$. The exact function and it's FE approximation is visualized here.

The result makes sense.

According to Wikipedia, in the Galerkin method, the error between the function and solution is orthogonal to $$v_n$$:

$$a\left(u,v_{n}\right) - a\left(u_{n},v_{n}\right) = 0.$$

However, if I integrate the above, as a result, I get $$\frac{27}{20}$$. To satisfy this condition above, $$u_2$$ needs to be $$\frac{107}{20} = 5.35$$. This result is visualized here. It also makes somehow sense, because it looks like the approximation is minimizing the error with respect to the accurate solution.

The basic question is what is the right solution and why? What I'm missing here? For me, the both options somehow make sense. In the first solution (which I'm believing to be the right one), the approximation is exact in point $$x = 2$$, while on the other hand, another solution looks like it is minimizing the error to the accurate solution, making sense in the energy norm.

The first approximation is a simple interpolation method which tries to minimize the error in a collocative sense. There exists different point disbributions for which the error is quasi best considering (i) the $$L_{\infty}$$ norm or (ii) the Lebesgue constant or (iii) the condition number of the Vandermonde matrix.
The seconde approximation is a projection method which tries to minimize the error in an integral sense. Here the Galerkin approximation is quasi best considering an energy norm ($$L_2$$ based).
As an additional example the least squares approximation minimizes the $$L_2$$ norm.