Matlab While loop help
Mostra commenti meno recenti
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 Commenti
Jan
il 30 Mag 2017
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
il 30 Mag 2017
Modificato: James Tursa
il 30 Mag 2017
Adam
il 31 Mag 2017
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.
Risposte (1)
ES
il 30 Mag 2017
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 Commenti
John D'Errico
il 30 Mag 2017
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
il 30 Mag 2017
This is not completely correct. The population decrease should be 10 percent or 25 whichever is larger
Patrick Flach
il 31 Mag 2017
Torsten
il 31 Mag 2017
Each year, iPopulation decreases by max(0.1*iPopulation,25) ...
Best wishes
Torsten.
Patrick Flach
il 4 Giu 2017
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!