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

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 05:10
Read the code below. what will the computer print if the input for year_variable is 1700? if year_variable == 1776: print("your answer is correct. the declaration of independence was signed in “year_variable”.") elif year_variable < 1776: compute_variable = 1776 - year_variable. print("add “compute_variable“ years to your answer for the correct answer.") elif year_variable > 1776: compute_variable = year_variable - 1776 print("subtract “compute_variable” years from your answer for the correct answer.")
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
The isometric projection camera technique provides an illusion of perspective by using things like parallax scrolling to create the illusion of 3d in a 2d game
Answers: 3
question
Computers and Technology, 22.06.2019 21:00
Ulia is planning to attend the same private four-year college her parents attended. she wants to save at least $18,000 in four years to contribute to her college education. which monthly deposit amounts can julia use to achieve her goal? check all that apply.
Answers: 2
question
Computers and Technology, 23.06.2019 03:00
State 7 common key's for every keyboard
Answers: 1
You know the right answer?
Using MatLab: An insect population doubles every generation. Write a while loop that iterates numGen...
Questions
question
Mathematics, 12.11.2020 01:00
question
Mathematics, 12.11.2020 01:00
Questions on the website: 13722363