Eléments finis sur Matlab, comparaison de la solution approchée et l'exacte.
mars 27, 2019
Education
![]() |
Modélisation Maths |
Modélisation et le code: ici
Code
--------------------------------------------------------------------------------------------------------------------------
N=15;
h=2/(N+1);
A=zeros(N,N);
b=zeros(N,1);
syms t real
w0=1-t;
w1=t;
f(t)=(-4*t^2-6)*exp(t^2);
Uexa(t)=(t^2-1)*exp(t^2);
m0=int(w0^2,0,1);
m1=int(w1^2,0,1);
m2=int(diff(w0)^2,0,1);
m3=int(diff(w1)^2,0,1);
m4=int(w1*w0,0,1);
m5=int(diff(w1)*diff(w0),0,1);
for i=1:N+2
x(i)=(i-1)*h-1;
ue(i)=Uexa(x(i));
end
for i=2:N
g1=f(h*t+x(i-1));
g2=f(h*t+x(i));
A(1,1)=(1/h)*(m3+m2)+h*(m1+m0);
A(i,i)=(1/h)*(m3+m2)+6*h*(m1+m0);
A(i-1,i)=(1/h)*m5+6*h*m0;
A(i,i-1)=(1/h)*m5+6*h*m4;
b(1)=h*int(g1*w1,0,1)+h*int(g2*w0,0,1);
b(i)=h*int(g1*w1,0,1)+h*int(g2*w0,0,1);
end
U=inv(A)*b;
S=[0;U;0];
plot(x,S,'r-d',x,ue,'b-d');
legend('par elem.fini','s.exacte');
--------------------------------------------------------------------------------------------------------------------------
Différence fini sur Matlab, comparaison de la solution approchée et l'exacte.
mars 27, 2019
Education
Code Matlab:
--------------------------------------------------------------------------------------------------------------------------
close
clear all
clc
N=15;
h=2/(N+1);
A=zeros(N,N);
B=zeros(N,1);
syms t real
Uexa(t)=(t^2-1)*exp(t^2); %solution exacte
f(t)=(-4*t^4-6)*exp(t^2);
for i=1:N+2
x(i)=(i-1)*h-1;
Ue(i)=Uexa(x(i));
end
for i=2:N
A(1,1)=-(2+6*h^2); A(i,i)=-(2+6*h^2); %Remplir la matrice A
A(i-1,i)=1;
A(i,i-1)=1;
B(1)=-h^2*f(x(i));
B(i)=-h^2*f(x(i));
end
V=inv(A)*B;
Uap=[0;V;0]; % solution approchée par D.fini
plot(x,Uap,’r-*’,x,Ue,’b-d’)
legend(‘D.fini’,’sol.exact’)
--------------------------------------------------------------------------------------------------------------------------