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 22:20
Pp 4.1 design and implement a class called sphere that contains instance data that represents the sphere’s diameter. define the sphere constructor to accept and initialize the diameter and include getter and setter methods for the diameter. include methods that calculate and return the volume and surface area of the sphere (see pp 3.5 for the formulas). include a tostring method that returns a one-line description of the sphere. create a driver class called multisphere, whose main method instantiates and updates several sphere objects.
Answers: 1
question
Computers and Technology, 24.06.2019 10:00
When writing a business letter, how many times can you use the same merge field in a document? once once, unless using the address block feature unlimited it will depend on the type of document you choose
Answers: 1
question
Computers and Technology, 24.06.2019 19:50
How to unblock on chrome book? ?
Answers: 1
question
Computers and Technology, 26.06.2019 04:00
Which is a characteristic of multimedia systems?
Answers: 1
You know the right answer?
Using MatLab: An insect population doubles every generation. Write a while loop that iterates numGen...
Questions
question
Social Studies, 03.10.2019 00:30
question
Mathematics, 03.10.2019 00:30
question
Mathematics, 03.10.2019 00:30