"percy sears" wrote in message <iu2rje$b98$1@newscl01ah.mathworks.com>...
> "Wayne King" <wmkingty@gmail.com> wrote in message <iu2r2l$9nn$1@newscl01ah.mathworks.com>...
> > "percy sears" wrote in message <iu2plk$55e$1@newscl01ah.mathworks.com>...
> > > hello i a new comer. can anyone help me with this assignment .
> > > Simulation of tossing a pair of fair dice can be done using the following two
> > > MATLAB lines
> > > X=ceil(6*rand(1,n));
> > > Y=ceil(6*rand(1,n));
> > > where n is the number of tosses.
> > > Write a MATLAB script to determine the probability P[X+Y=7]. Use a “for” loop
> > > to run simulation fifty times with n = 10000. Plot the 100 estimated probability
> > > values along with the theoretical result of P[X+Y=7].
> > > 2.
> > > Write a MATLAB script to do the following
> > > a. Create 10000 random variables uniformly distributed between 2 and 4.
> > > b. Create a histogram to approximate the actual probability density function.
> > > c. Superimpose the actual probability density function to the above histogram.
> >
> > Hi Percy, You should show the code you've written and where you are getting stuck.
> > People on this forum are very generous in helping you with specific code, but are generally not receptive to posts that just contain the problem statement.
> >
> > Wayne
>
> For question 1
>
> n=1000;
> m=10000;
>
>
> T=100;
>
> for k=1:m
>
> P=0;
> X=ceil(6*rand(1,n));
> Y=ceil(6*rand(1,n));
>
> for j=1:n
> if X(j)+Y(j) == 7;
> P=P+1;
> end
> end
>
> disp('Trial: ')
> k;
> disp('Success Rate: ')
> P=P/n;
>
> Xaxis(k) = k;
> Yaxis(k) = P;
> T=T+P;
> end
>
> disp('Total Average: ')
> T/m;
>
> plot(Xaxis,Yaxis);
>
> clear;
Hi Percy, Welcome to MATLAB, I'll just comment on the first part of your problem.
> X=ceil(6*rand(1,n));
> Y=ceil(6*rand(1,n));
> where n is the number of tosses.
> Write a MATLAB script to determine the probability P[X+Y=7]. Use a “for” loop
> to run simulation fifty times with n = 10000. Plot the 100 estimated probability
> values along with the theoretical result of P[X+Y=7].
Each time you call
n = 10000;
X = ceil(6*rand(1,n));
you are getting a simulation of 10,000 rolls of a single die.
Y = ceil(6*rand(1,n));
is another (independent) 10,000 rolls.
The problem is asking you to form another random variable, which is the sum of the two rolls. So you have two vectors of equal size, how would you form their sum in MATLAB? That is the random variable you are looking for. To determine the probability, you have 10,000 trials. Think about how you would count the number of 7's you observe and divide that by the total number of trials.
Then you are asked to repeat that experiment 50 times (with a for loop).
With MATLAB array operations, each experiment should only be about 34 lines of code. Read the MATLAB Getting Started Guide for help on basic MATLAB array operations.
Wayne
