I'm working on an finite element code to solve the boundary value problem:
$$-\frac{d}{dx}\left[ k \frac{du}{dx} \right] = f $$ $$u(0)=u(1)=0$$ The matlab code is available here.
I'm testing this code in the case where $k=1$ and the exact solution is:
$$u(x) = x(1-x)$$
Hence,
$$f(x)=-ku''=2$$
Using this information, the stiffness matrix was created using piecewise linear basis functions (hat functions) and with equispaced nodes. Checking the plot of the graphs of the approximate and exact solutions, I see that they are encouragingly close to each other.
I also calculate the discrete $L^{\infty}$ norm error, according to the following formula:
$$||U_{exact}-U_{approx}||_{L^{\infty}}=max_{x_i} \{ U_{exact}(x_i)-U_{approx}(x_i)\}$$.
I tested this code varying the number of elements as $xnel=10,20,40,...$ (i.e. successive doubling). In doing so, I noticed that this error is actually increasing as the number of element increases (i.e. the size of each element decreases).
I've combed the code for mistakes, but I haven't found any thus far. Could it really be possible that the error in the discrete $L^{\infty}$ norm actually increases as the element size decreases?