%   ondes06.m
%   fd, 13 decembre 2010, 06 mars 2025  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   clear ; format long

fprintf('ondes05 \n') ; 
fprintf('differences finies \n') 
fprintf('condition limite de Dirichlet homogene en x=0')
fprintf('condition limite de Neumann homogene en x=1 ')


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
n = 128     ,  niter = 360    %%%%%%%%%%%%%   180
  
sigma = .8  %%%%%%%%%      regle pour une periode 
dx = 1/n ; 

xx = zeros(1,n+1) ; y1 = xx ; 
xa    = 0 ; 
for j = 1:n+1 ; xx(j) = xa ; y1(j) = sin(pi*xa) ; 
xa = xa + dx ; end 

plot (xx,y1,'r;;' ) 
 
 
dt    = sigma * dx ; 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

t     = 0   ; 
yy   = y1 ; yym  = yy ;  yyp  = yy ;  yye  = y1 ; 

for jtime = 1 : niter  
for j = 1:n+1 ; yyp(j) = 0 ; end

for j = 2:n ; 
yyp(j) = 2*yy(j) - yym(j) + (sigma**2) *  (yy(j+1)-2*yy(j)+yy(j-1))  ;  end

d2x1   = 2*(yy(n)-yy(n+1))  ; 
yyp(n+1) = 2*yy(n+1) - yym(n+1) +  (sigma**2) * d2x1  ; 
%%%  yyp(n+1) = (1-sigma)*yy(n+1) + sigma*yy(n) ; 

t     = t + dt ; 
plot ( xx,y1,'k;t=0;' ,   xx,yyp,'*-r*;t;' )  
axis ([ -.01 , 1.01 ,  -1.1  , 1.1  ]) 
delete (findobj ("tag", "legend"))
title ('differences finies ; Dirichlet homogene en x=0, Neumann homogene en x=1')

if jtime==1 ;  print('06-001-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==30 ; print('06-030-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==60 ; print('06-060-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==90 ; print('06-090-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==120 ; print('06-120-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==150 ; print('06-150-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==180 ; print('06-180-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==210 ; print('06-210-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==240 ; print('06-240-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==270 ; print('06-270-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==300 ; print('06-300-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==315 ; print('06-315-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==330 ; print('06-330-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==345 ; print('06-345-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;
if jtime==360 ; print('06-360-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); end ;

pause (.005) ;

yym = yy ; yy = yyp ; 
end


plot ( xx,y1,'k;t=0;' ,   xx,yyp,'*-r*;;' )
delete (findobj ("tag", "legend")) 
axis ([ -.01 , 1.01 ,  -1.1  , 1.1  ]) 
title ('differences finies ; Dirichlet homogene en x=0, Neumann homogene en x=1')
%%%  print('06-differences-finies-conditions-limites-mixtes' , '-djpg','-S891,630'); 
