How to resolve the algorithm Forest fire step by step in the MATLAB / Octave programming language
How to resolve the algorithm Forest fire step by step in the MATLAB / Octave programming language
Table of Contents
Problem Statement
Implement the Drossel and Schwabl definition of the forest-fire model.
It is basically a 2D cellular automaton where each cell can be in three distinct states (empty, tree and burning) and evolves according to the following rules (as given by Wikipedia) Neighborhood is the Moore neighborhood; boundary conditions are so that on the boundary the cells are always empty ("fixed" boundary condition). At the beginning, populate the lattice with empty and tree cells according to a specific probability (e.g. a cell has the probability 0.5 to be a tree). Then, let the system evolve. Task's requirements do not include graphical display or the ability to change parameters (probabilities p and f ) through a graphical or command line interface.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Forest fire step by step in the MATLAB / Octave programming language
Source code in the matlab programming language
function forest_fire(f,p,N,M)
% Forest fire
if nargin<4;
M=200;
end
if nargin<3;
N=200;
end
if nargin<2;
p=.03;
end
if nargin<1;
f=p*.0001;
end
% initialize;
F = (rand(M,N) < p)+1; % tree with probability p
S = ones(3); S(2,2)=0; % surrounding
textmap = ' T#';
colormap([.5,.5,.5;0,1,0;1,0,0]);
while(1)
image(F); pause(.1) % uncomment for graphical output
% disp(textmap(F)); pause; % uncomment for textual output
G = ((F==1).*((rand(M,N)<p)+1)); % grow tree
G = G + (F==2) .* ((filter2(S,F==3)>0) + (rand(M,N)<f) + 2); % burn tree if neighbor is burning or by chance f
G = G + (F==3); % empty after burn
F = G;
end;
You may also check:How to resolve the algorithm Bitmap/Write a PPM file step by step in the PureBasic programming language
You may also check:How to resolve the algorithm SEDOLs step by step in the Java programming language
You may also check:How to resolve the algorithm Remove lines from a file step by step in the Racket programming language
You may also check:How to resolve the algorithm Hello world/Newline omission step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Write language name in 3D ASCII step by step in the Nanoquery programming language