lsqnonlin matlab has a bug when the function to be minimized is doubled

Recently I have encoutered the following problem when using the matlab function lsqnonlin. We have to do some simulations and we need to use 2 times the same function in the lsqnonlin. But then the lsqnonlin will stop prematurely because the min x is not found. And if we use just once the same function for the lsqnonlin the everything is good again. Do you know if there is a bug in lsqnonlin? Mathematically the above stated problem shouldn't be an issue.
Thank you!

8 Comments

Please provide a MWE that reproduces the problem.
Ok, thanks. I will try to reproduce it.
To keep it minimal, all we really need are your inputs to lsqnonlin() and any options you're using with that function. If the inputs are not easily reproducible, you could execute your code up to the line that calls lsqnonlin() and save the inputs to a mat file, attach the mat file, and provide the line of code you're using to send those variable into the function. That way we just need to download the mat file, copy the line of code, and run it.
Yes, we have many parameters and a lot of date that we use, and it is not easy to reproduce the problem. I will ask my supervisor what code we can send to you, etc... and I will come back to you.
Thanks!
Sending lots of code will be more work for you and much more work for us.
The easiest thing you can do it put a breakpoint at the line that calls lsqnonlin(), run the code up to that point, and then simply save all of the inputs to that function to a mat file. Make sure these sets of inputs reproduce the problem you're experiencing.
For example, if the line looks like this:
x = lsqnonlin(fun,x0,lb,ub,options)
Then, just prior to that line, add this (we need all of the inputs and options):
save('lsqnonlinInputs.mat','fun','x0','lb','ub','options')
Then attach that mat file and give us the entire line that calls lsqnonlin().
This should take you just a few minutes, provided that you know the inputs that cause the problem.
Corina Ciobotaru's "Answer" moved here:
I tried to add the save('lsqnonlinInputs.mat','fun','x0','LB','UB','options '); as you said, but our fct = fun is defined at the end of our program, and I got this
Error using save
Variable 'fct' not found.
Maybe the best for me is to look again in the function that we use as it is a complicated function and it might be possible there is a bug too.
"Error using save Variable 'fct' not found."
You tried to save the variable fct. Adam Danz did not ask you to save the variable fct.
In that case, save all other inputs and you can just copy-paste the function in as a comment.

Sign in to comment.

Answers (0)

Categories

Asked:

on 26 Nov 2019

Edited:

on 27 Nov 2019

Community Treasure Hunt

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

Start Hunting!