Matlab While loop help

1 visualización (últimos 30 días)
Patrick Flach
Patrick Flach el 30 de Mayo de 2017
Comentada: Patrick Flach el 4 de Jun. de 2017
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 comentarios
Patrick Flach
Patrick Flach el 30 de Mayo de 2017
Editada: James Tursa el 30 de Mayo de 2017
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 el 31 de Mayo de 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.

Iniciar sesión para comentar.

Respuestas (1)

ES
ES el 30 de Mayo de 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 comentarios
Torsten
Torsten el 31 de Mayo de 2017
Each year, iPopulation decreases by max(0.1*iPopulation,25) ...
Best wishes
Torsten.
Patrick Flach
Patrick Flach el 4 de Jun. de 2017
Just wanted to say that i've found the solution. Thx everyone for the help :)

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by