MATLAB问题求助

clear all
clc
t=[0.25 0.5 0.75 1 1.5 2 2.5 3 3.5 4 4.5 5 6 7 8 9 10 11 12 13 14 15 16]';
c1=[30 68 75 82 82 77 68 68 58 51 50 41 38 35 28 25 18 15 12 10 7 7 4]';
f=@(a,t)(3.965*((-a(1)/(a(2)-a(1)))*exp(-a(2)*t)+(a(1)/(a(2)-a(1)))*exp(-a(1)*t)));
nlinfit(t,c1,f,[3 3])

运行报错:
错误使用 nlinfit (line 239)
No usable observations after removing NaNs in Y and in the result of evaluating MODELFUN at the initial value BETA0.

出错 Untitled (line 6)
nlinfit(t,c1,f,[3 3])

检测你的程序代码后,就你的错误分析如下:

一、错误警告
No usable observations after removing NaNs in Y and in the result of evaluating MODELFUN at the initial value BETA0.

上述警告的意思是,初值( value BETA0)选择有问题,不能满足求解方程的条件。

二、自定义函数与实际数据有很大的偏差,实际数据不能满足自定义函数拟合要求。从t—x的散点图(可以用plot(t,x)命令)(说明,这里用x代替c1)可以看到,数据符合高斯函数,即  f(t)=a1*exp(-((t-b1)/c1)²) + a2*exp(-((t-b2)/c2)²)

自定义函数  func=@(a,t)(a(1)*exp(-((t-a(2))/a(3)).^2)+a(4)*exp(-((t-a(5))/a(6)).^2));

三、初值按t0=[0.45 0.77 0.32 0.78 0.47 0.04]初选

四、用a=nlinfit(t,x,func,t0)命令,求解自定义函数的系数

五、修改程序后,运行得到

温馨提示:答案为网友推荐,仅供参考
相似回答