Clear Filters
Clear Filters

About accuracy of Fmincon

9 views (last 30 days)
Dat Tran
Dat Tran on 27 Jan 2015
Commented: Dat Tran on 27 Jan 2015
Dear all,
I have used Fmincon to solve an constrained optimization and the Fmincon gives me two different solutions with two different computers while I used the same code and Matlab version (R2014a).
I am wondering what causes the problem?
Thank you! Dat

Accepted Answer

John D'Errico
John D'Errico on 27 Jan 2015
If I had a dollar for every time this (or a very similar) question is asked, well, I'd not be wealthy, but hey, every dollar counts!
While fmincon is a deterministic algorithm, there are MANY things that can cause differences.
- Did you use the same starting values? Too often people use random starting values, maybe not even realizing they did so. So are your starting values the same? Down to the least significant bit? You would be surprised how easy this is to mistake.
- Is your objective truly the same? Again, this is trivially easy to screw up. Perhaps there is data that was migrated from one system to the other? Too often people think they can simply copy what they see in the command window, or write a set of numbers out into an ascii file. Sorry, but that will not give you exactly the same result.
- Is your objective function deterministic? There are some functions that seem deterministic, but are not so. For example, eigs or svds use random starting values. So if you call them in your code, don't expect identical results each time.
- Is your code truly the same? Again, different systems may have different code. Perhaps you have a different objective function on the different systems and do not even realize this fact. Or some function that you wrote that is called may be different. People forget that they have some minor function that is different on the different system, but it happens to be crucial. YES, IT HAPPENS.
This was just a partial list of the things I've seen people get wrong over the years. Any one of them could be what you have done, or perhaps you got creative and found some different way.
You can try setting the random seed before each test, but even then there might be codes that reset the random seed themselves, perhaps based on time of day.
  1 Comment
Dat Tran
Dat Tran on 27 Jan 2015
Thank you very much for your answer.
I just copied the code from one computer to USB and pasted the code to another computer and run. I did not make any changes for the code!
Dat

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!