Next: Exercises
Up: Labs and Projects for
Previous: Labs and Projects for
The gradient vector at a point gives the direction in which the function increases most rapidly. For the purposes of this lab, you will need to know how to construct the gradient vector and be able to plot the gradient vector on the same graph as the contour plot of f. You may construct the gradient vector of a function f(x,y) by finding both partial derivatives or you may use the grad command in Maple defined below:
> gr := (x,y) -> vector([grad(f(x,y),vector([x,y]))]);
In order to see the output, type:
> gr(x,y);
you can use the Maple subs command to evaluate this gradient vector at different points.
Many applications of calculus involve finding the maximum and minimum values of functions. For example, suppose that there is a network of electrical power generating stations, each with its own cost for producing power, with the cost per unit of power at each station changing with the amount of power it generates. An important problem for the network operators is to determine how much power each station should generate to minimize the total cost of generating a given amount of power.
A crucial first step in solving such problems is being able to find and classify local extreme points of a function. What we mean by the term local extreme values is contained in the following definition.
Definition 1 Let f be a function defined at a point (x0,y0). Then f(x0,y0) is a local maximum if for all (x,y) in an open disk containing (x0,y0) and f(x0,y0) is a local minimum if
for all (x,y) in an open disk containing (x0,y0). If f(x0,y0) is a local maximum or a local minimum, we say that it is a local extreme value.
In single-variable calculus, we found that the first derivative vanished or did not exist at a local extreme value. For functions of two variables, both first-order partial derivatives vanish as described by the following theorem.
Theorem 1 If a function f(x,y) has local extreme values at a point (x0,y0) and the partial derivatives of f both exist at (x0,y0), then
Notice that having both first order partial derivatives vanish means that the tangent plane is horizontal. Following the terminology we used for functions of a single variable, we call points where the partial derivatives fx and fy vanish critical points. Note carefully that the theorem does not say that a point where the partial derivatives vanish must be a local extreme point. Rather, it says that critical points are candidates for local extrema. Just as was the case for functions of a single variable, there can be critical points that are not extrema. For example, the saddle surface f(x,y) = x2 - y2 has a critical point at the origin, but note it is neither a local maximum or a local minimum.
Finding and classifying the local extreme values of a function f(x,y) requires several steps. First, the partial derivatives must be computed. Then the critical points must be solved for, which is not always a simple task. Finally, each critical point must be classified as a local maximum, local minimum, or neither. The following example is intended to help you learn how to use Maple to simplify these tasks. To compute partial derivatives in Maple, it is probably simplest to use the diff command. It is possible to use the D command for partial derivatives, but it is more complicated. The following example shows how to compute (in order) the partial derivatives fx, fy, fxx, fxy, and fyy of the function .
> f := (x,y) -> exp(-x^2)*cos(y);
> diff(f(x,y),x);
> diff(f(x,y),y);
> diff(f(x,y),x,x);
> diff(f(x,y),x,y);
> diff(f(x,y),y,y);
Finding critical points can often be accomplished by using the solve command, as shown below.
> solve({diff(f(x,y),x) = 0,diff(f(x,y),y) = 0},{x,y});
Notice that you have to give the solve command the set of equations to be solved and the set of variables to be solved for and that both sets have to be enclosed in curly braces.
The solve command doesn't always do the job. For example, it only reported one critical point above. It turns out, however, that the function has an infinite number of critical points of the form x=0, , where n is any integer. Having an infinite number of critical points often happens when trig functions are involved, so you need to watch out for it.
The solve command attempts to solve equations analytically . Unfortunately, there are some equations that just can't be solved analytically. When Maple can't solve a set of equations analytically, it gives no output from the solve command.
If the solve command doesn't give the results you desire, there are alternatives. One possibility is to try to solve one of the equations for one of the variables in terms of the other, and then substitute into the other equation. This can work very well if it is easy to solve for one of the variables. Another, more general, method is to sovle the equations numericallyusing the fsolve command. The main drawbacks are that the fsolve command only finds one solution at a time and that you usually have to have an idea of where the solution is. For example, if you attempt to use the fsolve command on our example without specifying where to look for the solution, Maple can't solve the equation, as shown below.
> fsolvediff({f(x,y),x) = 0,diff(f(x,y),y) = 0},{x,y});
On the other hand, we can solve for the critical point at x=0, if we specify ranges for x and y containing the desired critical point as follows.
> fsolvediff({f(x,y),x) = 0,diff(f(x,y),y) = 0},{x,y},{x=-1..1,y=3.5..7});
Locating (if you have to use fsolve) the x and y range for critical points is probably best done with the plot3d command. By changing the plot ranges and using contours, you should be able to do this fairly easily.
Recall the difference between locating relative extrema and absolute extrema for single variable calculus. The procedure for finding relative extrema was to locate all critical values and use the first derivative test for example, checking if the function changed from increasing to the left of the critical value and decreasing to the right of the critical value to classify it as a relative maximum or the second derivative test in which you would evaluate the second derivative at a critical value and if the result was negative for example, then this would be a relative maximum. On the other hand, the test for absolute extrema was to locate all critical values and test all critical values and possible endpoints in the original function. The largest output from the function would be the absolute maximum and the smallest output would be the absolute minimum. Remember that you are only guaranteed both an absolute maximum and an absolute minimum if you have a continuous function on a closed interval.
For a function of two variables, the test for classifying relative extrema is the Second Partials Test. After finding critical points P0(x0,y0), let D = fxx(x0,y0)fyy(x0,y0) - [fxy(x0,y0)]2 then,
A relative maximum occurs at P0 if D>0 and fxx(x0,y0) < 0.
A relative minimum occurs at P0 if D>0 and fxx(x0,y0) > 0.
A saddle point occurs at P0 if D<0.
If D=0, then the test is inconlusive.
The function f(x,y) is said to have an absolute maximum at (x0,y0) if for all (x,y) in the domain D of f. Similarly, f has an absolute minimum at (x0,y0) if
for all (x,y) in D.
For absolute extrema of a function of two variables, it is necessary to test the function at all critical points as well as the points on the boundary of the domain where absolute extrema can occur. Just like single variable calculus, the output f(x0,y0) which is largest is the absolute maximum and the smallest output is the absolute minimum. You can be guaranteed to find both an absolute maximum and an absolute minimum if f(x,y) is continuous on a closed and bounded set.
For example, the function over the region in the xy-plane
Christine M Palmer