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.