subject

Using MatLab: An insect population doubles every generation. Write a while loop that iterates numGeneration times. Inside the while loop, write a statement that doubles currentPopulation in each iteration of the while loop.

I have set up the following code, but it only works for the first and third assessement checks.

function currentPopulation = CalculatePopulation(numGeneration, initialPopulation)
% numGeneration: Number of times the population is doubled
% currentPopulation: Starting population value

i = 2; % Loop variable counts number of iterations
currentPopulation = initialPopulation;

% Write a while loop that iterates numGeneration times
while ( i <= numGeneration )
currentPopulation = currentPopulation * (i * 2);
i = i * 2;
end
% Write a statment that doubles currentPopulation in
% each iteration of the while loop

% Hint: Do not forget to update the loop variable
end

Assessment Checks:

1. CalculatePopulation(2, 5) returns 20

2. CalculatePopulation(10, 4) returns 4096 << This is the one that won't work

3. Calculate Population (0, 78) returns 78

Could someone tell me where I went wrong with my coding?

ansver
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 00:30, angoraspinner
These tools give presenters more freedom to move about the room and interact with their audience. laptop computer laser pointer lcd projector remote control
Answers: 2
image
Computers and Technology, 23.06.2019 00:30, devenybates
Which one of the following is the most accurate definition of technology? a electronic tools that improve functionality b electronic tools that provide entertainment or practical value c any type of tool that serves a practical function d any type of tool that enhances communication
Answers: 1
image
Computers and Technology, 24.06.2019 02:00, sameh0425
Which steps will open the system so that you can enter a question and do a search for
Answers: 1
image
Computers and Technology, 24.06.2019 06:00, bzhsh8282
Hey i really need some solving this problem: 1. encrypt this binary string into cipher text: 110000. include in your answer the formula the decoder would use to decrypt your cipher text in the format (coded answer) x n mod (m) = y & 2. decrypt this cipher text into a binary string: 106 you.
Answers: 2
You know the right answer?
Using MatLab: An insect population doubles every generation. Write a while loop that iterates numGen...

Questions in other subjects:

Konu
History, 08.03.2021 22:30
Konu
Chemistry, 08.03.2021 22:30
Konu
English, 08.03.2021 22:30