How can I find the best fit to a bunch of data?

1 view (last 30 days)
Hi,
I am trying to find the best fitting to a bunch of data. I keep getting an error as below:
x = lsqcurvefit(@fcn,[.2, .2, .2] ,[T, V, M] , ones(93, 1)); ??? Error using ==> lsqcurvefit at 253 Function value and YDATA sizes are incommensurate.
Below are my m-files:
x = lsqcurvefit(@fcn,[.2, .2, .2] ,[T, V, M] , ones(93, 1));
function out = fcn(param, x) alpha = param(1); beta = param(2); gamma = param(3); T = x(1); V = x(2); M = x(3); out =(T/550)^alpha + (V/100)^beta + (M/30)^gamma;
Any help will be appreciated.

Answers (1)

Matt J
Matt J on 9 Dec 2012
Edited: Matt J on 9 Dec 2012
I'm assuming the lengths of T,V, and M are each 31. If so, you probably meant to do this:
x = lsqcurvefit(@fcn,[.2, .2, .2] ,[T,V,M] , ones(31, 1));
function out = fcn(param, x)
alpha = param(1);
beta = param(2);
gamma = param(3);
T = x(:,1); V = x(:,2); M = x(:,3);
out =(T/550)^alpha + (V/100)^beta + (M/30)^gamma;
  4 Comments
Amir
Amir on 9 Dec 2012
Edited: Amir on 9 Dec 2012
Thank you, It seems that it works now with the below comment:
Local minimum possible. lsqcurvefit stopped because the size of the current step is less than the default value of the step size tolerance. criteria details * *Optimization stopped because the norm of the current step, 6.612031e-008, is less than options.TolX = 1.000000e-006.
Optimization Metric Options norm(step) = 6.61e-008 TolX = 1e-006 (default)* *
Any suggestion?
Amir,
Matt J
Matt J on 9 Dec 2012
See if the fit is good. If not, try to find a better initial guess.

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!