how to match curve with equations?

3 views (last 30 days)
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)

Accepted Answer

Star Strider
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
Steve Harvey
Steve Harvey on 22 Mar 2015
Edited: Steve Harvey on 22 Mar 2015
Thanks
I'm trying to use this http://www.mathworks.com/help/curvefit/custom-nonlinear-models.html to do the fitting, but I'm not sure how to use it
I have x and y column vectors that produce the red curve and I want to fit that data to the custom equations in the red boxes(which are functions of 4 variables). So I typed sftool(x,y) and got this
Currently, I can only enter a custom function in terms of one variable. What should I do to make it so that I can enter a function of 4 variables?
Star Strider
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.

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!