lsqnonlin abort due matrix multiplication error

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

What does your function do if the external solver returns an unexpected size ?
Do you mean size of the error vector or absolute value of the error values? Both have not happend so far. What should the function do in that case?
Matt J
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.
The evidence suggests that a size error is occurring, unless the multiplication error is before you call the external function?
Fabian Teichmann
Fabian Teichmann el 12 de Nov. de 2020
Editada: Fabian Teichmann el 12 de Nov. de 2020
Right. The error occurrs exactly after one call of myFunction endet sucessfully and the next call starts. I have checked this by writing textfiles at discrete points of the function...
I recommend using
dbstop if caught error
to track down the problem.

Iniciar sesión para comentar.

Respuestas (0)

Preguntada:

el 12 de Nov. de 2020

Comentada:

el 12 de Nov. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by