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!