// Equation de la chaleur : schema explicite
//clear; close,
//da=gda(); da.auto_clear='on';
//
T=0.01;	// temps final
cfl=0.5;
	
N=[20,40,80,160,320 ]';	// Nb de point de discretisation

erreur=zeros(N);
for i=1:size(N,'r')
	dx=1/N(i);
	dt=cfl*dx^2/2.
	x=linspace(0,1,N(i)+1);
	u0=cos(5*%pi*x)';
	u=u0;
// plot(x,u);
	A=diag(sparse(2.*ones(1,N(i)+1)))-diag(sparse(ones(1,N(i))),1)-diag(sparse(ones(1,N(i))),-1);
	A(1,2)=-2.;
	A(N(i)+1,N(i))=-2.;
	A=A/(dx)^2;
	for t=dt:dt:T,
		v=u-dt*A*u;//schéma explicite
		u=v;
//			plot2d(x,[u u0]);
	end;
	uexact=exp(-25*%pi^2*T)*cos(5*%pi*x)';
	erreur(i)=sqrt(((u-uexact)'*(u-uexact)*dx));
	plot2d(x,[u   uexact]);
scf
end;
dN=ones(size(N,'r'),1)./N;
dN2=ones(size(N,'r'),1)./(N^2);
plot2d(N,[erreur dN dN2],logflag='ll');
