Maple V by Example

Examples from Multivariable Calculus

Many of these examples utilize functions that come with the plots package. To use the "plots" package, type with(plots): at the beginning of the file.

Tangent Lines to a Surface

with(plots):
f:= (x,y) -> x^2-y^2;
x0:=2:
y0:=1:
A:=plot3d(f(x,y), x=-3..3, y=-3..3, scaling=unconstrained, style=patch,axes=normal):
B:=spacecurve([x0+t,y0,f(x0,y0)+t*eval(diff(f(x,y),x),[x=x0,y=y0])], t=-6..4, color=black):
C:=spacecurve([x0,y0+t,f(x0,y0)+t*eval(diff(f(x,y),y),[x=x0,y=y0])], t=-6..4, color=black):
BB:=spacecurve([x0+t,y0,f(x0+t,y0)], t=(-3-x0)..(3-x0), color=red):
CC:=spacecurve([x0,y0+t,f(x0,y0+t)], t=(-3-y0)..(3-y0), color=red):
display({A,B,C,BB,CC});
After pressing Enter following the display command, Maple will graph the surface, show x- and y- slices through (2,1) in red, and show tangents to these slices. To change either the function we use or the point (x0,y0), change the corresponding lines and press enter. You will need to press Enter for all subsequent lines since Maple doesn't update a line unless you place the cursor on it and press Enter.

Tangent Planes to a Surface

with(plots):
f:= (x,y) -> 5-x^2-y^2;
x0:=2:
y0:=1:
A:=plot3d(f(x,y), x=-3..3, y=-3..3, scaling=unconstrained, style=patch,axes=normal):
B:=plot3d(f(x0,y0)+(x-x0)*eval(diff(f(x,y),x),[x=x0,y=y0])+(y-y0)*eval(diff(f(x,y),y),[x=x0,y=y0]), x=(x0-2)..(x0+2), y=(y0-2)..(y0+2), style=wireframe, color=black, grid=[6,6]):
display({A,B});
This example graphs the given surface and then shows the tangent plane to the surface at (x0,y0) in wireframe.

Example of an implicit plot

with(plots):
Fmin:=(x,y)->x^2+y^2;
A:=implicitplot({seq(Fmin(x,y)=.2*j, j=1..5)},x=-1..1, y=-1..1,axes=boxed, scaling=unconstrained):
B:=gradplot(Fmin(x,y),x=-1..1,y=-1..1,arrows=SLIM):
display({A,B});
The output of the display command plots the following sequence of implicitly defined curves in the plane:

Contour Lines and Gradient Plots

with(plots):
f:= (x,y) -> 8*x^4-8*x^2+1;
A:=gradplot((f(x)+f(y)),x=-1.2..1.2,y=-1.2..1.2,grid=[15,15]):
B:=contourplot(f(x)+f(y),x=-1.2..1.2,y=-1.2..1.2,grid=[20,20]):
display({A,B});
The output of the display command plots the contour lines to the 2 variable function F(x,y)=f(x)+f(y) and superimposes on this plot the gradient lines as well. Note that the option grid modifies the density of contour lines and gradient arrows.

Newton's Method

The following code implements Newton's method for solving by successive approximations two non-linear equations in two unknowns.
f:=(x,y)->3*x^2-x*y+4*y^2+2*x;
g:=(x,y)->y^2+5*x^2+x*y-2*y;
 
NsMethod:=proc(x0,y0,n)
  local NewX,NewY,k,s,x,y,Tf,Tg;
  NewX:=x0:
  NewY:=y0:
  readlib(mtaylor):
  for k from 1 to n do
    Tf:=mtaylor(f(x,y),[x=NewX,y=NewY],2):
    Tg:=mtaylor(g(x,y),[x=NewX,y=NewY],2):
    s:=solve({Tf=0,Tg=0},{x,y}):
    assign(s):
    NewX:=x:
    NewY:=y:
    x:='x':
    y:='y':
  od;
  [NewX,NewY];
end:

NsMethod(0.1,0.1,5);

This code defines the procedure NsMethod which works in conjunction with the functions f and g defined previously. It is strongly suggested that one always use a float (decimal) in the parameters for NsMethod; otherwise, if one uses integers, the procedure will return fractions of rapidly increasing size without evaluation them into decimal numbers.




Previous     Top     Table of Contents