//Differences finies pour l'equation de transport u_t+u_x=0
//schemas explicites a 1 pas du type v_j^{n+1}=Av_{j-1}^n+Bv_j^n+Cv_{j+1}^n


clear
 listu0=['creneau','casu0=1';
 				'chapeau','casu0=2';
 				'reguliere','casu0=3'];

 				
listschemas=['FTFS','schema=1';
 					 'FTBS','schema=2';
 					 'FTCS','schema=3';
 					 'Lax-Friedrichs','schema=4';
 					 'Lax-Wendroff','schema=5'];
 				
 				
 listlambda=['1','lambda=1';
 						'1.2','lambda=1.2';
 						'0.7','lambda=0.7';
 						'0.1','lambda=0.1'];
 						
while %t
 num=x_choose(listu0(:,1),'Choisir un u0')
   if num==0 then break
  else
execstr(listu0(num,2));
 select casu0
  	 case 1
   	    deff('y=u0(x)','y=bool2s((abs(x)<=1))');
   	case 2
 deff('y=u0(x)','y=bool2s((abs(x)<=1)).*(ones(size(x,1),size(x,2))-abs(x))');
   	case 3
deff('y=u0(x)','y=0.5*bool2s((abs(x)<=1)).*(ones(size(x,1),size(x,2))+cos(%pi*x))');
   	end
   end
  
  
  num=x_choose(listlambda(:,1),'Choisir un lambda')
  execstr(listlambda(num,2));

  M=10;  h=1/M;//pour le pas d'espace

  k=lambda*h;
  N=15;

  num=x_choose(listschemas(:,1),'Choisir un schema')
  execstr(listschemas(num,2));
  select schema
  case 1 //FTFS
  			A=0;B=1+lambda;C=-lambda;
  case 2 //FTBS 
       A=lambda;B=1-lambda;C=0;
  case 3  //FTCS
     A=lambda/2;B=1;C=-lambda/2;
  case 4  //Lax-Friedrichs
     A=(1+lambda)/2;B=0;C=(1-lambda)/2;
  case 5   //Lax-Wendroff
    A=lambda/2+lambda^2/2;B=1-lambda^2;C=-lambda/2+lambda^2/2;
    
  end
  
  
  xmin=-1-h*N;
  xmax=1+h*N;
  x=[xmin:h:xmax];
  xbis=[xmin:0.01:xmax];
  ymin=-0.1;
  ymax=1.2;
  
  y=u0(xbis);
  v=u0(x);LV=length(v);
  clf;
  plot2d(xbis',y',rect=[xmin,ymin,xmax,ymax]);
  plot2d4(x',v',rect=[xmin,ymin,xmax,ymax]);
  halt();
  for n=1:N
  t=n*k;
  xprime=xbis-t*ones(size(xbis,1),size(xbis,2));
  y=u0(xprime);
  v(2:LV-1)=A*v(1:LV-2)+B*v(2:LV-1)+C*v(3:LV);
  clf
  plot2d(xbis',y',rect=[xmin,ymin,xmax,ymax]);
  plot2d4(x',v',rect=[xmin,ymin,xmax,ymax]);
  xtitle(string(t))
  halt();
  end;
 
  end 
