Matlab While loop help
조회 수: 1 (최근 30일)
이전 댓글 표시
Hey guys i've been sitting here for 2 hours not finding a solution. There's a population of 400 wildcats. How long will it take them to die out if every year the population is going down by 10% und at least 25. I should use a while loop. Thx in advance :)
댓글 수: 3
Adam
2017년 5월 31일
Try to work it out in pseudo-code or simple instructions first to make sure you understand the algorithm that is needed. Then you can worry about putting it into Matlab syntax.
답변 (1개)
ES
2017년 5월 30일
You mean this?
iPopulation = 400;
iYr=1;
while(iPopulation>25)
iPopulation = floor(0.9*iPopulation); % = 10% decrease
disp(['At the end of year ', num2str(iYr), ' the population is ', num2str(iPopulation)]);
iYr = iYr+1;
end
댓글 수: 6
Torsten
2017년 5월 31일
Each year, iPopulation decreases by max(0.1*iPopulation,25) ...
Best wishes
Torsten.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!