Asked by Amir
on 8 Dec 2012

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.

Answer by Matt J
on 9 Dec 2012

Edited by 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;

bym
on 9 Dec 2012

well then, do as the error suggests, as follows

out =(T/550).^alpha + (V/100).^beta + (M/30).^gamma;

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
on 9 Dec 2012

See if the fit is good. If not, try to find a better initial guess.

Log in to comment.

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments

Log in to comment.