Matlab nsqnonlin-不正确的收敛-拟合曲线根本不对我的数据建模

Matlab nsqnonlin-不正确的收敛-拟合曲线根本不对我的数据建模,matlab,curve-fitting,non-linear-regression,Matlab,Curve Fitting,Non Linear Regression,下面,红色的十字是数据,蓝色的线是拟合曲线 这是正在安装的功能: function diff = fit_simp(x,X,Y) % This function is called by lsqnonlin. % x is a vector which contains the coefficients of the % equation. X and Y are the option data sets that were % passed to lsqnonlin. A1 = x(1

下面,红色的十字是数据,蓝色的线是拟合曲线

这是正在安装的功能:

function diff = fit_simp(x,X,Y)

% This function is called by lsqnonlin.
% x is a vector which contains the coefficients of the
% equation.  X and Y are the option data sets that were
% passed to lsqnonlin.

A1 = x(1);
A2 = x(2);
mode1 = x(3);
mode2 = x(4);
sig1 = x(5);
sig2 = x(6);
alpha = x(7);
beta = x(8);
gamma = x(9);
diff = (A1/(sqrt(2*pi)*sig1))*exp(-0.5.*((X-mode1)/sig1).^2) + (A2/(sqrt(2*pi)*sig2))*exp(-0.5.*((X-mode2)/sig2).^2) + alpha + beta*X + gamma*X.*X
我的起始值是:

X0=[0.1 0.02 0.6 1.2 1 1 0.1 -0.2 0.011]
来自MATLAB的最后一条消息:

Optimization completed: The first-order optimality measure, 3.114006e-10,
is less than options.OptimalityTolerance = 1.000000e-06.

Optimization Metric                                       Options
relative first-order optimality =   3.11e-10  OptimalityTolerance =   1e-06 (default)

有什么我遗漏的吗?它适用于更简单的函数

您没有使用您的
Y
数据。现在,对于参数
X
,您的
diff
是在
X
点对模型的评估,但您应该返回
diff-Y
lsqnonlin
将最小化返回值的范数。这确实是你得到的,一个函数,它(几乎)处处为零