how to match curve with equations?
3 views (last 30 days)
Show older comments
Steve Harvey
on 22 Mar 2015
Commented: Star Strider
on 22 Mar 2015
Is there a simple way for Matlab to keep testing coefficients of the two equations in the red box such that the above curve is produced?
(I have another known function that produces the curve)
0 Comments
Accepted Answer
Star Strider
on 22 Mar 2015
There is. MATLAB has several functions and one Toolbox devoted to solving that problem, called parameter estimation.
See specifically the Statistics Toolbox nlinfit, the Optimization Toolbox lsqcurvefit, the core MATLAB function fminsearch functions, and the Curve Fitting Toolbox for details.
2 Comments
Star Strider
on 22 Mar 2015
My pleasure.
I don’t believe you’re estimating four parameters, since I suspect ‘theta2’ and ‘theta4’ are your independent variables. That means you are estimating only three, ‘r2’, ‘a’ and ‘b’ (since ‘beta’ is a function of ‘a’ and ‘b’).
I would use this as my objective (model) function:
% MAPPING: B(1) = r2, B(2) = b, B(3) = c, Th24 = [theta2(:) theta4(:)];
pathfun = @(B, Th24) [B(1).*cos(Th24(:,1))+hypot(B(2),B(3)).*cos(Th24(:,2)+atan(B(3)/B(2))-pi/2); B(1).*sin(Th24(:,1))+hypot(B(2),B(3)).*sin(Th24(:,2)+atan(B(3)/B(2))-pi/2)];
Note that you are fitting two equations as a matrix, to match ‘xp’ and ‘yp’, so you have to have a matrix of dependent variables as well.
I would use lsqcurvefit for this problem were I estimating its parameters. Since I don’t have the Curve Fitting Toolbox, I can’t help you further, except to say that my ‘pathfun’ function should work with it as well.
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!