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

fprintf('ondes04 \n') ; 
fprintf('differences finies avec le premier mode de Fourier \n') 
fprintf('un joli cas qui diverge  \n')

n = 50  ,  niter = 31 
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;;' ) 

sigma = 1.2  
dt    = sigma * dx ; 

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

axis ([ -.01 , 1.01 ,  -1.2  , 1.2  ]) 
t     = 0   ; 
yy   = y1 ; yym  = yy ;  yyp  = yy ;  yye  = y1 ; 

for jtime = 1 : niter  
t     = t + dt ; 
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))  ; 
yye(j)  =  cos(pi*t) * y1(j) ; end 
plot ( xx,y1,'k;;' ,   xx,yyp,'*-r;t;' ,  xx,yye,'b;;' ) 
axis ([ -.02 , 1.02 , -1.85 , 1.75]) 
delete (findobj ("tag", "legend")) 
title ('differences finies : une instabilite') ;
pause (.01) ;

yym = yy ; yy = yyp ; 
end

hold off 

plot ( xx,y1,'k;condition initiale;' ,  ...
       xx,yyp,'-r*;differences finies;' ,  xx,yye,'b;solution exacte;' )
axis ([ -.02 , 1.02 , -1.85 , 1.75])  
print('04-differences-finies-instables' , '-djpg','-S891,630'); 

 

