The Error in lsqcurvefit

3 次查看(过去 30 天)
Saham Sharifi
Saham Sharifi 2021-4-22
Trying to fit a equation and I keep getting:
Error using lsqcurvefit (line 271)
"Function value and YDATA sizes are not equal.
Error in optim (line 63)
optimizedParameters = lsqcurvefit( ..."
Could you please have a look?
  1 个评论
Walter Roberson
Walter Roberson 2021-4-22
fun = @(parameters,expStrain) packFun(strainRate(j),...
tempC(i),parameters,finalStrain);
packFun is not a Mathworks function, and you did not provide its code.

请先登录,再进行评论。

回答(2 个)

Saham Sharifi
Saham Sharifi 2021-4-23
Thank you Walter for your reply,
Actually, I did define a packFun function, as follow. It refers to the whole calculation process.
(I attached T1000 in txt format since the web page did not accept it in .dat )

Walter Roberson
Walter Roberson 2021-4-23
fun = @(parameters,expStrain) packFun(strainRate(j),...
tempC(i),parameters,finalStrain);
and
optimizedParameters = lsqcurvefit( ...
fun, ...
parameters, ...
experimentalData(1:500,1), ...
experimentalData(1:500,2), ...
lowerBounds, ...
upperBounds, ...
options);
lsqcurvefit is going to call the function, fun, passing to it a vector of trial model parameters, and some data points (for the first iteration it will not necessarily be the full set of X data.) The objective function is responsible for returning a vector the same size as the data passed in, with the output being a projection of what the y data would be for those model parameters at those x locations. If all goes well, lsqcurvefit() would then form the sum-of-squared error against the y data, giving a goodness of fit. Then it would alter the trial model parameters and try again.
However, look at the function you passed in, fun. You take the passed in second parameter, expStrain (the x data), and you... do not pass it to packFun. So unless packFun has its own copy of the x data, packFun cannot possibly return output the same size as the input.
What your packFun does return is data that is numberOfSteps x 1, where numberOfSteps is 1000 * the value of the 4th parameter -- that is, it calls solveFlowStress which returns numberOfSteps x 9, and packFun returns one column of that. That is probably not exactly the same size as the number of rows in experimentalData ... and did I mention that lsqcurvefit is permitted to pass in only a subset of the data?
You need a function that takes in a vector of coordinates, and calculates output for those coordinates.

类别

Help CenterFile Exchange 中查找有关 Genetic Algorithm 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by