Message Boards Message Boards

6 Replies
1 Total Likes
View groups...
Share this post:

FindMaximum gives wrong answer for simple non-linear function

Posted 10 years ago

I'm trying to use FindMaximum to maximize a function of the form A F(x). However, FindMaximum gives the wrong answer when A is very small. For example,

FindMaximum[{10^-6 x^2, 0 <= x <= 10}, {x, 0}]


{3.03108*10^-7, {x -> 0.550553}}

but the correct answer is x->10.

The problem seems to be related with the accuracy needed for small numbers, but increasing the precision in the options does not help. That is, increasing the values in the following options yields little improvement: FindMaximum[{10^-6 x^2, 0 <= x <= 10}, {x, 0}, AccuracyGoal -> 40, PrecisionGoal -> 40, WorkingPrecision -> 40, MaxIterations -> 2000].

Also changing the method is of no help because FindMaximum can only implement Interior Point Algorithm for constrained problems.

Is the a way that FindMaximum yields the right answer with this simple function?

6 Replies

Thanks Marco! That solved it!

It get's kind of stuck if you choose unsuitable initial conditions. You can see that when you evaluate:

FindMaximum[{10^(-6) x^2, 0 <= x <= 10}, {x, #}, WorkingPrecision -> 30] & /@ Range[0, 10]

which basically uses different initial guesses in the interval. It is as I said above, Maximize is better. But if you absolutely want FindMaximum this does work:

Max[x /. (Quiet[FindMaximum[{10^(-6) x^2, 0 <= x <= 10}, {x, #}, WorkingPrecision -> 30] & /@ Range[0, 10]])[[All, 2]]]

which is really, really inefficient and slow. The Quiet is to ignore all (important) warnings that the method does not converge in the prescribed number of iterations.


POSTED BY: Marco Thiel

Sorry, that was my mistake. You are right

FindMaximum[{10^-6 x^2, 0 <= x <= 10}, x]

does not work. I copied that wrong. Sorry.


POSTED BY: Marco Thiel
Posted 10 years ago

Maximize or NMaximize is more suitable for that problem. FindMaximum tries to find a local maximum an uses numarical evaluations. Also see the "Possible Issues" part of the documentation, espacially the part about numerical bumpyness and constraint regions.

POSTED BY: Karsten 7.

Thanks Marco. Unfortunately, not giving a starting value doesn't work with my original function (which has a small constant in front):

FindMaximum[{10^-6 x^2, 0 <= x <= 10}, x]

which gives the wrong answer

{1.03645*10^-6, {x -> 1.01806}}

Maximize does work, but Maximize tries to find global optima, and I'm needing to find local optima, which FindMaximum can find.

Thanks again, Mauricio

I guess that this is a numerical artefact. If you set the precision higher you get a warning:

FindMaximum[{SetPrecision[10^(-6 ) x^2, Infinity]}, {x, 0}]


FindMaximum::fmgz: Encountered a gradient that is effectively zero. The result returned may not be a maximum; it may be a minimum or a saddle point. >>

Maximize does work

Maximize[{10^(-6 ) x^2, 0 <= x <= 10}, x]

Cheers, Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract