Program no longer working from Matlab version 2021b to 2022a

10 views (last 30 days)
I have a matlab code which presents an error in fsolve. "Objective function is returning undefined values at initial point. FSOLVE cannot continue." when running it in the new version Matlab 2022a.
This does not happen running the same program in Matlab 2021b.
Could you help me in the method I should use to repare this problem? or in how to avoid my progam from crushing if updates are made i nthe functions i am using?
If you need in further information, please ask.
It is a complex matlab program with multiple functions, and that is whay I am not sure of the information you require to try to help me with my issue.
Thank you very much.
  5 Comments
John D'Errico
John D'Errico on 6 Mar 2023
Edited: John D'Errico on 6 Mar 2023
Whenever someone claims that the "same" code is not running in one release, but is in another, the problem is almost always that it is not in fact the "same" code. Almost always what comes out is something was not correctly copied over between the two releases. It might be that there is some function in what you admit is a lengthy, complex code, that is different between the two systems. Far too often there are extra copies of some small function made, that have subtle differences in them.
It might be that some data was not copied correctly. Very often we see cases where some numbers were copied, but only to 4 significant digits, when in the other release, they were used to full precision. As such, the data driving the code was actually different, even though they swore the numbers were the same. Yes, I know you claim the inputs to be the same. But you need to understand others have claimed the same sort of thing. Those individuals often even thought they were correct. So I am not saying you have told a lie here, only that you may be mistaken.
So the very, very first thing you need to do, is to absolutely insure the codes are the same. I would probably install all of that code on a flash drive. Make sure it is on top of the search path. Now call the same code, in exactly the same way, on both systems. You might be surprised now, that the codes do behave consistently. But if the problem still happens, now you have some assurance the problem is as you claim it to be.
There are many possibilities that may be the issue, even if the code is found to be identical. But without seeing any code, we cannot really know what is happening.
It is actually fairly rare for changes between releases to impact existing code. This is something they seriously strive to avoid, always trying to have code be backwards compatible. (I have 30 year old code that still works with no problems.) However, you should spend some time reading the release notes for the newer release. Those notes should state exactly which functions had some changes made to them.
Next, you probably need to spend some time with the debugger. Learn to use it. Run the code. And VERY carefully look to see exactly what got passed to fsolve. What cause the undefined result as it was returnd to fsolve? Learn what happened. Now do the same thing in the old release.
If you can seriously claim that fsolve fails on one system at the start point, but succeeds on the older release with the IDENTICAL start point, then show it. Save the start point as a .mat file, so we can see the actual numbers in full double preciion. Post at least the objective function that fsolve would use. Now we can compare how fsolve would work in each release. I hope you realize that will almost certainly not happen, that in fact, something else is the issue? If the start point causes fsolve to fail because the result is undefined in one release, it will be undefined in another release too. But anything could be true.
Finally, is there any way to absoutely insure that your code will not have problems if updates are made? Again, updates are rare that cause problems in existing code. And long before they make serious changes, MathWorks usually tries to inform users to expect a change with specific codes. That is, if you look in the help for some functions, they might tell you that some specific functions may go away in the future, to avoid using them. And this information is given out years in advance. For example, if you read the help for findstr, you will see this:
>> help findstr
findstr Find sequence of characters within string
findstr is not recommended. Use CONTAINS or STRFIND instead.
So one day, findstr may go away. And we have been told that same information for many years now. You NEED to read the release notes. If you don't, then you may be surprised at some point. That is a risk you take for not doing due diligence, IF this is a fear you have.
I'm sorry if this seems not very helpful. But without seeing any code, do you seriously expect better help? We are limited in how we might possibly help you here. If you want better help, then you need to either post the COMPLETE code, with all data so we could run it, or you need to spend some time in narrowing down the problem..
Shree Charan
Shree Charan on 2 May 2023
The error message "Objective function is returning undefined values at initial point. fsolve cannot continue." in MATLAB typically means that the initial guess supplied to the fsolve function is causing the objective function to return NaN or Inf values. Since fsolve relies on the objective function to find a solution, this error prevents fsolve from continuing with the optimization process.
If the program runs successfully in R2021b and fails in R2022a, it might be useful to compare the functions and ensure the code is same. Further as @Jan suggested, it might be useful to apply breakpoints in the objective function and search, where the difference occurs.
It might be useful to share part of the code that can help reproduce the error.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!