检测你的程序代码后,就你的错误分析如下:
一、错误警告
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)命令,求解自定义函数的系数
五、修改程序后,运行得到
subplot(2,2,1)
x=0:3;
plot(x,x)
subplot(2,2,2)
x=-1:1;
plot(x,x.*sin(x))
subplot(2,2,3)
x=0:.1:1.5
plot(x,x.^2)
subplot(2,2,4)
x=0:.1:1.3
plot(x,tan(x))
我看了下边的哦哥们的图像,画的很不错,他是在4个坐标系下画的。
但是不知道你是不是要他那样的图,我再给你一个做法,就是在一个坐标系下画出所有的图。
x=0:3;
plot(x,x)
hold on
x=-1:1;
plot(x,x.*sin(x))
hold on
x=0:.1:1.5
plot(x,x.^2)
hold on
x=0:.1:1.3
plot(x,tan(x))