A list,
1 Cellular automata CA
Cellular automata (CA) is a kind of grid dynamics model with discrete time, space and state, and local spatial interaction and temporal causality, which has the ability to simulate the space-time evolution process of complex system. Among them, cellular automata is also called cellular automata, and The Game of Life is a very typical CA.
Here are my notes. CA has four main points:
2 The Game of Life
The Game of Life was proposed by British mathematician John Horton Conway in 1970. As a cellular automata system, the game of life is a zero-player game. After the user determines the initial state and evolution rules, the evolution process of the form can be simulated without other operations.
The basic idea of cellular Automata can be traced back to the concept of “machine reproduction” proposed by Von Neumann in Theory of Self-Reproducing Automata in the last century: A dynamic system in which small machines made up of a group of cells evolve according to a few simple rules and initial patterns. Machines can evolve and continue on their own.
MatLab realization of the game of life
I thought most of the code on the web didn’t take boundaries into account, so I made some improvements.
The rules are explained in detail in the notes, and there are three of them.
Here’s a chart to help you understand :(imagine the origin coordinates in the lower left corner.)
Ii. Source code
The % cellular automata game of Life rule: assume that a cell can only be alive and dead1.If a living cell has a perimeter (including diagonal neighbors)2or3One cell sustains, the cell remains sustains; %2.If there's a dead cell around3When a cell feeds, the cell turns into a living cell; %3.In other cases, dead cells remain dead and living cells become dead. clc; clear; % defines the size of the cell space as100, that is100Delta x is equal to delta x20;
y = 20; % defines the number of iterations epoch =100; % net = rand(x,y); game = zeros(x,y);for i = 1:x
for j = 1:y
if net(i,j)<= 0.3% in accordance with (I- 1,j)->(i,j)->(i,j- 1)->(i- 1,j- 1) to outline the graph fx = [I- 1,i,i,i- 1];
fy = [j,j,j- 1,j- 1];
fill(fx,fy,'g') % represents cellular state for game(I,j)=1;
hold on
end
end
end
pause(0.1)
for k = 1:epoch
temp = zeros(x,y);
fx=[0,x,x,0];
fy=[0.0,y,y];
fill(fx,fy,'w');
hold on;
for i = 1:x
for j = 1:y
if i~=1 && i~= x && j~=1There are only three neighbors at the four corners and five neighbors at the border- 1,j- 1)+game(i,j- 1)+game(i+1,j- 1)+game(i- 1,j)+game(i+1,j)+game(i- 1,j+1)+game(i,j+1)+game(i+1,j+1);
if game(i,j) = =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a== 3
temp(i,j) = 1;
end
end
elseif i==1
if j==1
a = game(i,j+1)+game(i+1,j)+game(i+1,j+1);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
elseif j==y
a = game(i,j- 1)+game(i+1,j- 1)+game(i+1,j);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
else
a = game(i,j- 1)+game(i+1,j- 1)+game(i+1,j)+game(i,j+1)+game(i+1,j+1);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
end
elseif i == x
if j==1
a = game(i- 1,j)+game(i- 1,j+1)+game(i,j+1);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
elseif j==y
a = game(i- 1,j- 1)+game(i- 1,j)+game(i,j- 1);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
else
a = game(i- 1,j- 1)+game(i,j- 1)+game(i- 1,j)+game(i- 1,j+1)+game(i,j+1);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
end
elseif j == 1
a = game(i- 1,j)+game(i+1,j)+game(i- 1,j+1)+game(i,j+1)+game(i+1,j+1);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
elseif j == y
a = game(i- 1,j- 1)+game(i,j- 1)+game(i+1,j- 1)+game(i- 1,j)+game(i+1,j);
if game(i,j)= =1
if a == 3 || a ==2
temp(i,j) = 1;
end
else
if a == 3
temp(i,j) = 1;
end
end
end
end
end
if game == temp
disp(strcat('in the first',num2str(k),'Wheel cellular automata reaches steady state'))
for i=1:x
for j=1:y
if temp(i,j)==1
fx=[i- 1,i- 1,i,i];
fy=[j- 1,j,j,j- 1];
fill(fx,fy,'g');
hold on;
end
end
end
break;
end
Copy the code
3. Operation results
I initialized the rectangle with a uniform distribution, in the 20 by 20 region.
Fourth, note
Version: 2014 a