How to calculate the errors for Finite Element Method for 1D Poisson equation?
14 次查看(过去 30 天)
显示 更早的评论
I have solved the 1D Poisson equation -u"(x) = sinx using the Finite Element Method over the period 0 to pi.
For n = 8 elements I got this as the (9x1) vector of nodal values:
[0; 0.3827; 0.7071; 0.9239; 1.0; 0.9239; 0.7071; 0.3827; 0]
For n = 16 elements I got this as the (17x1) vector of nodal values:
[0; 0.1951; 0.3827; 0.5556; 0.7071; 0.8315; 0.9239; 0.9808; 1.0; 0.9808; 0.9239; 0.8315; 0.7071; 0.5556; 0.3827; 0.1951; 0]
The Output is like this:
I have used xvec = linspace(0, pi, n+1) for the nodal points (1x9) vector. Now I want to calculate two error norms using the following formulas:
For the double absolute value i.e. norm, I am considering this
double( sqrt(int((error^2), x, 0, pi)) );
The output of errors should be like this in the loglog scale:
Can you help me out with this how to calculate and get the final plot? Thank you.
2 个评论
Torsten
2022-2-26
Hint:
The exact solution is u*(x) = sin(x).
To get a graph as shown, you will need more than two variations of the number of elements since you can always make a straight line through only two points.
回答(1 个)
Torsten
2022-2-26
编辑:Torsten
2022-2-26
You must use higher precision for the output of the solution because now, the solution with 16 elements is classified worse than the solution with 8 elements:
u8 = [0; 0.3827; 0.7071; 0.9239; 1.0; 0.9239; 0.7071; 0.3827; 0];
u16 = [0; 0.1951; 0.3827; 0.5556; 0.7071; 0.8315; 0.9239; 0.9808; 1.0; 0.9808; 0.9239; 0.8315; 0.7071; 0.5556; 0.3827; 0.1951; 0];
x8 = linspace(0,pi,numel(u8)).';
x16 = linspace(0,pi,numel(u16)).';
ustar8 = sin(x8);
ustar16 = sin(x16);
eps_nodal8 = norm(u8-ustar8)/norm(ustar8)
eps_nodal16 = norm(u16-ustar16)/norm(ustar16)
eps_L2_8 = trapz(x8,abs(u8-ustar8))
eps_L2_16 = trapz(x16,abs(u16-ustar16))
9 个评论
Torsten
2022-2-27
编辑:Torsten
2022-2-27
The expressions to evaluate must be calculated from the u_h values alone. If you used finite differences instead of finite elements, du_h/dx could be calculated as du_h/dx (xi) ~ (u_h(i+1)-u_h(i-1))/(x(i+1)-x(i-1)) for 2<=i<=n-1, du_h/dx(x1) = (u_h(2)-u_h(1))/(x(2)-x(1)), du_h(xn) = (u_h(n)-u_h(n-1))/(x(n)-x(n-1)). So an expression to compute eps_H1_8 would be
n8 = numel(u8);
x8 = linspace(0,pi,n8).';
du8 = [(u8(2)-u8(1))/(x8(2)-x8(1));(u8(3:n8)-u8(1:n8-2))./(x8(3:n8)-x8(1:n8-2));(u8(n8)-u8(n8-1))/(x8(n8)-x8(n8-1))];
dustar8 = cos(x8);
eps_H1_8 = sqrt(trapz(x8,(du8-dustar8).^2))
But I don't know how the first-order derivatives were approximated within the finite-element method you used. This method should be implemented to calculate du8.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!