Using the \"rand\" function, you can simulate a random coin flip with any probab
ID: 673335 • Letter: U
Question
Using the "rand" function, you can simulate a random coin flip with any probability of a heads outcome: P(heads). For example, if P(heads) 0.60; consider the following MATLAB there are many ways to program this, but consider the following MATLAB >> x = rand >> if x-.0.40 >= 0 , y=1, else y=0, end >> % from the above, if y = 1, then the coin flip results in a "head" >> % from the above, if y = 0, then the coin flip results in a "tail" test the above using 1.000 samples of "x" also, test using 10,000 samplesExplanation / Answer
100 tosses with p=0.5
x=round(rand(100,1));
If you want a probability other than p=0.5 then realiza that rand() is uniform random number genrator between [0,1] so you assign the output of rand accordingly
for example p=0.6
y=zeros(100,1);
x=rand(100,1);
y(x<0.6)=1
And If you want to use rand fuction in MATLAB
100 tosses with 0 heads , 1 tails
coin=rand([0:1],[100,1])
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.