I am having a difficult time with this assignment. Will someone please help me f
ID: 3316174 • Letter: I
Question
I am having a difficult time with this assignment. Will someone please help me figure this out?
Project 2: Suppose a gambler can bet $20 in a game each time, in which, the House wins by a 51% chance and the player wins by a 49% chance. Suppose the gambler have $100 initially. The player plans to stop once he won $200. What is the chance that he is going to be able to successfully carry out this plan? You may perform a Matlab experiment to empirically get an estimation of this chance. That is, 1. Generate a random variable that has a 49% of being one to mimic the win in the gambling game. 2. Add $20 each time a one shows up, and subtract $20 otherwise 3. Repeat the procedure until either that the total dollar amount reaches $200 or the total dollar amount reduces to 0. To generate a random variable with 49% of being one, use the uniform random variable. x-rand(# of rows, # of columns); X will be a matrix of uniform random variables betweenlo0.1]. To generate a single variable, set both ro and column to one. If X> 0.51, then set the chance variable C to one, otherwise set it to zero. This variable c will have a 49% chance of being one. 4. Report the chance of winning $200 and stop out of 100 trials.Explanation / Answer
clc
clear all
c=zeros(10,10);temp=0;
win=0;loose=0;
for i=1:100
amount=100;
count=0;
x=rand(10,10);
[m,n]=size(x);
for j=1:m
for k=1:n
if(x(j,k)>=0.51)
c(j,k)=1;
count=count+1;
amount=amount+20;
else
amount=amount-20;
end
if(amount==200)
win=win+1;
m=0;
break
end
if(amount==0)
loose=loose+1;
m=0;
break
end
end
if(amount==200||amount==0)
break
end
end
end
percentwin=(win/100)*100;
fprintf('Win percentage is %f: ', percentwin)
output:
1st execution
Win percentage is 49.000000:
2nd execution
Win percentage is 51.000000:
Since probabilities are randomly distributed the win percentage of the gambler varies each execution time.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.