Here are two vectors representing the census years from 1810 to 1900 and the corresponding population of a certain country in millions of people:
1810 到 1900 年每隔10年人口如下
[74.875 92.552 107.231 120.153 130.879 152.427 180.383 202.352 227.485 250.597];
Please use MATLAB to estimate the population in 1865, you must hand in your source code and plot the result.
最好有matlab的源代码
clear
clf
x=1810:10:1900;
y=[74.875 92.552 107.231 120.153 130.879 152.427 180.383 202.352 227.485 250.597];
plot(x,y,'s','markersize',3)
grid on
%画图并观察离散数据的特性
p=polyfit(x,y,1);
%用1次多项式进行拟合
f = polyval(p,x);
hold on
plot(x,f,'r');
xlabel('年份')
ylabel('人口')
title('拟合曲线')
%在同一个坐标内画出拟合曲线和原有离散数据
p
%显示拟合多项式系数
p1865=polyval(p,[1865])
%估计1865年的人口数量
#################################################################
运行结果:
p =
1.0e+003 *
0.0019 -3.4480
p1865 =
173.3108