Use the Programming Language —- > 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 Your Function Save C Reset E MATLAB Documentation 1function currentPopulation – CalculatePopulation (numGeneration, initialPopulation) 2 % numGeneration: Number of times the population is doubled 3% currentPopulation : starting population value 4 5 % Loop variable counts number of iterations 6 currentPopulation initia!Population; = % Write a while loop that iterates numGeneration times 9 while () 10 % Write a statment that doubles currentPopulation in % each iteration of the while loop 12 13 14 15 16 17 end % Hint: Do not forget to update the loop variable Code to call vour function C Reset CalculatePopulation(2, 5)
Expert Answer
Copyable code:
File Name: CalculatePopulation.m
%Function CalculatePopulation
function currentPopulation = CalculatePopulation(numGeneration, initialPopulation)
%Set initial loop value
i=1;
%set currentPopulation
currentPopulation = initialPopulation;
%Loop
while(i<=numGeneration)
%Double the currentPopulation
currentPopulation = 2* currentPopulation;
%update i
i= i+1;
%end
end
%end
end