필터 지우기
필터 지우기

how to write matlab code for following problem

조회 수: 1 (최근 30일)
praveen yadav
praveen yadav 2017년 10월 1일
답변: Neil Sheridan 2018년 10월 16일
  댓글 수: 1
Stephen23
Stephen23 2017년 10월 1일
편집: Stephen23 2017년 10월 1일
"how to write matlab code for following problem"
  • First understand the problem: do some reading about it, learn about the mathematics it uses, try some worked examples.
  • Think about an algorithm, try it with pencil and paper.
  • Consider how to convert that algorithm to code. Read the documentation for all operations that you consider using.
  • Implement the code. Test each line as you write it. Check that it does what you expect.

댓글을 달려면 로그인하십시오.

답변 (2개)

Yogananda Jeppu
Yogananda Jeppu 2017년 10월 1일
For the simulation Make a large vector a multiple of 30 (why?). For the first set with probability of 50% make half the vector as 1 (boys) and other half 0 (girls). Shuffle this array. A good way to shuffle is a generate a random array of the same size as the large vector. Sort and keep track of the index. The index is the shuffled set. See help rand, sort for this. Reshape the vector to Nx5 array. Each row is a family. See help reshape. Use sum() to see how many boys in each family. Find rows (families) where boys are three. See help find. See what is the probability out of N. Run for multiple iteration. Enjoy Matlab.

Neil Sheridan
Neil Sheridan 2018년 10월 16일
mean(sum(rand(5,10^7)<1/3)==3)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by