lsqnonlin matlab has a bug when the function to be minimized is doubled
Show older comments
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
Corina Ciobotaru
on 26 Nov 2019
Adam Danz
on 26 Nov 2019
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.
Corina Ciobotaru
on 26 Nov 2019
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.
Stephen23
on 27 Nov 2019
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.
Stephen23
on 27 Nov 2019
"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.
Answers (0)
Categories
Find more on Licensing on Cloud Platforms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!