MATLAB将数据拟合到逆二次方程

And*_*uri 1 matlab curve-fitting

我有一堆数据,例如,我想要一个我想要的功能1/(ax^2+bx+c).我的目标是获得a,b,c值.

MATLAB有什么功能可以帮助解决这个问题吗?我一直在检查fit()功能,但我没有得出结论.哪种方式最好?

Rod*_*uis 5

您提供的模型可以使用简单的方法解决:

% model function
f = @(a,b,c,x) 1./(a*x.^2+b*x+c);

% noise function 
noise = @(z) 0.005*randn(size(z));

% parameters to find
a = +3;
b = +4;
c = -8;

% exmample data
x = -2:0.01:2;    x = x + noise(x);
y = f(a,b,c, x);  y = y + noise(y);


% create linear system Ax = b, with 
% A = [x²  x  1]
% x = [a; b; c]
% b = 1/y;
A = bsxfun(@power, x.', 2:-1:0);

A\(1./y.')
Run Code Online (Sandbox Code Playgroud)

结果:

ans = 
 3.035753123094593e+00  % (a)
 4.029749103502019e+00  % (b)
-8.038644874704120e+00  % (c)
Run Code Online (Sandbox Code Playgroud)

这是可能的,因为你给出的模型是线性模型,在这种情况下,反斜杠运算符将给出解决方案(1./y虽然......有点危险)

在拟合非线性模型时,请查看lsqcurvefit(优化工具箱),或者您可以使用fmincon(优化工具箱)编写自己的实现, fminsearch或者fminunc.

此外,如果您碰巧有曲线拟合工具箱,请键入help curvefit并从那里开始.