1 - disp('2 collects all'); y1=y1-1; y2=y2+2; y3=y3-1;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
function avgflips = 1(initp1, initp2, initp3, eps, n) totalflips=0; for m=eps(1,1):eps(1,9) f for j=1:n y1=initp1; y2=initp2; y3=initp3; while y1>0 && r1=rand; while r1==0.5; r1=rand; end r2=rand; while r1==0.5; r1=rand; end r3=rand; while r1==0.5; r1=rand; end if r1 >m & r2 >m && r3 >m; disp('It''s a tie'); y1=y1; y2=y2; y3=y3; disp([y1;y2;y3]); elseif r1 <m & r2 disp('It''s a tie'); y1=y1; y2=y2; y3=y3; disp([y1;y2;y3]); elseif r1 >m & r2 disp('1 collects all'); y1=y1+2; y2=y2-1; y3=y3-1; disp([y1;y2;y3]); elseif r1 <m & r2 >m && r3 >m; disp('1 collects all') y1=y1+2; y2=y2-1; y3=y3-1; disp([y1;y2;y3]); elseif r1 >m & r2 m; disp('2 collects all'); y1=y1-1; y2=y2+2; y3=y3-1; disp([y1;y2;y3]); elseif r1 <m & r2 >m &&r3
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: disp('2 collects all'); y1=y1-1; y2=y2+2; y3=y3-1; disp([y1;y2;y3]); elseif r1 &gt;m &amp;&amp; r2 &gt;m &amp;&amp; r3 &lt;m; disp('3 collects all'); y1=y1-1; y2=y2-1; y3=y3+2; disp([y1;y2;y3]); elseif r1 &lt;m &amp;&amp; r2 &lt;m &amp;&amp; r3 &gt;m; disp('3 collects all'); y1=y1-1; y2=y2-1; y3=y3+2; disp([y1;y2;y3]); end totalflips=totalflips+1; end end disp(['The number of flip is ',num2str(totalflips)]); avgflips=totalflips/n; disp(['the avg of flip per game is ',num2str(avgflips)]); % Generate time vector - you will need to modify the following line. eps = [0.1:0.1:0.9]; e figure; %gtext('Reaction Progress');xlabel('time');ylabel('Concentration') plot(eps,avgflips,'r+'); end end...
View Full Document

Page1 / 2

1 - disp('2 collects all'); y1=y1-1; y2=y2+2; y3=y3-1;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online