Question: using matlab (a) Implement the following function as specified: function [pFinal, hFinal] doubleGame (pStart, hStart) % simulate the double game, a betting game between a
(a) Implement the following function as specified: function [pFinal, hFinal] doubleGame (pStart, hStart) % simulate the "double game," a betting game between a player and a host % pStart: a positive number of chips with which the player starts the game. % hStart: a positive number of chips with which the host starts the game. % A game consists of 1 or more rounds. The betting starts at 1 chip. In each round of % the game Player flips a coin: heads means Player wins the bet from Host and the % game ends (no more rounds); tails means Player loses the bet to Host but can start % another round that doubles the bet if Player and Host each has enough chips for the % bet. The game ends when Player wins a bet or when Player or Host does not have % enough chips for the bet % pFinal, hFinal: the number of chips that Player and Host have, respectively, at the end of the game. (b) Assume that function doubleGame from Part (a of it in order to implement the following function as specified: ) has been correctly implemented; make effective use function [count, playerAve] - manyDoubleGames (n,pStart,hStart) % simulate the "double game" n times, each time with Player starting with pStart chips % and Host starting with hStart chips. n, pStart, and hStart are each a positive % integer. % count is a vector of appropriate length such that count (k) is the number of times % that Player ends the game with k-1 chips. 1.e., count (1) is the number of times % that Player ends the game with 0 chip, count (2) is the number of times that Player ends the game with 1 chip,,etc. % playerAve is the average number of chips with which Player ends the game. % The only built-in function allowed is zeros. % Be run-time efficient for full credit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
