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
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.
Fahmid Mahmud
Fahmid Mahmud 2022-2-26
Thank you for your comment.
I'm just trying to get the error calculation properly with just 2 elements, then I will increase the elements to get the final plot.
Any suggestions on calculating the two errors?

请先登录,再进行评论。

回答(1 个)

Torsten
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
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.
Fahmid Mahmud
Fahmid Mahmud 2022-3-1
I am stuck with the 2nd error, which is the L2 norm. Here I have to transform my u which is a (9x1) vector into a function (my instructor told me piece-wise linear) and get the difference between the function and the sine function. It has to be a function of x because I have to take the derivative of the difference between these 2 function to calculate the 3rd error, H1 norm.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by