I'm trying to plot Exact VS FEM solution for this equation:
I followed this code for example: Example Code
It's fine for its case, but in my case I don't know about how to get the triangulation (for my case) for this line:
x(1)=0; x(2)=0.1; x(3)=0.3; x(4)=0.333; x(5)=0.5; x(6)=0.75;x(7)=1;
Here is my code:
clear all; close all;
x(1)=0*pi; x(2)=0.1*pi; x(3)=0.3*pi; x(4)=0.333*pi; x(5)=0.5*pi; x(6)=0.75*pi;x(7)=1*pi;
U = fem1d(x);
x2 = 0:0.01:pi; k2 = length(x2);
for i=1:k2,
u_exact(i) = soln(x2(i));
u_fem(i) = fem_soln(x,U,x2(i));
end
error = norm(u_fem-u_exact,inf)
plot(x2,u_fem,':',x2,u_exact)
hold; plot(x,U,'o')
xlabel('x'); ylabel('u(x) & u_{fem}(x)');
title('Solid line: Exact solution, Dotted line: FEM solution')
figure(2); plot(x2,u_fem-u_exact); title('Error plot')
xlabel('x'); ylabel('u-u_{fem}'); title('Error plot')
How to generate the triangulation values? Does anyone know?
Thank you