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 ビュー (過去 30 日間)
古いコメントを表示
i cannot do the loop in this simulation please help
0 件のコメント
回答 (1 件)
Image Analyst
2014 年 12 月 22 日
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 件のコメント
Star Strider
2014 年 12 月 22 日
Alternatively, you can specify a range for randi:
tosses = randi([0 1], 1, 1000);
and use nnz.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!