In matlab For the third problem we will be growing ferns by
In matlab
For the third problem, we will be growing ferns by random repetition of a few simple matrix/vector transformations. For each step a random number is generated and dependent on the number one of four possible transformations occur. Your program should successively generate a random number and should apply z = [0 0; 0 0.16] * z with probability 0.01 apply z = 3 [0.85 0.04; -0.04 0.85] * z + [0; 1.6] with probability 0.85 apply z = [0.2 -0.26; 0.23 0.22]* z + [0; 1.6] with probability 0.07 apply z = [-0.15 0.28; 0.26 0.24] * z + [0; 0.44] with probability 0.07 starting with z = [0; 0]. This recursion should occur n = 10,000 times. You should accomplish this with a single if clause, although, given that your logic now forks four ways, you will want to make use of some subordinate elseif statements.Solution
z=[0;0];
for i=1:1000 %1 to 1000 loop
r = rand; %generate random number
if(r<0.01)
z=[0 0;0 0.16]*z;
elseif(r<0.85)
z=[0.85 0.04;-0.04 0.85]*z+ [0;1.6];
elseif(r<0.07)
z=[0.2 -0.26;0.23 0.22]*z+[0;1.6];
else
z=[-0.15 0.28;0.26 0.24]*z+[0;0.44];
end
end
