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;
% iterations de Gauss-Seidel
errgs=100;
itegs=0;
t0=cputime;
while(errgs>tol)
v0=v;
itegs=itegs+1;
for j=2:n;
for i=2:n;
t=v(i-1,j)+v(i+1,j)+v(i,j-1)+v(i,j+1);
v(i,j)=(t-dx^2*f(i,j))/4;
end;
end;
errgs=max(max(abs(v-v0)))/max(max(abs(v)));
end;
t1=cputime-t0;
%ax=[0,1,0,1,0,1/pi^2];
%surf(x,y,v);axis(ax);pause(0.01);
disp([n,itegs,t1]);




