Can anyone help with this MATLAB homework please THANKS SO M

Can anyone help with this MATLAB homework please?? THANKS SO MUCH!!!

Here is a simple game: a player can roll a fair, six-sided die up to three times. After each roll a player may stop the game and receive $1 for each dot on the upturned die. The player has to roll at least once, and the game automatically stops after the third roll. For example, if a player rolls 1, rolls 4, and then stops, the player receives $4. The purpose of this exercise is to determine a good strategy to play this game, one that maximizes the chances of winning the most money.

a. The MATLAB command rand yields a uniformly distributed, random number between 0 and 1. Therefore the statement

provides a 1, 2, 3, 4, 5 or 6 each with probability 1/6. We may thus interpret the result of the above MATLAB statement to be the occurrence of a roll of a fair, six-sided die.

Use the above command to simulate rolls of a die when you implement a MATLAB function of the form

function Strategy(minFirstRoll,minSecRoll).

Strategy(minFirstRoll,minSecRoll) simulates the outcome of the strategy that stops if the outcome of the first roll is at least minFirstRoll and stops if the outcome of the second roll at least minSecRoll. The Strategy function inputs two integers between 1 and 6 and outputs the number representing the upturned die where the player employing the strategy in question stops. Note: the output of Strategy is a random number.

b. We seek to find which strategies do well on average, so we need to average the results in part a. Write a function

that computes the arithmetic average of Strategy(minFirstRoll,minSecRoll) after playing numGames games. Display command line outputs of AveStrategy(1,2,10000), AveStrategy(4,3,10000)
and AveStrategy(5,5,10000).

c. Of the strategies considered above, which one does best? and what is its average (as the number of games played gets larger and larger)?

Remarks: For parts a and b, provide the MATLAB code you wrote for the Strategy and AveStrategy functions; for part b, also provide your numerical results; for part c, just answer the questions.

Solution

function [mean_score]=AveStrategy(minFirstRoll,minSecRoll,numGames)
mean_score=zeros(3,1); % Define Array to store all 3 possible upturned
for i=1:numGames
upturned_die=Strategy(minFirstRoll,minSecRoll); % Get Starategy
mean_score(i)=mean(upturned_die); % Take mean of the strategies
%fprintf(\'Game :%d, Average Score :%f \ \',i,mean_score(i));
end
fprintf(\'Total Final Score For (%d,%d,%d) Strategy :%.2f, Final Mean Score: %.2f \ \',minFirstRoll,minSecRoll,numGames,sum(mean_score),mean(mean_score)); % Display TotalScore of All Games
end

------------------------------------------------------------------------------------------------------------------------------

function [final_score]=AveStrategy(minFirstRoll,minSecRoll,numGames)
mean_score=zeros(3,1); % Define Array to store all 3 possible upturned
for i=1:numGames
upturned_die=Strategy(minFirstRoll,minSecRoll); % Get Starategy
mean_score(i)=mean(upturned_die); % Take mean of the strategies
%fprintf(\'Game :%d, Average Score :%f \ \',i,mean_score(i));
end
final_score=sum(mean_score);
fprintf(\'Total Final Score For (%d,%d,%d) Strategy :%.2f, Final Mean Score: %.2f \ \',minFirstRoll,minSecRoll,numGames,sum(mean_score),mean(mean_score)); % Display TotalScore of All Games
end

-------------------------------------------------------------------------------------------------------------------------------------

Output:=

>> AveStrategy(4,3,10000)
Total Final Score For (4,3,10000) Strategy :21270.33, Final Mean Score: 2.13

ans =

2.1270e+04

>> AveStrategy(1,2,10000)
Total Final Score For (1,2,10000) Strategy :32952.67, Final Mean Score: 3.30

ans =

3.2953e+04

>> AveStrategy(5,5,10000)
Total Final Score For (5,5,10000) Strategy :16753.00, Final Mean Score: 1.68

ans =

1.6753e+04

>>

----------------------------------------------------------------------------------------------------------------------------------

Part C:

You can evaluate the best strategy by using this code

This code iterates for all possible states of minFirstRoll and minSecRoll for numGames=10000

clc;
close all;
clear all;
best_score=0;
new_score=0;
best_i=0;
best_j=0;
numGames=10000;
for i=1:6 % for minFirstRoll
for j=1:6 % loop for possible cases of minSecRoll
new_score=AveStrategy(i,j,numGames); % New Score is calcualted for each minFirstRoll and minSecRoll
if(new_score>best_score) % Check whether the current strategy is better than pervious strategies
best_score=new_score; % If yes then best score is new Score and best minFirstRoll=i and minSecRoll=j
best_i=i;
best_j=j;
end
end
end
fprintf(\'Total Best Score For (%d,%d,%d) Strategy = %.2f \ \',best_i,best_j,numGames,best_score); % Display TotalScore of All Games

Can anyone help with this MATLAB homework please?? THANKS SO MUCH!!! Here is a simple game: a player can roll a fair, six-sided die up to three times. After eac
Can anyone help with this MATLAB homework please?? THANKS SO MUCH!!! Here is a simple game: a player can roll a fair, six-sided die up to three times. After eac

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site