Bonjour,

je suis débutant à matlab et je dois réaliser une simulation de diffusion atomique. Mon programme est primitif : des boucles for et if.

Le principe : je dispose d'une matrice 30x30 composée d'atomes 1 et 2 (rouge et bleu) et de 0: les lacunes. Je fais un balayage de la matrice pour déplacer les lacunes. Pour ne pas reprendre les mêmes lacunes je balaye un coup les indices pairs et un coup les indices impairs.
Je balaye les bords séparément.

Mon problème : le programme fonctionne bien pour les premières itérations, mais il se met à tourner dans le vide après un certain temps (assez court), les matrices ne bougeant plus... je ne comprends pas!

voici mon code
Code:
mat(1:30,1:15)=1;
mat(1:30,16:30)=2;
for p=1:15
mat(floor(rand(1)*30),floor(12+6*rand(1)))=0;
end
for q=1:7
mat(floor(rand(1)*30),floor(1+10*rand(1)))=0;
mat(floor(rand(1)*30),floor(20+10*rand(1)))=0;
end
A=mat



hold on
for i=1:30 
    for j=1:30
        if A(i,j)==1
        plot(j/30,1-(i-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
         elseif A(i,j)==2
        plot(j/30,1- (i-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
    end
    end
end

for t=1:1000000

for m=2*(1:14)
    for n=2*(1:14)
        if A(m,n)==0
        a=floor(rand(1)*4)
              if a==0 && A(m-1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==0 && A(m-1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m+1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m+1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==2 && A(m,n+1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==2 && A(m,n+1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==3 && A(m,n-1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)             
              elseif a==3 && A(m,n-1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              end
                    if a==0 
                        A(m-1,n)=0
plot(n/30,1-(m-2)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==1 
                        A(m+1,n)=0 
plot(n/30,1-(m)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                   
                    elseif a==2 
                        A(m,n+1)=0
plot((n+1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                   
                    elseif a==3
                        A(m,n-1)=0
plot((n-1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    end
                    else continue 
         end
    end
end



for m1=2*(1:14)+1
    for n1=2*(1:14)+1
        if A(m1,n1)==0
        a=floor(rand(1)*4)
              if a==0 && A(m-1,n1)==1
                 A(m1,n1)=1
plot(n1/30,1-(m1-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==0 && A(m1-1,n1)==2
                 A(m1,n1)=2
plot(n1/30,1-(m1-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m1+1,n1)==1
                 A(m1,n1)=1
plot(n1/30,1-(m1-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m1+1,n1)==2
                 A(m1,n1)=2
plot(n1/30,1-(m1-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)             
              elseif a==2 && A(m1,n1+1)==1
                 A(m1,n1)=1
plot(n1/30,1-(m1-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==2 && A(m1,n1+1)==2
                 A(m1,n1)=2
plot(n1/30,1-(m1-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==3 && A(m1,n1-1)==1
                 A(m1,n1)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==3 && A(m1,n1-1)==2
                 A(m1,n1)=2
plot(n1/30,1-(m1-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              end
                    if a==0 
                        A(m1-1,n1)=0
plot(n1/30,1-(m1-2)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                   
                    elseif a==1 
                        A(m1+1,n1)=0
plot(n1/30,1-(m1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                  
                    elseif a==2 
                        A(m1,n1+1)=0
plot((n1+1)/30,1-(m1-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                   
                    elseif a==3
                        A(m1,n1-1)=0
plot((n1-1)/30,1-(m1-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                   
                    end
                    else continue 
         end
    end
end



for m=1 
    for n=2:29
        if A(m,n)==0
        a=floor(rand(1)*3)

              if a==0 && A(m+1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==0 && A(m+1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m,n+1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m,n+1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)            
              elseif a==2 && A(m,n-1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)            
              elseif a==2 && A(m,n-1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              end

                    if a==0 
                        A(m+1,n)=0
plot(n/30,1-(m)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==1 
                        A(m,n+1)=0
plot((n+1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==2
                        A(m,n-1)=0
plot((n-1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    end
                    else continue 
        end       
    end
end




for m=30 
    for n=2:29
        if A(m,n)==0
        a=floor(rand(1)*3)
              if a==0 && A(m-1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)
              elseif a==0 && A(m-1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m,n+1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)             
              elseif a==1 && A(m,n+1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)               
              elseif a==2 && A(m,n-1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)             
              elseif a==2 && A(m,n-1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              end
                    if a==0 
                        A(m-1,n)=0
plot(n/30,1-(m-2)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                     
                    elseif a==1 
                        A(m,n+1)=0
plot((n+1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==2
                        A(m,n-1)=0
plot((n-1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    end
                    else continue 
        end       
    end
end



for n=1 
    for m=2:29
        if A(m,n)==0
        a=floor(rand(1)*3)
              if a==0 && A(m-1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)               
              elseif a==0 && A(m-1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)               
              elseif a==1 && A(m+1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m+1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)             
              elseif a==2 && A(m,n+1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)            
              elseif a==2 && A(m,n+1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)             
              end
                    if a==0 
                        A(m-1,n)=0
plot(n/30,1-(m-2)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==1 
                        A(m+1,n)=0
plot(n/30,1-(m)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==2 
                        A(m,n+1)=0
plot((n+1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                   
                    end
                    else continue 
        end       
    end
end




for n=30 
    for m=2:29
        if A(m,n)==0
        a=floor(rand(1)*3)
              if a==0 && A(m-1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==0 && A(m-1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m+1,n)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)
pause(0.05)              
              elseif a==1 && A(m+1,n)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)             
              elseif a==2 && A(m,n-1)==1
                 A(m,n)=1
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',8)


pause(0.05)             
              elseif a==2 && A(m,n-1)==2
                 A(m,n)=2
plot(n/30,1-(m-1)/30,'o','MarkerEdgeColor','k','MarkerFaceColor','b','MarkerSize',8)
pause(0.05)              
              end
                    if a==0 
                        A(m-1,n)=0
plot(n/30,1-(m)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==1 
                        A(m+1,n)=0
plot(n/30,1-(m)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                    
                    elseif a==2
                        A(m,n-1)=0
plot((n-1)/30,1-(m-1)/30,'o','MarkerEdgeColor','w','MarkerFaceColor','w','MarkerSize',8)
pause(0.05)                   
                    end
                    else continue 
        end       
    end
end

continue
end
si quelqu'un a le courage de regarder, cela me serait d'une grande aide!
merci d'avance