The Error in lsqcurvefit
3 次查看(过去 30 天)
显示 更早的评论
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
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 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!