Consider the random experiment of selecting a ball from an urn containing one bl
ID: 3537605 • Letter: C
Question
Consider the random experiment of selecting a ball from an urn containing one blue ball, two green balls and three red balls. UseMATLAB to simulate 10, 20, 30,...,200 trials of this experiment and record the color of selected ball at each trial. We suppose the experiment is such that the ball is immediately put back into the urn after each trial so there is always six balls in the urn. Calculate and plot the frequency of selecting each color (Use hist function in MATLAB). Calculate the relative frequency of selecting each color and generate a plot. What do you conclude about the probability of selecting each of the colors? (Use random function to generate the random selection of balls).
I really need help with the relative frequency plot I already have the frequency. I know that we need a for loop for 10-200 trials going by 10's. the graph should look similar to this but with three lines representing the three different color balls
Explanation / Answer
blue=1;
green=2;
red=3;
balls = [ 1 ,2 ,2,3,3,3 ];
trials= [10:10:200];
rel_freq=zeros(3,length(trials));
for i=1:length(trials)
for j=1:trials(i)
r=randi([1,6]);
ball=balls(r);
rel_freq(ball,i) =rel_freq(ball,i) +1;
end
rel_freq(1,i)=rel_freq(1,i)/trials(i);
rel_freq(2,i)=rel_freq(2,i)/trials(i);
rel_freq(3,i)=rel_freq(3,i)/trials(i);
end
plot(trials,rel_freq(1,:),'-b.','MarkerSize',20);
hold on;
plot(trials,rel_freq(2,:),'-g.','MarkerSize',20);
plot(trials,rel_freq(3,:),'-r.','MarkerSize',20);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.