// convection: schéma de Lax-Wendroff
//clear; close,
//da=gda(); da.auto_clear='on';
//
V=1;	// vitesse de convection
T=1;	// temps final
cfl=0.75;

//N=[20,40,80,160]';	// Nb de point de discretisation
N=[750,1500,3000,6000]';	// Nb de point de discretisation
erreur=zeros(N);
for i=1:size(N,'r')
	dx=1/N(i);
	dt=cfl*dx/V;

	x=linspace(0,1,N(i)+1);

//u0=sin(%pi*x)';
	u0=double(x<0.25)'+double(x>0.75)';

	u=u0;
	plot(x',u);



		for t=dt:dt:T,
			v=(1-cfl^2)*u-0.5*(cfl-cfl^2)*[u(2:N(i)+1);u(2)]+0.5*(cfl+cfl^2)*[u(N(i));u(1:N(i))];	// Law Wendroff
			u=v;
	//		plot2d(x,u);
		end;

		plot2d(x',[u u0]);
		erreur(i)=sqrt((u-u0)'*(u-u0)*dx);
	//erreur(i)=sqrt(((u-u0)'*(u-u0)-(u(1)-u0(1))^2)*dx);
		//erreur(i)=(norm(u-u0,1)-abs(u(1)-u0(1)))*dx;
scf
end;
dN=ones(size(N,'r'),1)./N;
dN12=ones(size(N,'r'),1)./(N.^0.5);
dN14=ones(size(N,'r'),1)./(N.^0.25);
dN2=ones(size(N,'r'),1)./(N.^2);
plot2d(N,[erreur dN dN12 ],logflag='ll');
scf
plot2d(N,[erreur  dN14 dN2],logflag='ll');
