how to fit inverse proportional function

73 views (last 30 days)
x,y is a vectors. How to get a fitting function like y'=a/(x+b)+c
  2 Comments
Mikhail
Mikhail on 14 Nov 2014
DO you have curve fitting toolbox?
xiaoyan
xiaoyan on 14 Nov 2014
Yes, but I have many group data should be fitted respectively. I want to make it through command.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 14 Nov 2014
Edited: Star Strider on 14 Nov 2014
Your function could be difficult to fit. You can use the fminsearch function to estimate the parameters:
% Define ‘x’ and ‘y’ here
% Parameter Vector: b(1) = a, b(2) = b, b(3) = c
yfit = @(b,x) b(1)./(x + b(2)) + b(3); % Objective Function
CF = @(b) sum((y-yfit(b,x)).^2); % Cost Function
b0 = rand(1,3)*10; % Initial Parameter Estimates
[B, fv] = fminsearch(CF, b0); % Estimate Parameters
Note that ‘x’ and ‘y’ have to be defined in your workspace
  2 Comments
xiaoyan
xiaoyan on 14 Nov 2014
Thank you. It works, but could I keep one of the parameter larger than zero. For instance, in the case of b(2)>0, keep CF as small as possible.
Star Strider
Star Strider on 14 Nov 2014
My pleasure!
To constrain the parameters, you would have to use the Optimization Toolbox function lsqcurvefit. It is the only curve fitting function that allows parameter constraints. The ‘yfit’ function will work with it, so you only need to change the function call. Also, for lsqcurvefit, you do not need the ‘CF’ function, since lsqcurvefit calculates the cost function internally.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!