1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| clear all
close all
h=input('Donnez le pas espace h:');
a=0;b=1;
N=round((b-a)/h);
k=input('donnez le pas temps k:');
r=k/((pi^2)*(h^2));
for i=1:N
x(i)=i*h;
end
for j=1:N
t(j)=j*k;
end
for j=1:N
Uh(1,j)=0;
end
for j=1:1:N
Uh(N,j)=0;
end
for i=2:1:N-1
Uh(i,1)=sin(pi*x(i));
end
%solution exacte
for i=1:N
for j=1:N
U(i,j)=exp(-t(j))*sin(pi*x(i));
end
end
%Matrice tridiagonale
A=r*tridiag(1,-2,1,N)
b=0;
%solution approche a laide de jacobi
[Uh,nellerr,inter]=jacobi(A,b,0.000003,10^(-7),N);
Uh
% erreur de convergance
for i=1:1:N
for j=1:1:N
EC(i,j)=abs(U(i,j)-Uh(i,j));
end
end
if N==10
V=[Uh(1,:) Uh(2,:) Uh(3,:) Uh(4,:) Uh(5,:) Uh(6,:) Uh(7,:) Uh(8,:) Uh(9,:) Uh(10,:)];
Z=[U(1,:) U(2,:) U(3,:) U(4,:) U(5,:) U(6,:) U(7,:) U(8,:) U(9,:) U(10,:) ];
P=[EC(1,:) EC(2,:) EC(3,:) EC(4,:) EC(5,:) EC(6,:) EC(7,:) EC(8,:) EC(9,:) EC(10,:)];
subplot(3,1,1);
plot(V);
title('solution approcheé');
subplot(3,1,2);
plot(Z);
title('solutions exacte');
subplot(3,1,3);
plot(P);
title('erreur cv');
else
subplot(2,1,1);
mesh(Uh);
title('solution approcheé');
subplot(2,1,2);
mesh(U);
end |
Partager