Graphics Programs Reference
In-Depth Information
else
r=0;
end
Here is the series of commands to test the Captain's survival
possibilities:
x1=25;y1=25;h=0;
for n = 1:100
x0 = 50*rand;
y0 = 50*rand;
r = lifeordeath(x1, y1, x0, y0);
h=h+r;
end
ifh>0
disp('The Captain is dead!')
else
disp('Picard lives!')
end
The Captain is dead!
In fact if you run this sequence of commands multiple times, you will see
the Captain die far more often than he lives.
(c)
So let's do a Monte Carlo simulation to see what his odds are:
x1=25;y1=25;c=0;
for k = 1:100
h=0;
for n = 1:100
x0 = 50*rand;
y0 = 50*rand;
r = lifeordeath(x1, y1, x0, y0);
h=h+r;
end
ifh>0
c=c;
Search WWH ::




Custom Search