The Error in lsqcurvefit

3 visualizaciones (últimos 30 días)
Saham Sharifi
Saham Sharifi el 22 de Abr. de 2021
Respondida: Walter Roberson el 23 de Abr. de 2021
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 comentario
Walter Roberson
Walter Roberson el 22 de Abr. de 2021
fun = @(parameters,expStrain) packFun(strainRate(j),...
tempC(i),parameters,finalStrain);
packFun is not a Mathworks function, and you did not provide its code.

Iniciar sesión para comentar.

Respuestas (2)

Saham Sharifi
Saham Sharifi el 23 de Abr. de 2021
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 el 23 de Abr. de 2021
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.

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by