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

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

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;

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

View Full Document
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

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern