Question & Answer: Assign finalPopulation with the population size given an initial population, population growth rate, and number of years. The popu…..

Assign finalPopulation with the population size given an initial population, population growth rate, and number of years. The population growth is calculated by: Final population = Initial population* (1 + Rate of growth)Number of years Your Function B Save C Reset I a MATLAB Documentation 1 % Create a function name CalculatePopulation (O to calculate the population. 3 function final Population = CalculatePopulation (initialPopulation, growthRate, numberYears ) 5 % Assign final Population with the population size given an 7 % initial population, population growth rate , and number of years 9 finalPopulation = initiatPopulation * ((1 + growthRate).numberYears); 10 11 12 13 % Call the function calculatePopulation() to findd the final population. 14 15 S=sprintf(Final population = f , CalculatePopulation (10000, 0.06, 20) ); 16 17% Display the final population. 18 19 disp (S) 21 % Call the function calculatePopulation() to findd the final population. 23 S=sprintf(Final population = f , CalculatePopulation (10000, 0.40, 10)); 25 % Display the final population.

Assign finalPopulation with the population size given an initial population, population growth rate, and number of years. The population growth is calculated by: Final population = Initial population* (1 + Rate of growth)Number of years Your Function B Save C Reset I a MATLAB Documentation 1 % Create a function name “CalculatePopulation (O” to calculate the population. 3 function final Population = CalculatePopulation (initialPopulation, growthRate, numberYears ) 5 % Assign final Population with the population size given an 7 % initial population, population growth rate , and number of years 9 finalPopulation = initiatPopulation * ((1 + growthRate).numberYears); 10 11 12 13 % Call the function “calculatePopulation()” to findd the final population. 14 15 S=sprintf(‘Final population = f “, CalculatePopulation (10000, 0.06, 20) ); 16 17% Display the final population. 18 19 disp (S) 21 % Call the function “calculatePopulation()” to findd the final population. 23 S=sprintf(‘Final population = f “, CalculatePopulation (10000, 0.40, 10)); 25 % Display the final population.

Expert Answer

 

Your previous function was correct except that in your question, it seems that it’s asking to just calculate the value of final population in the function body. But looking at your code, it was printing the value using sprintf and disp() which is not supposed to be printed by a function because a function is made to calculate and return a value not to calculate and print it.

So you need to replace your previous function with the below one.

Corrected Matlab Function Code
function finalPopulation = CalculatePopulation(initialPopulation, growthRate, numberYears)
format long g

finalPopulation = initialPopulation * (1 + growthRate)^numberYears;
end

Still stressed from student homework?
Get quality assistance from academic writers!