Consider an experiment where ants are placed on a rectangula
Consider an experiment where ants are placed on a rectangular board of height R inches and width C inches and are allowed to move on the board. Let us represent the number of ants on one inch-square segments of the board by the matrix m. The figure below shows an example of a 3-by-4 board. After one minute, for any given segment, 1/4th of the ants on that segment move up, 1/4th move down, 1/4th move left, and 1/4th move right. For the ants on the segments along the edges of the board, some of the ants move off the board.
Use matlab to write a function diffuseants2d(m) that takes a matrix m and returns the number of ants on the segments of the board after one minute. For simplicity, assume that the number of ants in a segment does not have to be a whole integer.
8 0 0 02 3.5 0 2 2.5 0 3.5 00 2.5 0 0 0 0 10 0 0 4 0 0Solution
Any queries please cmment
disp( simulateants2d( [8 0 0 4; 0 0 10 0; 0 0 0 0] ) )
0 2.0000 3.5000 0
2.0000 2.5000 0 3.5000
0 0 2.5000 0
>> disp( simulateants2d( [8 0 0 4; 0 0 10 0; 0 0 0 0], 2 ) )
1.0000 1.5000 0.5000 1.7500
0.6250 1.0000 3.0000 0
0.5000 1.2500 0 1.5000
