# Finite element error for second order ODE at nodes equal to zero

I coded a finite element method with linear basis elements for the problem $$-u'' = f(x), x\in[0,1], u(0) = u(1) = 0$$ The nodes are uniformly spaced and I will denote them as $x_i$. I initially calculated the error of my method as $$\text{error} = \max_i |u(x_i) - \hat{u}(x_i)|$$ where $\hat{u}$ denotes the FEM solution. I kept getting approximately 0 as the error, and I'm thinking that's because the FEM solution interpolates the exact solution $u$ at the nodes $x_i$.

I then went back and got an approximation for $$\max_{x\in[0,1]} |u(x) - \hat{u}(x)|$$ and I got second-order convergence (as expected).

My question is does the FEM (with linear/quadratic/cubic piecewise basis functions) always give back an interpolation of the exact solution, and so should I expect an error of zero at the nodes?

• What is the expression for $f(x)$? – Charles Jun 21 '16 at 2:12
• I too have observed FEM yielding slightly better accuracy than in the interior of the elements. It doesn't always happen, nor does it necessarily yield error within floating point precision when it does happen. I think bill barth is right in that it is a special circumstance that occaisionally happens in numerical computation called 'superconvergence'. I don't remember the precise reason why it happens. It may have sonething to do with the function f that you chose. What was f in this case? – Paul Jun 21 '16 at 2:17
• I tried a few different functions for $f$. First was $f\equiv 2$, which has the exact solution of $u(x) = (1-x)x$. Then I tried $f(x) = -e^x (x^4 + 6x^3 + x^2 - 8x + 2)$, which has an exact solution of $u(x) = e^x (1-x)^2 x^2$. For both of them, the error was somewhere around $10^{-14}$. – Kurt Jun 21 '16 at 2:38
• Yes, for this problem, the solution is exact at the nodes provided your integrals in the weak formulation are exact. This is a nice assignment/exam question. – cpraveen Jun 21 '16 at 3:50

Since it's such a nice homework problem, instead of the (simple) proof, here's a hint: Use the weak formulation with a hat function centered on $x_i$ as a test function, Galerkin orthogonality, and partial integration.