求用y=a*exp(b*x)+c的方程用matlab来拟合,求参数值。 25
clear all;
close all;
x=[2011,2010,2009,2008,2007,2006,2005,2004,2003,2002]
y=[ 318230243.6700 229797398.1700 184142192.5300 151118088.6100 192241044.9000 102483106.6400 81462390.8900 64753538.3300 62066553.2900 77369354.7500 ]
f= inline('c(1)+c(2)*exp(x*log(c(3)))','c','x');
opt=optimset('TolFun',1e-3,'TolX',1e-3);
c = lsqcurvefit(f, [0,0,-1], x, y);
plot(x,y, '-o', x, f(c, x), 'r:x');
legend('原始数据', '拟合函数')
a = c(1)
b = c(2)
c = c(3)
拟合图如下,要哭了!! 展开
从图上可以看出,选用y=a*exp(b*x)+c进行拟合是不对的,应改用polynomial中的
cubic polynomial,我试着拟合得:
Linear model Poly3:
f(x) = p1*x^3 + p2*x^2 + p3*x + p4
where x is normalized by mean 2007 and std 3.028
Coefficients (with 95% confidence bounds):
p1 = 1.903e+006 (-3.354e+007, 3.734e+007)
p2 = 2.888e+007 (5.686e+005, 5.719e+007)
p3 = 7.472e+007 (1.333e+007, 1.361e+008)
p4 = 1.204e+008 (8.642e+007, 1.543e+008)
Goodness of fit:
SSE: 5.048e+015
R-square: 0.922
Adjusted R-square: 0.883
RMSE: 2.901e+007
画出图如下,
可是我写的论文要求是要用y=a*exp(b*x)+c这种指数函数来拟合的,因为会用到参数a,b,c的性质比较,请问高手,您有什么高招,把参数a,b,c求出来吗?一定重谢啊