# Finding exact local extrema of simple functions

I want to exactly find all the local maxima of

f[x_] := x^4/4 - x^2/2

over the interval [-Sqrt[2], 1 + Pi/10].

The correct answer is that we have global maxima at x = -Sqrt[2] and x=0, and a local maximum at x= 1 + Pi/10.

Right now my approach is to iterate the Maximize command, which finds global maximums symbolically, and each time it finds a maximum I tell it to not find the same one again. Of course after it finds the two global maxima, it doesn't give me anything useful on the third application, as the one I am trying to find is merely local.

Now I could use FindMaximum, but that only yields a numerical approximation, and I want the exact value. Also note that in this case my algorithm fails to find the local maximum at an endpoint, but it would be easy to use a different function where the method would fail to find a local maximum properly inside the interval.

Iteration 1:

Maximize[{x^4/4 - x^2/2, (x >= -Sqrt[2]) && (x <= 1 + Pi/10)}, x]

This finds the point x=0.

Iteration 2:

Maximize[{x^4/4 - x^2/2, (x >= -Sqrt[2]) && (x <= 1 + Pi/10) && (x != 0)}, x]

This finds the point x = -Sqrt[2].

Iteration 3:

Maximize[{x^4/4 - x^2/2, (x >= -Sqrt[2]) && (x <= 1 + Pi/10) && (x != 0) && (x != -Sqrt[2])}, x]

Of course this throws a "no maximum in the region" error, when I would like it to find x = 1 + Pi/10.

I am open to patches for this approach or completely different algorithms as well.

-
If your function going to be twice differentiable? – Kuba Jan 29 '14 at 8:33
You could do it old-school: solve for f'[x]==0 and check the second derivatives plus look at the edges of your interval for local extrema. – Yves Klett Jan 29 '14 at 8:34
@Yves Klett and Kuba, good suggestions. Unfortunately the function isn't guaranteed to be twice-differentiable, and even when it is, the second-derivative test isn't guaranteed to give all extrema (e.g. in y = x^4). – Twiffy Jan 29 '14 at 19:25
Ahhh... you should definitely add this info to the question. – Yves Klett Jan 29 '14 at 20:15