MATLAB fitting of data to a inverse quadratic equation

牧云@^-^@ 提交于 2019-12-11 08:08:21

问题


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.

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?


回答1:


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

Result:

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

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

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.

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




回答2:


To me this sounds like a least squares problem.

I think lsqcurvefit might be a good place to start:

http://www.mathworks.co.uk/help/optim/ug/lsqcurvefit.html




回答3:


I don't know whether this post is useful after 3 months or not. i think cftool may help you check it

easily you can add data and select fitting method ....



来源:https://stackoverflow.com/questions/12970043/matlab-fitting-of-data-to-a-inverse-quadratic-equation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!