debutant en informatique on nous a demandé de comprendre la fonction suivante, je n'ai jamais fait de MATLAB, qqn serait il capable de me donner une traduction en francais de l'essentiel du programme?
notre objectif est de modifier le programme pour modeliser un autre type d'ecoulement dans le cadre d'un projet en mecanique. Nous avons besoin de comprendre les fonctions principales utilisees .
merci

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [x1,x2,x3,x4,x5,x6,x7]=collision(x1,x2,x3,x4,x5,x6,x7,N)
  for i=1:N
    for j=1:N
      c = x1(i,j)+2*x2(i,j)+4*x3(i,j)+8*x4(i,j)+16*x5(i,j)+32*x6(i,j)+64*x7(i,j);
      r = rand<0.5;
      switch c
      case 5
        x1(i,j) = 0; x2(i,j) = 1; x3(i,j) = 0; x7(i,j) = 1;
      case 9
        x1(i,j) = 0; x2(i,j) = r; x3(i,j) = 1-r; x4(i,j) = 0; x5(i,j) = r;
        x6(i,j) = 1-r;
      case 10
        x2(i,j) = 0; x4(i,j) = 0; x3(i,j) = 1; x7(i,j) = 1;
      case 17
        x1(i,j) = 0; x5(i,j) = 0; x6(i,j) = 1; x7(i,j) = 1;
      case 18
        x1(i,j) = r; x2(i,j) = 0; x3(i,j) = 1-r; x4(i,j) = r; x5(i,j) = 0;
        x6(i,j) = 1-r;
      case 20
        x3(i,j) = 0; x4(i,j) = 1; x5(i,j) = 0; x7(i,j) = 1;
      case 21
        x1(i,j) = 0; x2(i,j) = 1; x3(i,j) = 0; x4(i,j) = 1; x5(i,j) = 0;
        x6(i,j) = 1;
      case 34
        x1(i,j) = 1; x2(i,j) = 0; x6(i,j) = 0; x7(i,j) = 1;
      case 36
        x1(i,j) = r; x2(i,j) = 1-r; x3(i,j) = 0; x4(i,j) = r; x5(i,j) = 1-r;
        x6(i,j) = 0;
      case 40
        x4(i,j) = 0; x5(i,j) = 1; x6(i,j) = 0; x7(i,j) = 1;
      case 42
        x1(i,j) = 1; x2(i,j) = 0; x3(i,j) = 1; x4(i,j) = 0; x5(i,j) = 1;
        x6(i,j) = 0;
      case 65
        x1(i,j) = 0; x2(i,j) = 1; x6(i,j) = 1; x7(i,j) = 0;
      case 66
        x1(i,j) = 1; x2(i,j) = 0; x3(i,j) = 1; x7(i,j) = 0;
      case 68
        x2(i,j) = 1; x3(i,j) = 0; x4(i,j) = 1; x7(i,j) = 0;
      case 72
        x3(i,j) = 1; x4(i,j) = 0; x5(i,j) = 1; x7(i,j) = 0;
      case 73
        x1(i,j) = 0; x2(i,j) = r; x3(i,j) = 1-r; x4(i,j) = 0; x5(i,j) = r;
        x6(i,j) = 1-r;
      case 80
        x4(i,j) = 1; x5(i,j) = 0; x6(i,j) = 1; x7(i,j) = 0;
      case 82
        x1(i,j) = r; x2(i,j) = 0; x3(i,j) = 1-r; x4(i,j) = r; x5(i,j) = 0;
        x6(i,j) = 1-r;
      case 85
        x1(i,j) = 0; x2(i,j) = 1; x3(i,j) = 0; x4(i,j) = 1; x5(i,j) = 0;
        x6(i,j) = 1;
      case 96
        x1(i,j) = 1; x5(i,j) = 1; x6(i,j) = 0; x7(i,j) = 0;
      case 100
        x1(i,j) = r; x2(i,j) = 1-r; x3(i,j) = 0; x4(i,j) = r; x5(i,j) = 1-r;
        x6(i,j) = 0;
      case 106
        x1(i,j) = 1; x2(i,j) = 0; x3(i,j) = 1; x4(i,j) = 0; x5(i,j) = 1;
        x6(i,j)= 0;
      end
    end
  end
end
Et le fichier principal :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
 
% FHP-2
 
% The domain is NxN, hexagonal
N              = 200 ;
% domain with high density, disc of radius r
r = 8;
% Initial density of cells alive
initialDensity = 0.01;
highDensity =0.6;
% Number of iteration steps
nSteps         = 100;
 
% Create a random initial condition
cells1 = rand(N,N)<initialDensity;
cells2 = rand(N,N)<initialDensity;
cells3 = rand(N,N)<initialDensity;
cells4 = rand(N,N)<initialDensity;
cells5 = rand(N,N)<initialDensity;
cells6 = rand(N,N)<initialDensity;
cells7 = rand(N,N)<initialDensity;
 
% Higher density inside a disc as initial condition
for i=1:N
  for j=1:N
    if (mod(j,2)==1)
      if((i-N/2+(j-1)/2)^2+(j-N/2)^2 < r^2)
        cells1(i,j)=rand<highDensity;
        cells2(i,j)=rand<highDensity;
        cells3(i,j)=rand<highDensity;
        cells4(i,j)=rand<highDensity;
        cells5(i,j)=rand<highDensity;
        cells6(i,j)=rand<highDensity;
        cells7(i,j)=rand<highDensity;
      elseif((i-3*N/2+(j-1)/2)^2+(j-N/2)^2 < r^2)
        cells1(i,j)=rand<highDensity;
        cells2(i,j)=rand<highDensity;
        cells3(i,j)=rand<highDensity;
        cells4(i,j)=rand<highDensity;
        cells5(i,j)=rand<highDensity;
        cells6(i,j)=rand<highDensity;
        cells7(i,j)=rand<highDensity;
      end
    else
      if((i-N/2+j/2)^2+(j-N/2)^2 < r^2)
        cells1(i,j)=rand<highDensity;
        cells2(i,j)=rand<highDensity;
        cells3(i,j)=rand<highDensity;
        cells4(i,j)=rand<highDensity;
        cells5(i,j)=rand<highDensity;
        cells6(i,j)=rand<highDensity;
        cells7(i,j)=rand<highDensity;
      elseif((i-3*N/2+j/2)^2+(j-N/2)^2 < r^2)
        cells1(i,j)=rand<highDensity;
        cells2(i,j)=rand<highDensity;
        cells3(i,j)=rand<highDensity;
        cells4(i,j)=rand<highDensity;
        cells5(i,j)=rand<highDensity;
        cells6(i,j)=rand<highDensity;
        cells7(i,j)=rand<highDensity;
      end
    end
  end
end
 
aviobj = avifile('FHP2.avi','fps',15); 
 
plot_cells = cells1(:,:,:)+cells2(:,:,:)+cells3(:,:,:)+cells4(:,:,:)+ ...
                 cells5(:,:,:)+cells6(:,:,:)+cells7(:,:,:)>0;
 
 
 
    % Plot the result
    imagesc(zeros(N,N));
    hold on
    for im=1:N
      if (mod(im,2)==1)
        imagesc(0.5:N-0.5,im,circshift(plot_cells(1:N,im),[(im-1)/2,0])');
       colormap(gray)
 
      else
        imagesc(1:N,im,circshift(plot_cells(1:N,im),[im/2-1,0])');
        colormap(gray)
      end
    end
 
% Main time loop
for i=1:nSteps
    % Propagation
    cells1 = circshift(cells1,[1,0]);
    cells2 = circshift(cells2,[1,-1]);
    cells3 = circshift(cells3,[0,-1]);
    cells4 = circshift(cells4,[-1,0]);
    cells5 = circshift(cells5,[-1,1]);
    cells6 = circshift(cells6,[0,1]);
 frame = getframe(gcf);
    aviobj = addframe(aviobj,frame);
    % Collision
    [cells1,cells2,cells3,cells4,cells5,cells6,cells7] = ...
      collision(cells1,cells2,cells3,cells4,cells5,cells6,cells7,N);
    % Field to be plotted
    plot_cells = cells1(:,:,:)+cells2(:,:,:)+cells3(:,:,:)+cells4(:,:,:)+ ...
                 cells5(:,:,:)+cells6(:,:,:)+cells7(:,:,:)>0;
 
 
 
    % Plot the result
    imagesc(zeros(N,N));
    hold on
    for im=1:N
      if (mod(im,2)==1)
        imagesc(0.5:N-0.5,im,circshift(plot_cells(1:N,im),[(im-1)/2,0])');
        colormap(gray)
    else
        imagesc(1:N,im,circshift(plot_cells(1:N,im),[im/2-1,0])');
        colormap(gray)
 
      end
    end
    drawnow;
 
    hold off
end
 
 
aviobj = close(aviobj);