Skip to content
Prev 181285 / 398502 Next

using optimize() correctly ...

Esmail Bonakdarian-4 wrote:
Your function is not unimodal.
The help for optimize states: 

"If f is not unimodal, then optimize() may approximate a local, but perhaps
non-global, minimum to the same accuracy."

In you case, optimize is locating a local maximum/minimum.

You should restrict the search to the interval [-10 , -7 ] so

result=optimize(f, c(-10,10), lower = -10, upper=-7, maximum=TRUE)

will locate your global maximum.

Berend