作业帮 > 综合 > 作业

如何用matlab进行数据拟合,在进行数据的估计?

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/09 15:50:03
如何用matlab进行数据拟合,在进行数据的估计?
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