How to write a matlab code for this question?

조회 수: 2 (최근 30일)
Dr. Siva Malla
Dr. Siva Malla 2012년 10월 20일
In a forest, there were 'x' bunnies, 50% male, and 50% female, all adults. Bunnies doubles every 15 days, 10% of the baby rabbits dies at birth. They mature after 30 days, 30% leave the forest, and rest becomes rabbits. In every 30 days , 25% dies off due to flu. If every bunny dies off, the bunny world ends.
Task
Calculate the final number of bunnies alive after 1 year for any number of initial bunnies, x.
Input
Will be an integer number, the number of initial bunnies. Your program should read from the standard input
Output
Your program should write back to the standard output. When all bunnies die off, write 0 to the standard output.
Example
Test Case 1
444 (input)
0 (output)
Test Case 2
30000 (input)
56854 (output)
  댓글 수: 2
Walter Roberson
Walter Roberson 2012년 10월 20일
Walter Roberson
Walter Roberson 2012년 10월 20일
Please show your attempt, and describe any error messages you have encountered.

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

답변 (2개)

Matt J
Matt J 2012년 10월 20일
Hint - the information about 50% male, 50% female doesn't matter. There are no separate birth and death rules mentioned for males and females.

Matt J
Matt J 2012년 10월 20일
The general structure of the solution would probably be a for loop like this
for day=15:15:365
if mod(day,15)
%do 15 day birth/death update
end
if mod(day,30)
%do 30 day birth/death update
end
end

카테고리

Help CenterFile Exchange에서 Genomics and Next Generation Sequencing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by