1 - disp'2 collects all y1=y1-1 y2=y2 2 y3=y3-1...

Info icon This 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 && y2>0 && y3>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 <m && r3 <m; disp('It''s a tie'); y1=y1; y2=y2; y3=y3; 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 && r3 >m; 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('2 collects all'); y1=y1-1; y2=y2+2; y3=y3-1; disp([y1;y2;y3]); elseif r1 <m && r2 >m &&r3 <m;
Image of page 1

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

View Full Document Right Arrow Icon
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 >m && r2 >m && r3 <m; disp('3 collects all'); y1=y1-1; y2=y2-1; y3=y3+2; disp([y1;y2;y3]); elseif r1 <m && r2 <m && r3 >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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern