MATLAB: Which is more accurate/good/feasible ‘optimtool’ or a same function involked in command window

optimization

Hi
I am optimizing a non linear function using 'fmincon'. when i am using this command in matlab command window i am getting some results which is different than when i am using it with 'optimtool' user interface for optimization. Both the cases have same input data but output is different for some variables.
P.S. My objective function calls many user defined functions while calculation. Is it the reason??

Best Answer

You should get the exact same result if you call it in command line or through the GUI, they use the same functions. There could be couple of reasons you may be seeing different results, some may be:
1) The options are different. You can change the options in the command line using OPTIMSET. In the GUI you can just enter them. The options holds several tolerances and that will affect your stopping criterion.
2) Do you have something that is random in your objective function or initial conditions? If yes you can fix the seed of the internal random number generator using the RNG function.
3) Check if the constraints are the same.