format short e; format compact;
Lx=1;Ly=1;Tfinal=0.1;
dx=Lx/(n);
dy=dx;
tol=dx^3;
x=0:dx:1;
y=0:dy:1;
[X,Y]=meshgrid(x,y);
f=-sin(pi*X).*sin(pi*Y);
vex=-f/pi^2/2;
v=0*vex;
uancien=v;
% iterations de Jacobi
errjacobi=100;
itejacobi=0;
t0=cputime;
while(errjacobi>tol)
v0=v;
itejacobi=itejacobi+1;
t=v0(1:n-1,2:n)+v0(3:n+1,2:n)+v0(2:n,1:n-1)+v0(2:n,3:n+1);
v(2:n,2:n)=(t-dx^2*f(2:n,2:n))/4;
errjacobi=max(max(abs(v-v0)))/max(max(abs(v)));
ax=[0,1,0,1,0,1/pi^2];
%surf(x,y,v);axis(ax);pause(0.01);
end;
t1=cputime-t0;
disp([n,itejacobi,t1]);




