NONLCON must be a function using lsqnonlin

Hello everyone!
I am trying to estimate parameters using lsqnonlin and I get the following error:
Error using cnls
NONLCON must be a function
Error in lsqnonlin (line 220)
[xCurrent,Resnorm,FVAL,EXITFLAG,OUTPUT,LAMBDA,JACOB] = cnls(caller, FUN,xCurrent,A,B,Aeq,Beq,LB,UB,NONLCON, ...
I have no nonlinear constraints and therefore I left NONLCON as empty square brackets. I don't understand where I am going wrong.
The error occurs on line 70.

 Respuesta aceptada

Matt J
Matt J el 27 de Ag. de 2023
Editada: Matt J el 27 de Ag. de 2023

0 votos

No, you have set the nonlcon argument to Cexp which is a numeric vector. You should review the documentation for the correct ordering if the arguments.

6 comentarios

Matt J
Matt J el 27 de Ag. de 2023
Editada: Matt J el 27 de Ag. de 2023
Possibly this is what you meant to have:
fun=@(x)resfun(x,texp,Initial,Data,Spatial,Cexp);
[OptimalParameters, SSEout] = lsqnonlin(fun,InitGuess,lb,ub);
James99
James99 el 28 de Ag. de 2023
Thank you Matt! your code works, although, it works forever. Do you have any tips for fast convergence?
Matt J
Matt J el 28 de Ag. de 2023
How fast are your objective function evaluations?
James99
James99 el 28 de Ag. de 2023
Do you mean how long it takes to solve the PDE?
I must add that it could be due to the parameters supplied and not due to the way the code is written.
I've attached the final code, should you wish to examine it. Beware that it takes quite a lot of time to solve, still accompanied by warnings.
Matt J
Matt J el 28 de Ag. de 2023
If the optimization time is long, it doesn't necessarily mean you have slow convergence. If one execution of resfun takes a long time, that will also make the optimization time longer.
James99
James99 el 28 de Ag. de 2023
Right, but the warnings about not reaching the solution without reducing the time step below a permitted value a part of the process? I noticed that MATLAB continues with the calculation despite of these warnings. I suppose it does that particular iteration with smallest permitted time step value.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 27 de Ag. de 2023

Comentada:

el 28 de Ag. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by