Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: help with assigment Date: Fri, 24 Jun 2011 21:11:04 +0000 (UTC) Organization: The MathWorks Inc Lines: 86 Message-ID: <iu2uh8$jj0$1@newscl01ah.mathworks.com> References: <iu2plk$55e$1@newscl01ah.mathworks.com> <iu2r2l$9nn$1@newscl01ah.mathworks.com> <iu2rje$b98$1@newscl01ah.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: www-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: newscl01ah.mathworks.com 1308949864 20064 172.30.248.37 (24 Jun 2011 21:11:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Fri, 24 Jun 2011 21:11:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1597503 Xref: news.mathworks.com comp.soft-sys.matlab:733631 "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 3-4 lines of code. Read the MATLAB Getting Started Guide for help on basic MATLAB array operations. Wayne