matlab,最小二乘法,指数型函数
time=0:1:24;tem=[15,14,14,14,14,15,16,18,20,20,23,25,28,31,32,31,29,27,25,24,22,20,18...
time=0:1:24;tem=[15,14,14,14,14,15,16,18,20,20,23,25,28,31,32,31,29,27,25,24,22,20,18,17,16];用指数型函数a*exp(-b*(t-c)^2)进行最小二乘法拟合,求出a ,b,c参数,并画出拟合曲线求完整的matlab程序,完整的程序!
展开
2个回答
展开全部
问题分析
你给的拟合公式一有些问题,很难达到理想的拟合效果,参考代码如下:
time = 0:1:24;
tem = [15,14,14,14,14,15,16,18,20,20,23,25,28,31,32,31,29,27,25,24,22,20,18,17,16];
f = inline('x(1)*exp(-x(2)*(t-x(3)).^2)', 'x', 't');
x0 = [30 0.1 15];
x = lsqcurvefit(f,x0,time,tem)
plot(time,tem,'-o',time,f(x,time),'r.:');
得到的拟合系数(依次为a、b、c):
Optimization terminated: relative function value
changing by less than OPTIONS.TolFun.
x =
27.7940 0.0057 14.2074
改进拟合公式
如果考虑修改拟合公式,加入一个常数项d,即a*exp(-b*(t-c)^2)+d,则代码修改如下:
time = 0:1:24;
tem = [15,14,14,14,14,15,16,18,20,20,23,25,28,31,32,31,29,27,25,24,22,20,18,17,16];
f = inline('x(1)*exp(-x(2)*(t-x(3)).^2)+x(4)', 'x', 't');
x0 = [30 0.1 15 14];
x = lsqcurvefit(f,x0,time,tem)
plot(time,tem,'-o',time,f(x,time),'r.:');
程序运行结果如下:
Optimization terminated: relative function value
changing by less than OPTIONS.TolFun.
x =
16.6593 0.0283 14.5690 14.1598
由图可见,效果相对而言比较理想。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询