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

Jan
Jan 2017년 5월 30일
As usual for question, which sound like homework: Posting a working solution is less useful than trying to assist you to solve the problem by your own. So please post, what you have tried so far and ask a specific question.
Patrick Flach
Patrick Flach 2017년 5월 30일
편집: James Tursa 2017년 5월 30일
ok sry! for better understanding: i've only one course at university where i use Matlab, so i don't have any experience in it. the only example i'v in my sheets is this one:
x=1
while x<100
Anweisungen;
end
nevermind the language it's german. i have to use a counter and not the display function to show how much iterations it takes till the population dies out. so i know how to use the counter but i don't really know how i can express the decrease of -10% and at least 25 per year in a while loop.
Adam
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
ES 2017년 5월 30일

0 개 추천

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

Jan
Jan 2017년 5월 30일
편집: Jan 2017년 5월 30일
Patrick cannot provide this as his own solution now. Posting working solutions to homework questions has the disadvantage, that the user might look like he is cheating. It is better to help them to find the solution by their own.
John D'Errico
John D'Errico 2017년 5월 30일
Posting a complete answer to a homework problem is generally to be avoided. This does not help the person asking. It just convinces them there will always be someone willing to do their work for them.
Walter Roberson
Walter Roberson 2017년 5월 30일
This is not completely correct. The population decrease should be 10 percent or 25 whichever is larger
Patrick Flach
Patrick Flach 2017년 5월 31일
yeah and thats the problem i can't solve :(
Torsten
Torsten 2017년 5월 31일
Each year, iPopulation decreases by max(0.1*iPopulation,25) ...
Best wishes
Torsten.
Patrick Flach
Patrick Flach 2017년 6월 4일
Just wanted to say that i've found the solution. Thx everyone for the help :)

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

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2017년 5월 30일

댓글:

2017년 6월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by