Using "extrema" in Maple
Department of Mathematics, Statistics, and Computer Science
University of Illinois at Chicago
Copyright © 1998 Paul Brown, Heidi Burgiel, Marc Culler
Start by opening a Maple worksheet, loading the "student" package, and defining a function f(x,y) to be extremized, and a function g(x,y) to be used in the constraint equation.
> with(student);
> f := (x,y) -> x^2+y^2;
> g := (x,y) -> y - 2*x^2 + 1;
In its simplest form the extrema function just computes the extreme values of f(x,y). This is not so useful for us, since we want to know where these extreme values occur. But let's try it anyway. The extrema function expects expressions, not functions, as arguments, so you must use f(x,y) and g(x,y) instead of just f and g.
> extrema(f(x,y), g(x,y)=0);
To get the locations of the extrema, another argument is required. This argument is the name of a Maple variable whose value will become the list of points where the extrema are located. You can use any name for this variable; in the example below it is named TheAnswer. (The quotes are important.)
> extrema(f(x,y), g(x,y)=0, {x,y}, 'TheAnswer');
The result looks the same as what you got before, but now if we display the value of TheAnswer, we get more information:
> TheAnswer;
Notice that the result is actually a list of equations, and involves ``Rootof'' expressions. We could use evalf to get the values of these roots, but we have to be careful. By default Maple only evaluates one root, when the polynomial in question may have many. For example, with the quadratic polynomial above, evalf will not find both roots. Try it.
> evalf(TheAnswer);
Notice that this gives two answers, when there are really three extrema.
To force Maple to find all of the roots you can use use the Maple function "allvalues".
> allvalues(TheAnswer);
> evalf(allvalues(TheAnswer));
The rest of this discussion is only for those who want to delve deeper into the mysteries of Maple.
It may look at first glance like we got four points as TheAnswer. But if you look closely you will see that the value of allvalues(TheAnswer)consists of two sets, which have a non-empty intersection. As we mentioned above the elements of these two sets are not points. In fact they are sets of equations. So allvalues(The Answer) is actually a list of sets of sets of equations!
Maple has a number of operations that it can perform on sets. For example we can take the union of the two sets in allvalues(TheAnswer) to get a single set containing three sets of equations. (Read the help page with ?union if you are curious about the quote marks in the following command.)
> `union`(allvalues(TheAnswer));