Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

up vote 4 down vote accepted

If you use linear finite elements, then theory tells us that the $L^\infty$ error decreases as $$ \|e\|_{L^\infty} \le C \;h^2 \; |\log h| \; \|u\|_{H^2} $$ where $h$ is the mesh size. In fact, in 1d, the finite element approximation equals the interpolant of the solution, and so the error should even decay as $h^2$.

What I could imagine is that the definition above applies to the $L^\infty$ norm whereas you only evaluate it at the nodes. You should evaluate it at other points as well in order to get the real $L^\infty$ error. Do you see the correct error orders in the other norms?

share|improve this answer
    
I checked the $H^1$ and $L^2$ norms, which give orders of convergence $O(h)$ and $O(h^2)$, respectively. That is, the error decreases in both cases as $h\rightarrow 0$. This doesn't guarantee that my approximate solution is correct, but it's encouraging :) –  Paul Nov 2 '12 at 1:08
    
What's the magnitude of your $L^\infty$ error? If I'm right and the solution is simply the interpolant, then the $L^\infty$ error at the nodes where you evaluate should be zero, up to round-off and other numerical errors... –  Wolfgang Bangerth Nov 2 '12 at 2:14
2  
If you run Paul's code, the error for a small number of elements is ~1e-17 and it grows up to around 1e-11 for 10k elements. I think your suggestion to include the interiors of the elements is correct. The solution is probably the nodal interpolant, so the error will be higher inside the elements--and much higher for large h. I'd be surprised if this didn't compensate for everything. –  Bill Barth Nov 2 '12 at 12:07
    
Yes, that was exactly my suspicion. If the error is 1e-11, then it's zero. An increase from 1e-17 to 1e-11 is a change from zero to zero. –  Wolfgang Bangerth Nov 2 '12 at 12:31
    
So then, it is possible for the discrete $L^{\infty}$ error to increase while the overall (continuous) $L^{\infty}$ error decreases? At least, initially? –  Paul Nov 2 '12 at 16:13
show 5 more comments

Just to riff on Wolfgang's post, if on each element the error takes the form: $$ e_h(x)=x(1-x) -(a_h x +b_h) $$

then this error has its extreme value where its derivative is zero, i.e. at $$ x_h=\frac{1-a_h}{2} $$ Assuming I've done the math right, you ought to be able to evaluate the $L_\infty$ error without having to search each element for the maximum value of its error.

share|improve this answer
    
I'm not so sure about this... the approximate function is a linear combination of piecewise linear basis functions. I don't think this results in the linear function you describe as $(a_hx+b_h)$. –  Paul Nov 2 '12 at 13:47
    
It's linear inside each element. What else could it be? –  Bill Barth Nov 2 '12 at 13:56
    
Oh... I think I misread your explanation the first time... I was thinking this expression was over the entire interval instead of over each piecewise element. But you are correct: the maximum in each element should follow this formula. –  Paul Nov 2 '12 at 16:07
    
Right, which means that you can a) compute it exactly, and b) you can probably work backwards from the form of $a_h$ to see that this point is in the element interior. Given that, I think that Wolfgang is right to suggest that you compute the actual norm of the error. –  Bill Barth Nov 2 '12 at 19:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.