Maple Lab 2 (Spring 2007 Math 251 Sections 05-07) 

Background Worksheet. 

 

It's a good idea to start every sheet with the restart command. Maple remembers everything that 

you do, so the restart command gives you a fresh start without having to shutdown and restart  

the program itself! 

> restart; 1
 

 

A Quick Note for Typing in Maple: 

To create new text groups such as this use the button labeled "T" above. To create a new execution group  

(the lines with maple commands which start with ">") you can use the button labeled "[>" or the keyboard  

shortcut "Ctrl+J". To insert a group before the cursor use "Ctrl+K".  

 

To delete a line of input or Maple output you can use the keyboard shortcut "Ctrl+Delete". To begin 

another line in an execution group use "Shift+Enter". Remember that "Enter" alone will just execute 

the command you've typed. 

 

For this lab we will need the "plots" package along with the "VectorCalculus" package. 

> with(plots); 1; with(VectorCalculus); 1
 

[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
[Interactive, animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, ...
 

[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
[`&x`, `*`, `+`, `-`, `.`, `<,>`, `<|>`, AddCoordinates, ArcLength, BasisFormat, Binormal, CrossProd, CrossProduct, Curl, Curvature, D, Del, DirectionalDiff, Divergence, DotProd, DotProduct, Flux, Get...
 

We will be exploring Chapter 14 material using Maple. Specifically, we will be looking at: 

multivariable scalar valued functions, level surfaces, partial derivatives, the gradient operator, mins/maxs & Lagrange multipliers 

 

We have all ready seen how to graph functions of two variables: z = f(x, y) using the plot3d command and how to graph level 

surfaces: F(x, y, z) = K using the implicitplot3d command. Let's look at a command to draw level curves. 

(The "contours" option tells Maple how many level curves to draw.) 

 

First, we will define our function: z = f(x, y) and f(x, y) = 4-1/8*x^2-1/8*y^2. 

> f := proc (x, y) options operator, arrow; 4-1/8*x^2-1/8*y^2 end proc; 1
 

proc (x, y) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)(4, (VectorCalculus:-`-`)((VectorCalculus:-`*`)((VectorCalculus:-`*`)(1, 1/8), x^2))), (VectorCalculus:-`-`)((VectorCalc...
proc (x, y) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)(4, (VectorCalculus:-`-`)((VectorCalculus:-`*`)((VectorCalculus:-`*`)(1, 1/8), x^2))), (VectorCalculus:-`-`)((VectorCalc...
proc (x, y) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)(4, (VectorCalculus:-`-`)((VectorCalculus:-`*`)((VectorCalculus:-`*`)(1, 1/8), x^2))), (VectorCalculus:-`-`)((VectorCalc...
proc (x, y) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)(4, (VectorCalculus:-`-`)((VectorCalculus:-`*`)((VectorCalculus:-`*`)(1, 1/8), x^2))), (VectorCalculus:-`-`)((VectorCalc...
 

> contourplot(f(x, y), x = VectorCalculus:-`-`(5) .. 5, y = VectorCalculus:-`-`(5) .. 5, contours = 15); 1
 

Plot 

 

The contourplot3d command draws the level curves in 3D. The "filled=true" option tells Maple 

to fill in the surface in between the level curves. 

> contourplot3d(f(x, y), x = VectorCalculus:-`-`(5) .. 5, y = VectorCalculus:-`-`(5) .. 5, contours = 15, filled = true, orientation = ([36, 48]), scaling = constrained); 1
contourplot3d(f(x, y), x = VectorCalculus:-`-`(5) .. 5, y = VectorCalculus:-`-`(5) .. 5, contours = 15, filled = true, orientation = ([36, 48]), scaling = constrained); 1
 

Plot 

 

Let's draw a vector located at the point 2, -3 which points in the gradient direction ("up-hill")  

for this particular surface. To do so we need to use the gradient command. 

> u := Gradient(f(x, y), [x, y]); 1
 

Vector[column](%id = 145097304) 

The "Gradient" command spits out a "VectorField" object. We need to find the gradient's value 

at the point 2, -3 so we need the "evalVF" (evaluate vector field) command. 

> v := evalVF(u, `<,>`(2, VectorCalculus:-`-`(3))); 1
 

Vector[column](%id = 143677184) 

Putting a plot of this vector together with the contour plots gives us the following: 

> gradPlot := arrow(`<,>`(2, VectorCalculus:-`-`(3)), v, shape = arrow, color = blue); 1
 

PLOT(CURVES([[2., -3.], [1.500000000, -2.250000000]], [[1.562500000, -2.425000000], [1.500000000, -2.250000000], [1.637500000, -2.375000000]], STYLE(PATCHNOGRID), COLOUR(RGB, 0., 0., 1.00000000))) 

> levelCurvePlot := contourplot(f(x, y), x = VectorCalculus:-`-`(5) .. 5, y = VectorCalculus:-`-`(5) .. 5, contours = 15); 1
 

PLOT(CURVES([[-1.39999999999999992, -1.09999999999999920], [-1.47499999999999943, -.99999999999999988]], [[-1.47499999999999943, -.99999999999999988], [-1.54999999999999960, -.850000000000000088]], [[... 

> display({levelCurvePlot, gradPlot}); 1
 

Plot 

 

We can use Maple to compute directional derivatives. The "DirectionalDiff" command accepts 

a function and a vector direction -- this vector does not need to be normalized, Maple will do 

that for you. 

 

Let's compute the directional derivative of our function at the point 2, -3 in the `<,>`(1, 1)direction  

using the formula for the directional derivative and then using the built-in function. 

> u := VectorCalculus:-`*`(1/Norm(`<,>`(1, 1)), `<,>`(1, 1)); 1
 

Vector[column](%id = 146582332) 

> gradf := Gradient(f(x, y), [x, y]); 1
 

Vector[column](%id = -1211369772) 

> Typesetting:-delayDotProduct(evalVF(gradf, `<,>`(2, VectorCalculus:-`-`(3))), u); 1
 

1/8*2^(1/2) 

Note: If we wished to dot and then evaluate, we must turn `<,>`(2, -3) into a vector field and substitute. 

> subs([x = 2, y = VectorCalculus:-`-`(3)], Typesetting:-delayDotProduct(gradf, VectorField(u, 'cartesian'[x, y]))); 1
 

1/8*2^(1/2) 

Now let's use the built-in function. 

> subs([x = 2, y = VectorCalculus:-`-`(3)], DirectionalDiff(f(x, y), `<,>`(1, 1), [x, y])); 1
 

1/8*2^(1/2) 

 

Remember that the gradient operator can also be used to find normal vectors for the tangent 

planes of level curves. Let's graph the hyberboloid of one sheet 1/4*x^2+y^2-1/9*z^2 = 1 together 

with its tagent plane and normal line at the point 2, -1, 3. 

 

First, notice that this point is on the surface: 

> F := proc (x, y, z) options operator, arrow; 1/4*x^2+y^2-1/9*z^2 end proc; 1
 

proc (x, y, z) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)((VectorCalculus:-`*`)((VectorCalculus:-`*`)(1, 1/4), x^2), y^2), (VectorCalculus:-`-`)((VectorCalculus:-`*`)((Vector...
proc (x, y, z) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)((VectorCalculus:-`*`)((VectorCalculus:-`*`)(1, 1/4), x^2), y^2), (VectorCalculus:-`-`)((VectorCalculus:-`*`)((Vector...
proc (x, y, z) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)((VectorCalculus:-`*`)((VectorCalculus:-`*`)(1, 1/4), x^2), y^2), (VectorCalculus:-`-`)((VectorCalculus:-`*`)((Vector...
 

> evalb(F(2, VectorCalculus:-`-`(1), 3) = 1); 1
 

true 

Now we will generate the normal vector at the point 2, -1, 3. 

> n := evalVF(Gradient(F(x, y, z), [x, y, z]), `<,>`(2, VectorCalculus:-`-`(1), 3)); 1
 

Vector[column](%id = 144621392) 

Next, we need equations for the tangent plane and the normal line. 

> tPlane := Typesetting:-delayDotProduct(n, VectorCalculus:-`+`(`<,>`(x, y, z), VectorCalculus:-`-`(`<,>`(2, VectorCalculus:-`-`(1), 3)))) = 0; 1
 

x-2-2*y-2/3*z = 0 

> nLine := VectorCalculus:-`+`(`<,>`(2, VectorCalculus:-`-`(1), 3), VectorCalculus:-`*`(n, t)); 1
 

Vector[column](%id = 143397156) 

Now let's make our plots and display them together. 

> levelSurface := implicitplot3d(F(x, y, z) = 1, x = VectorCalculus:-`-`(5) .. 5, y = VectorCalculus:-`-`(5) .. 5, z = VectorCalculus:-`-`(8) .. 8, scaling = constrained, numpoints = 5000); 1
levelSurface := implicitplot3d(F(x, y, z) = 1, x = VectorCalculus:-`-`(5) .. 5, y = VectorCalculus:-`-`(5) .. 5, z = VectorCalculus:-`-`(8) .. 8, scaling = constrained, numpoints = 5000); 1
 

PLOT3D(ISOSURFACE(Array(1..20, 1..20, 1..20, 1..4, {(1, 1, 1, 1) = -5.0, (1, 1, 1, 2) = -5.0, (1, 1, 1, 3) = -5.0, (1, 1, 1, 4) = -5.0, (1, 1, 2, 1) = -5.0, (1, 1, 2, 2) = -5.0, (1, 1, 2, 3) = -5.0, (... 

> tangentPlot := plot3d(solve(tPlane, z), x = VectorCalculus:-`-`(4) .. 4, y = VectorCalculus:-`-`(3) .. 2, color = blue); 1
 

PLOT3D(GRID(-4. .. 4., -3. .. 2., Array(1..25, 1..25, {(1, 1) = .0, (1, 2) = -.6250000000000004, (1, 3) = -1.2500000000000008, (1, 4) = -1.8750000000000012, (1, 5) = -2.5000000000000016, (1, 6) = -3.1... 

> normalPlot := spacecurve(nLine, t = VectorCalculus:-`-`(2) .. 2, color = red, thickness = 3); 1
 

PLOT3D(CURVES([[0., 3., 4.333333333], [0.8163265300e-1, 2.836734694, 4.278911565], [.1632653060, 2.673469388, 4.224489796], [.2448979590, 2.510204082, 4.170068027], [.3265306120, 2.346938776, 4.115646... 

> display({levelSurface, normalPlot, tangentPlot}, orientation = ([VectorCalculus:-`-`(90), 71])); 1
 

Plot 

 

Now let's redo the minimum distance problem from class using Maple techniques. 

 

12.7 #40) Find the points on the level surface x^2*y^2*z = 1 which are closest to the origin. 

 

Let's begin with a graph of this surface. 

> F := proc (x, y, z) options operator, arrow; x^2*y^2*z end proc; 1
 

proc (x, y, z) options operator, arrow; (VectorCalculus:-`*`)((VectorCalculus:-`*`)(x^2, y^2), z) end proc 

> implicitplot3d(F(x, y, z) = 1, x = VectorCalculus:-`-`(2) .. 2, y = VectorCalculus:-`-`(2) .. 2, z = VectorCalculus:-`-`(1) .. 2, scaling = constrained, axes = normal, numpoints = 5000, orientation = ...
implicitplot3d(F(x, y, z) = 1, x = VectorCalculus:-`-`(2) .. 2, y = VectorCalculus:-`-`(2) .. 2, z = VectorCalculus:-`-`(1) .. 2, scaling = constrained, axes = normal, numpoints = 5000, orientation = ...
 

Plot 

From the graph we can see that the problem should have FOUR solutions. 

 

We need to find a function describing the distance squared (to make things look nicer)  

from the surface to the origin. Then we mustcompute some partial derivatives, find  

critical points, and test them. 

 

Note: Minimizing the distanced squared is the same as minimizing the distance. 

> distSq := proc (x, y, z) options operator, arrow; x^2+y^2+z^2 end proc; 1
 

proc (x, y, z) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)(x^2, y^2), z^2) end proc 

> f := proc (x, y) options operator, arrow; distSq(x, y, solve(F(x, y, z) = 1, z)) end proc; 1
 

proc (x, y) options operator, arrow; distSq(x, y, solve(F(x, y, z) = 1, z)) end proc 

> z = f(x, y); 1
 

z = x^2+y^2+1/(x^4*y^4) 

> fx := diff(f(x, y), x); 1
 

2*x-4/(x^5*y^4) 

> fy := diff(f(x, y), y); 1
 

2*y-4/(x^4*y^5) 

> fxx := diff(f(x, y), `$`(x, 2)); 1
 

2+20/(x^6*y^4) 

> fyy := diff(f(x, y), `$`(y, 2)); 1
 

2+20/(x^4*y^6) 

> fxy := diff(f(x, y), x, y); 1
 

16/(x^5*y^5) 

Notice that the mixed partials are the same: 

> fyx := diff(f(x, y), y, x); 1
 

16/(x^5*y^5) 

Let's find the critial points. 

> critPts := solve({fx = 0, fy = 0}, [x, y]); 1
 

[[x = -RootOf(_Z^10-2), y = RootOf(_Z^10-2)], [x = RootOf(_Z^10-2), y = RootOf(_Z^10-2)]]
[[x = -RootOf(_Z^10-2), y = RootOf(_Z^10-2)], [x = RootOf(_Z^10-2), y = RootOf(_Z^10-2)]]
 

Note: "RootOf(Z^10-2)" means the number Z which is a solution of Z^10-2 = 0  

this means Z = 2^(1/10) or Z = -2^(1/10). So (as in class) we actually have FOUR solutions! 

> plot(VectorCalculus:-`+`(Z^10, VectorCalculus:-`-`(2)), Z = VectorCalculus:-`-`(1.1) .. 1.1); 1
 

Plot 

The above graph shows that Z^10-2 has TWO x-intercepts. 

 

Now we will construct the "D" operator which appears in our critical point test. 

(We can't use the name "D" itself -- Maple's all ready using that for something.) 

> DOp := VectorCalculus:-`+`(VectorCalculus:-`*`(fxx, fyy), VectorCalculus:-`-`(fxy^2)); 1
 

(2+20/(x^6*y^4))*(2+20/(x^4*y^6))-256/(x^10*y^10) 

Now we plug in our critical points and see what we have. 

> 0 < simplify(subs(critPts[1], DOp)); 1
 

0 < 80 

> 0 < simplify(subs(critPts[1], fxx)); 1
 

0 < 12 

Therefore, the first critical point is a local minimum. 

 

Now we check the second point. 

> 0 < simplify(subs(critPts[2], DOp)); 1
 

0 < 80 

> 0 < simplify(subs(critPts[2], fxx)); 1
 

0 < 12 

Therefore, both points are local minima. 

 

We get that the surface is closest to the origin when... 

> op(critPts[1]), z = subs(critPts[1], solve(F(x, y, z) = 1, z)); 1
 

x = -RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/RootOf(_Z^10-2)^4 

and 

> op(critPts[2]), z = subs(critPts[2], solve(F(x, y, z) = 1, z)); 1
 

x = RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/RootOf(_Z^10-2)^4 

 

Next, let's solve the problem again. But this time we'll use Lagrange multipliers. 

 

Let's identify our objective function f(x, y, z)(in this case the distance from 

the origin squared) and our constraint g(x, y, z) = K (in this case the level surface 

defined by x^2*y^2*z = 1. 

> f := proc (x, y, z) options operator, arrow; x^2+y^2+z^2 end proc; 1
 

proc (x, y, z) options operator, arrow; (VectorCalculus:-`+`)((VectorCalculus:-`+`)(x^2, y^2), z^2) end proc 

> f(x, y, z); 1
 

x^2+y^2+z^2 

> g := proc (x, y, z) options operator, arrow; x^2*y^2*z end proc; 1
 

proc (x, y, z) options operator, arrow; (VectorCalculus:-`*`)((VectorCalculus:-`*`)(x^2, y^2), z) end proc 

> g(x, y, z) = 1; 1
 

x^2*y^2*z = 1 

Next, we need to compute the gradient of f  and the gradient of g to find 

our system of equations. 

> gradf := Gradient(f(x, y, z), [x, y, z]); 1
 

Vector[column](%id = 146025740) 

> gradg := Gradient(g(x, y, z), [x, y, z]); 1
 

Vector[column](%id = 143270740) 

> gradf = lambda*gradg; 1
 

Vector[column](%id = 146025740) = Vector[column](%id = 147179364) 

We can rip off the components of each side of the vector equation by using 

something like this... 

> Typesetting:-delayDotProduct(gradf, VectorField(`<,>`(1, 0, 0), 'cartesian'[x, y, z])); 1
 

2*x 

But it's just easier to compute the gradients one component at a time (using 

the definition of the gradient operator) and construct our equations in that 

manner. 

> Eqn1 := diff(f(x, y, z), x) = VectorCalculus:-`*`(lambda, diff(g(x, y, z), x)); 1
 

2*x = 2*lambda*x*y^2*z 

> Eqn2 := diff(f(x, y, z), y) = VectorCalculus:-`*`(lambda, diff(g(x, y, z), y)); 1
 

2*y = 2*lambda*x^2*y*z 

> Eqn3 := diff(f(x, y, z), z) = VectorCalculus:-`*`(lambda, diff(g(x, y, z), z)); 1
 

2*z = lambda*x^2*y^2 

Our last equation is given by the constraint. 

> Eqn4 := g(x, y, z) = 1; 1
 

x^2*y^2*z = 1 

Now we solve. 

> soln := solve({Eqn3, Eqn4, Eqn2, Eqn1}, [x, y, z, lambda]); 1
 

[[x = RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2], [x = -RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2]]
[[x = RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2], [x = -RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2]]
[[x = RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2], [x = -RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2]]
[[x = RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2], [x = -RootOf(_Z^10-2), y = RootOf(_Z^10-2), z = 1/2*RootOf(_Z^10-2)^6, lambda = RootOf(_Z^10-2)^2]]
 

> evalf(subs(soln[1], f(x, y, z))); 1
 

2.871745892 

> evalf(subs(soln[2], f(x, y, z))); 1
 

2.871745892 

Looking carefully, you will notice that the answers given by this method are 

the same as given by the last method. Evaluating our objective function at 

these points tells us that the minimum distance to the origin is about 2.87. 

>