# FindMaximum gives wrong answer for simple non-linear function

**URL:** <https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690>\
**Category:** Questions\
**Tags:** mathematica\
**Created:** [July 16, 2014, 3:30pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690 "2014-07-16T15:30:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maoforero86](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@maoforero86](https://community.wolfram.com/u/maoforero86)\
**Post date:** [July 16, 2014, 3:30pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690/1 "2014-07-16T15:30:45Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [July 16, 2014, 3:59pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690/2 "2014-07-16T15:59:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![maoforero86](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@maoforero86](https://community.wolfram.com/u/maoforero86)\
**Post date:** [July 16, 2014, 4:11pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690/3 "2014-07-16T16:11:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![karstenpotrick](https://avatars.discourse-cdn.com/v4/letter/k/da6949/32.png) [@karstenpotrick](https://community.wolfram.com/u/karstenpotrick)\
**Post date:** [July 16, 2014, 4:21pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690/4 "2014-07-16T16:21:05Z")

</div>

`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](http://reference.wolfram.com/language/ref/FindMaximum.html?q=FindMaximum), espacially the part about numerical bumpyness and constraint regions.

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [July 16, 2014, 4:23pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690/5 "2014-07-16T16:23:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mthiel](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mthiel/32/42877_2.png) [@mthiel](https://community.wolfram.com/u/mthiel)\
**Post date:** [July 16, 2014, 4:34pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690/6 "2014-07-16T16:34:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![maoforero86](https://avatars.discourse-cdn.com/v4/letter/m/d26b3c/32.png) [@maoforero86](https://community.wolfram.com/u/maoforero86)\
**Post date:** [July 16, 2014, 4:38pm UTC](https://community.wolfram.com/t/findmaximum-gives-wrong-answer-for-simple-non-linear-function/2690/7 "2014-07-16T16:38:21Z")

</div>

Thanks Marco! That solved it!
