lsqnonlin abort due matrix multiplication error
Mostrar comentarios más antiguos
When using lsqnonlin I get an error message saying:
" Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in
the second matrix. To perform elementwise multiplication, use '.*'.
Error in atamult (line 23)
V = A'*Y;
Error in snls (line 396)
newgrad = feval(mtxmpy,newA,newfvec(:,1),-1,varargin{:});
Error in lsqncommon (line 164)
snls(funfcn,xC,lb,ub,flags.verbosity,options,defaultopt,initVals.F,initVals.J,caller, ...
Error in lsqnonlin (line 253)
lsqncommon(funfcn,xCurrent,lb,ub,options,defaultopt,allDefaultOpts,caller,...
Error in lsqnonlinTest14 (line 71)
[x,resnorm,residual,exitflag,output] = lsqnonlin(problem);"
myFunction does the following:
- read an input vector from lsqnonlin
- create an input file for external finite element software
- start external solver, reads results, calculates error compared to experimental results
- returns error as vector (err in the .mat file attached)
- my function only contains matrix multiplication
lsqnonlin is implemented with these options:
set.scale=[1000 100];
problem.objective = 'myFunction';
problem.x0 = [20 250].*set.scale;
problem.lb = [5 220].*set.scale;
problem.ub = [40 320].*set.scale;
problem.solver = 'lsqnonlin';
problem.options = optimoptions(@lsqnonlin,'UseParallel',true);
problem.options.Algorithm = 'trust-region-reflective';
problem.options.PlotFcn = 'optimplotstepsize';
problem.options.Display = 'iter-detailed';
problem.options.StepTolerance = 1e-1;
problem.options.Diagnostics='on';
problem.options.OptimalityTolerance = 1e-3;
[x,resnorm,residual,exitflag,output] = lsqnonlin(problem);
The error appears randomly, sometimes after 6, 20...n iterations of lsqnonlin.
From the command line I can reconstruct the following:
Norm of First-order
Iteration Func-count f(x) step optimality
1 6 2.83613e+11 8.95184 8.57e+11
2 9 1.93657e+11 5.54999 6.05e+11
3 12 1.08155e+11 7.76516 4.04e+11
4 15 7.431e+10 3.7301 4.13e+11
5 18 4.42101e+10 4.20724 2.14e+11
6 21 2.90596e+10 2.85327 1.4e+11
So finally my questions are:
- are my options wrong?
- Is this a known issue?
- is my scaling correct?
Thank you!
6 comentarios
Walter Roberson
el 12 de Nov. de 2020
What does your function do if the external solver returns an unexpected size ?
Fabian Teichmann
el 12 de Nov. de 2020
Matt J
el 12 de Nov. de 2020
It's not something that can be investigated here without being provided the means to run the optimization.
Walter Roberson
el 12 de Nov. de 2020
The evidence suggests that a size error is occurring, unless the multiplication error is before you call the external function?
Fabian Teichmann
el 12 de Nov. de 2020
Editada: Fabian Teichmann
el 12 de Nov. de 2020
Walter Roberson
el 12 de Nov. de 2020
I recommend using
dbstop if caught error
to track down the problem.
Respuestas (0)
Categorías
Más información sobre Solver Outputs and Iterative Display en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!