0
$\begingroup$

How can I find global minimum for the function: (what is the function name?)

ff[x_] := 0.01*(x + 20) + 0.001*(x + 20)^2 + Sin[(x + 20)] + 20

Plot[ff[x],{x,-222,222}]

enter image description here

$\endgroup$

closed as off-topic by rhermans, happy fish, MarcoB, yohbs, Bob Hanlon May 23 '17 at 5:03

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – rhermans, happy fish, MarcoB, yohbs, Bob Hanlon
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ Maybe you could use a function like FindMinimum, or perhaps NMinimize? $\endgroup$ – bill s May 18 '17 at 12:34
  • $\begingroup$ Welcome! Make the most of Mma.SE and take the tour now. Help us to help you, write an excellent question. Edit if improvable, show due diligence, give brief context, include minimal working examples of code and data in formatted form. As you receive give back, vote and answer questions, keep the site useful, be kind, correct mistakes and share what you have learned. $\endgroup$ – rhermans May 18 '17 at 12:35
  • 1
    $\begingroup$ Have you tried reading the documentation? Your question may be put on-hold as it seems to be off-topic, i.e it arises from a simply not readfing the documentation and is unlikely to help any future visitors. Don't be discouraged by that cleaning-up policy. Your future good questions are welcome. Learn about common pitfalls here. $\endgroup$ – rhermans May 18 '17 at 12:36
  • $\begingroup$ Learn abut Numerical and Symbolic Optimization here $\endgroup$ – rhermans May 18 '17 at 12:55
2
$\begingroup$

Your function is a parabola plus a sinusoidal. The parabola has minimum at x-> -25 that you can find like this

Minimize[0.01*(x + 20) + 0.001*(x + 20)^2 + 20, x]
{19.975, {x -> -25.}}

or

Solve[D[0.01*(x + 20) + 0.001*(x + 20)^2 + 20, x] == 0, x]
 {{x -> -25.}}

For your particular function, there will be many local minima, so the initial guess is important. here I use FindMinimum with an initial guess given by the minimum of the parabola.

{x, ff[x]} /. FindMinimum[ff[x], {x, -25}][[2]]
{-27.8483, 18.9831}

Or you could use Minimize giving constrains around x->-25. Notice that without constrains it will not find the global minimum.

Minimize[{ff[x], -50 < x < 0}, x]
{18.9831, {x -> -27.8483}}

you can see the result in a Plot by placing a Point in an Epilog

Plot[ff[x], {x, -50, 0}, 
 Epilog -> {Red, PointSize[Large], 
   Point[{x, ff[x]} /. FindMinimum[ff[x], {x, -25}][[2]]]}]

Mathematica graphics

$\endgroup$
3
$\begingroup$

As a supplement to the solution of rhermans

ff[x_]= 0.01*(x + 20) + 0.001*(x + 20)^2 + Sin[(x + 20)] + 20;
tab = Table[{x, ff[x]}, {x, -222, 222, 0.001}];
{x, ff} = MinimalBy[tab, Last] // Flatten
{-27.848, 18.9831}
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.