Message Boards Message Boards

0
|
8551 Views
|
6 Replies
|
1 Total Likes
View groups...
Share
Share this post:
GROUPS:

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}]

yields

{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

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}]

gives

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

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

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.

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.

M.

POSTED BY: Marco Thiel

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.

M.

POSTED BY: Marco Thiel

Thanks Marco! That solved it!

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract