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

nsqnonlin - Incorrect convergence - Fitted curve does not model my data at all

下图中,红叉为数据,蓝线为拟合曲线。

Data and fit curve - image

这是适合的函数:

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 数据。现在,您的 diff 是模型在 X 点对参数 x 的评估,但您应该 return diff - Ylsqnonlin 将最小化 returned 值的范数。这确实是你得到的,一个到处(几乎)为零的函数。