⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp_fit.m

📁 用matlab实现对已知数据的非线性拟合及数据预测
💻 M
字号:
clear all;
close all;
%数据输入
people=[13.2, 26.8, 33.2, 34.2, 48.4, 66.2, 71.4, 95,113.6, 144.4, 177.4, 209, 249.2, 295.6, 342.2, 377.6, 459, 491.4, 522.2, 540.2, 558.4];
time=1800:10:2000;
%绘制人口增长曲线
figure;
plot(time,people);
title('人口增长曲线');
xlabel('时间(年)');
ylabel('人口(百万)');
%使用非线性拟合
pro=lsqcurvefit(@my_fitfun,0.000001*ones(1,2),time,people);%y=N0*exp(r*t),需要调用my_fitfun这个函数,初值的选取会影响拟合的结果
N0=pro(1,1)
r=pro(1,2)
%计算后50年数据
time_future=2010:10:2050;
people_future=zeros(1,5);
for k=1:1:5
    people_future(1,k)=N0*exp(r*time_future(1,k));
end
%绘制新图
new_people=[people,people_future];
new_time=[time,time_future];
figure;
plot(new_time,new_people);
title('人口增长曲线(线性拟合估计2010至2050年)');
xlabel('时间(年)');
ylabel('人口(百万)');
people_future%显示估计的人口值

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -