Simulate the tossing of a fair coin. Repeat the experiment 1000 and verify that the number of times in which a head appeared is almost 500.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
i cannot do the loop in this simulation please help
0 Kommentare
Antworten (1)
Image Analyst
am 22 Dez. 2014
That's fine, because a loop is not needed. Hint:
tosses = randi(2, 1,1000) - 1;
and I'm sure you've heard of the sum() function so make sure you don't name any variable in your program "sum".
1 Kommentar
Star Strider
am 22 Dez. 2014
Alternatively, you can specify a range for randi:
tosses = randi([0 1], 1, 1000);
and use nnz.
Siehe auch
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!