MATLAB数据拟合到逆二次方程式 [英] MATLAB fitting of data to a inverse quadratic equation

查看:158
本文介绍了MATLAB数据拟合到逆二次方程式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆数据,并且想要拟合一个我想要的函数,例如1/(ax^2+bx+c).我的目标是获取a,b,c值.

I have a bunch of data, and I want a fitting with a function that I want, for example, 1/(ax^2+bx+c). My objective is to get a,b,c values.

MATLAB有什么功能可以帮助您解决此问题吗?我一直在检查fit()函数,但是没有得出结论.最好的方法是什么?

Is there any function of MATLAB that helps with this? I have been checking the fit() function, but I didn't reach a conclusion. Which is the best way?

推荐答案

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

The model you give can be solved using simple methods:

% 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.')

结果:

ans = 
 3.035753123094593e+00  % (a)
 4.029749103502019e+00  % (b)
-8.038644874704120e+00  % (c)

之所以可行,是因为您提供的模型是线性模型,在这种情况下,反斜杠运算符将给出解决方案(尽管1./y有点危险...)

This is possible because the model you give is a linear one, in which case the backslash operator will give the solution (the 1./y is a bit dangerous though...)

在拟合非线性线性模型时,请查看lsqcurvefit(优化工具箱),或者您可以使用fmincon(优化工具箱),fminsearchfminunc.

When fitting non-linear models, take a look at lsqcurvefit (optimization toolbox), or you can write your own implementation using fmincon (optimization toolbox), fminsearch or fminunc.

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

Also, if you happen to have the curve fitting toolbox, type help curvefit and start there.

这篇关于MATLAB数据拟合到逆二次方程式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆