fminsearch - find best x0
2 views (last 30 days)
Show older comments
Hi i was wondering how to best use the function fminsearch. I determine a x0 for this function and get a result but this result changes when I change my x0 parameter. How can I best optimize my x0 suggestion? Run a loop for multiple x0's and take the mean??
0 Comments
Accepted Answer
Walter Roberson
on 1 Feb 2016
With each x0 you can have the value of the objective displayed. You would take the x0 that gave you the smallest objective value.
2 Comments
More Answers (1)
John D'Errico
on 1 Feb 2016
If there were a simple way to find the BEST starting point, then it would be used already. As it is, that is what optimization is, finding a minimal solution from a starting point.
The problem is, there are often multiple local minimizers. So if you start from a point that gets you to one of the non-globally optimal solutions, then that is what you get. Choose better starting values next time.
Do NOT use multiple starting values, then take the average of the results!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! It is easily shown that this may lead you to garbage for results. For example, find the minimum of the function cos(x), with several start points. Try it. See what happens.
x1 = fminsearch(@cos,2)
x1 =
3.1416015625
x2 = fminsearch(@cos,-2)
x2 =
-3.1416015625
So, now take the average of these results:
x3 = (x1 + x2)/2
x3 =
0
Taking the average worked rather poorly. Instead of a minimizer, the average of two minimizers actually got us to a point that is a local MAXIMIZER.
A good plan is to simply use multiple start points, taking the best (i.e., lowest function value) solution from among them. You can also use the global optimization toolbox to help you with some of this, although even that toolbox cannot guarantee a truly global solution.
Finally, in some cases (hard to know since we don't know your problem) you can improve things by the careful application of mathematics to a problem.
0 Comments
See Also
Categories
Find more on Get Started with Optimization Toolbox 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!