In: Mechanical Engineering
The population data for a certain country are as follows:
Obtain a function that describes these data. Plot the function and the data on the same plot. Estimate when the population will be double its 2004 size.
Function using MATLAB script:
clc;close all;clear all;
year= linspace(2004,2009,6);
population = [10 10.9 11.7 12.6 13.8 14.9];
P = polyfit(year,population,3);
year1 = linspace(2004,2014,21);
PP = polyval(P,year1);
figure
plot(year,population,\'o\')
hold on
plot(year1,PP)
hold off;grid;
xlabel(\'year\');ylabel(\'Poulation(millions)\');
title(\'Population data\')
y2004=population(find(year ==2004));
y=min(year1(find(round(PP)>=2*y2004)));
fprintf(\'The population will be double in the year %d as the population of the year 2004.\\n \',y)
Command window:
The population will be double in the year 2012 as the population of the year 2004.
Function using MATLAB script:
clc;close all;clear all;
year= linspace(2004,2009,6);