[> diff( x^3 - 3*x, x ); or [> p := x^3 - 3*x; diff(p, x);To compute higher order derivatives, we use the operator $. To compute the second, third, and fourth derivatives of x^3 - 3x try:
[> diff( x^3 - 3*x, x$2 ); [> diff( x^3 - 3*x, x$3 ); [> diff( x^3 - 3*x, x$4 );Differentiation in Maple does not always work quite the way you might expect. It is often useful to combine diff with simplify to get results that look reasonable:
[> diff( x^n, x ); [> simplify( diff( x^n, x ) );
Example: Consider the curve in the plane defined by the equation
xy^3 + x^3y = 30 (eqn1)
What does this graph look like? How can we find points on
this curve? When we find a point on the curve, how can we
compute the slope of the curve at that point?
We start by using Maple to find some points on this graph. Pick a value for x, say x = 1, and try to find the corresponding y-values if any exist.
[> eqn1 := x*y^3 + x^3*y = 30;
[> subs( x = 1, eqn1 );
[> solve( ", y );
[> evalf(");
We find that if x = 1 our equation becomes y^3 + y = 30 and solving, we
find that this cubic has one real solution (and two complex solutions ---
Maple uses I for the square root of -1). The
upshot is that we have found a point on this curve, the point (1, 3).
Let's look for another point on this curve. Try x = 0.5 and see what happens:
[> subs(x = 0.5, eqn1); [> solve(subs(x = 0.5, eqn1), y);So it looks like the point (0.5, 3.894) is on the curve. (This time we did not need evalf because we gave the x-value in decimal form. This told Maple to compute answers in decimal form. Compare what happens if we start with x = 1/2 instead of x = 0.5.) Now that we have found two points on the curve, we want to find the slope at each of these points. We need to do implicit differentiation. That is,
[> diff(eqn1, x);Optimists are often disappointed --- this is not what we want. Maple has treated y as a constant, not as a function of x. We can fix this if we tell Maple that y depends on x. Everywhere we had a y in our equation, we must replace it by y(x), to indicate that y is a function of x.
[> eqn1x := x*(y(x))^3 + x^3*y(x) = 30; [> diff(eqn1x, x);That is more like what we need, although that may not be apparent at first glance. If you look carefully, you will see that Maple has differentiated the equation correctly, giving us the relationship between x, y, and dy/dx:
y^3 + 3xy^2(dy/dx) + 3x^2y + x^3(dy/dx) = 0
We can even have Maple solve for dy/dx, if we ask for it
in Maplese, using diff(y(x), x) when we mean dy/dx:
[> solve( diff(eqn1x, x), diff(y(x), x) );Now we have our formula, but not in a very usable form. Replacing each occurrence of y(x) by y, Maple is telling us that
dy y(y^2 + 3x^2)
---- = - --------------
dx x(3y^2 + x^2)
To get a usable version of this slope formula, the simplest
solution is simply to type it in. Also, since we want
to compute the slope at a given point (x,y) on the curve, it
is a good idea to make a function of two variables:
[> dydx := (x,y) -> -y*(y^2 + 3*x^2) / ( x*(3*y^2 + x^2) );and now we can compute the slope at the points we found above:
[> x1 := 1.0; y1 := 3.0; m1 := dydx(x1,y1); [> x2 := 0.5; y2:= 3.893581479; m2 := dydx(x2,y2);We now have enough information to plot some tangent lines to this curve. For example, the above computation tells us that the slope of the curve at (1,3) is m1 = -1.2857. Therefore, the equation of the tangent line is given by
y-3 = -1.2857*(x-1) or y = 3 - 1.2857*(x-1)
To plot a small portion of this tangent line, we could type:
[> plot( 3 - 1.2857*(x-1), x = 0.9..1.1); or equivalently [> r := 0.1: plot( y1 + m1*(x - x1), x = x1 - r..x1 + r );The following commands would produce a plot that contains a small piece of the tangent line to the curve at (x1,y1) = (1,3) together with a small piece of the tangent line to the curve at the point (x2,y2) = (0.5, 3.89358).
[> with(plots):
[> r := 0.1: # the radius of the plotting interval
[> points := plot([ [x1,y1], [x2,y2] ], style = point, symbol = diamond):
[> t1 := plot( y1 + m1*(x - x1), x = x1 - r..x1 + r ):
[> t2 := plot( y2 + m2*(x - x2), x = x2 - r..x2 + r ):
[> display( { t1, t2, points } );
(a) 4x - 5 (b) (cos(5t))^3 (c) sin(sin(x^3 - 5x))
---------
6x^2 + 2x
Next, find y-values that correspond to x = 0.0, 0.25, and 0.75 in (eqn1). Using the example as a guide, make a plot that contains the points corresponding to x = 0.0, x = 0.25, x = 0.5, x = 0.75, and x = 1 together with a small portion of their tangent lines, as illustrated in the example.
Print your graph and draw in your best estimate for the curve defined by the equation. Take into account the fact that this equation has odd symmetry. That is, if (x,y) satisfies the equation then so does (-x, -y). How are the slopes at (x,y) and at (-x,-y) related?
Use implicitplot to graph the curve defined by (eqn1) for x between 0 and 1. Use your work in the previous exercise to help you choose an appropriate range of y-values:
[> implicitplot( eqn1, x = 0..1, y = ??..??);Then use implicitplot to graph the curve for x between -10 and 10.
y + cos(xy^2) + 3x^2 = 4 (eqn2)
Obviously, the cos(xy^2) term is the
piece that is difficult to understand. On the other hand, cos(xy^2) is
a number between -1 and 1, so maybe it would help if we consider the curves
we get by replacing cos(xy^2) with 1 and with -1:
[> plot( {5 - 3*x^2, 3 - 3*x^2}, x = -10..10, y = -10..10);
The graph of (eqn1) must lie between these two parabolas, so now we know
a lot more about the graph than we did before. In particular, we can see
from this picture what a good viewing rectangle might be when we use
implicitplot to draw the curve. Compare the following:
[> implicitplot( y + cos(x*y^2) + 3*x^2 = 4, x = -5..5, y = -5..5);
[> implicitplot( y + cos(x*y^2) + 3*x^2 = 4, x = -2..2, y = -5..5);
[> implicitplot( y+ cos(x*y^2) + 3*x^2 = 4, x = -2..2, y = -5..5,
numpoints = 1000);
[> implicitplot( y+ cos(x*y^2) + 3*x^2 = 4, x = -2..2, y = -5..5,
numpoints = 5000);
to plot the curve defined by (eqn2). Looking at this
sequence of graphs, how well would the method we used on (eqn1) work?
What difficulties would arise?
Finally, try this:
[> envelope := plot( {5 - 3*x^2, 3 - 3*x^2}, x = -2..2, y = -5..5);
[> curve := implicitplot( y+ cos(x*y^2) + 3*x^2 = 4,
x = -2..2, y = -5..5, numpoints = 5000):
[> display({envelope, curve});