how to fit inverse proportional function
73 views (last 30 days)
Show older comments
x,y is a vectors. How to get a fitting function like y'=a/(x+b)+c
2 Comments
Accepted Answer
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
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.
More Answers (0)
See Also
Categories
Find more on Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!