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, 24.06.2019 14:30
In a home that has 120 v service, there is an electric appliance that has a resistance of 12 ohms. how much power will this appliance consume? a. 10 w b. 120 w c 1200 w d. 1440 w
Answers: 1
question
Computers and Technology, 24.06.2019 21:40
Which of these is not a type of socket? aga (alternating grid array) pga (pin grid array) spga (staggered pin grid array) lga (land grid array)
Answers: 1
question
Computers and Technology, 25.06.2019 04:30
What is the purpose of network permissions? a)to control access to network resources b)to convert to wireless networking c)to enable the installation of nics d)to reduce operating costs
Answers: 1
question
Computers and Technology, 25.06.2019 08:30
Acollection of computers and other devices that are connected together to enable users to share hardware, software, and data, as well as to communicate electronically with each other is called
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, 04.10.2020 23:01
question
Mathematics, 04.10.2020 23:01
question
Spanish, 04.10.2020 23:01
Questions on the website: 13722361