Maple hints for "week 7" homework

sm311o_11.mws,wdj,3-23-98

1(a), section 8.5

> f:=(x,y)->x^2+2*x*y+4*y^2;

[Maple Math]

> diff(f(x,y),x);
diff(f(x,y),y);

[Maple Math]

[Maple Math]

1(i), section 8.5

> p:=(x,y,z)->(sqrt(x^2+y^2+z^2)^2-1)/sqrt(x^2+y^2+z^2)^3;

[Maple Math]

> diff(p(x,y,z),x$2);

[Maple Math]

1(l), section 8.5

> u:=(x,y,z)->BesselJ(1,a*sqrt(x^2+y^2+z^2));

[Maple Math]

> diff(u(x,y,z),x);

[Maple Math]

6(b), section 8.5

> psi:=(x,y)->a*y-b*y/(x^2+y^2);

[Maple Math]

> laplace:=proc(p)
local temp;
temp:=diff(p(x,y),x$2)+diff(p(x,y),x$2);
RETURN(temp);
end;

[Maple Math]

> laplace(psi);

[Maple Math]

>

Problem 1(a), section 8.6

For this we use a program written by

##
##Robert Israel israel@math.ubc.ca
##Department of Mathematics (604) 822-3629
##University of British Columbia fax 822-6074
##Vancouver, BC, Canada V6T 1Y4
##
##################################################################

> with(plots):
with(linalg):
with(plottools):

> evl := t -> convert(evalm(t), list);

[Maple Math]

## myarrow plots an arrow as a line with a pyramidal head.
## usage: myarrow(base, vect, options)
## "base" is point for base of arrow, "vect" is tip - base
## These can be lists or vectors.
## "options" are the usual plot3d options.
## Colour is red by default.
## More options could be added to control the proportions of the arrow.

> myarrow := proc(base::{list,vector},vect::{list,vector})
local b1,v1,stem,r,hbase,hpoint,v2,v3,head,opts;
b1 := evalf(evl(base));
v1 := evalf(evl(vect));
if nops(b1) <> 3 or nops(v1) <> 3 then
ERROR(`points need three dimensions`)
fi;
if not type(b1,[realcons,realcons,realcons]) and
type(v1,[realcons,realcons,realcons]) then
ERROR(`points must evaluate to real constants`)
fi;
hbase := evl(b1+.8*v1);
hpoint := evl(b1+v1);
opts := args[3 .. nargs];
if indets({opts}) intersect {color,colour} = {} then
opts := opts,colour = red
fi;
stem := plots[spacecurve]([b1,hbase],thickness = 3,opts);
if v1 = [0,0,0] then RETURN(stem) fi;
r := sqrt(linalg[norm](v1,2));
v2 := evl(linalg[crossprod]([1,0,0],v1));
if linalg[dotprod](v2,v2) < .01*linalg[dotprod](v1,v1) then
v2 := evl(linalg[crossprod]([0,1,0],v1))
fi;
v2 := evl(.05*r*v2/linalg[norm](v2,2));
v3 := linalg[crossprod](v1,v2);
v3 := evl(.05*r*v3/linalg[norm](v3,2));
head := plots[polygonplot3d]([hpoint,evl(hbase+v2),
evl(hbase+v3), evl(hbase-v2),
evl(hbase-v3), evl(hbase+v2)]
,style = patch,opts);
plots[display]({stem,head})
end;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

## surfarrows plots a 3d surface (parametric or cartesian) with arrows from
## a vector field at points on the surface
## Usage:
## surfarrows(F(s,t),[x(s,t),y(s,t),z(s,t)],s=a1..b1,t=a2..b2,options)
## for vectors F(s,t) at points [x(s,t), y(s,t), z(s,t)]
## where F(s,t) is a list expression
## surfarrows(F(x,y), z(x,y), x=a1 .. b1, y=a2 .. b2, options)
## for vectors F(x,y) at points [x, y, z(x,y)]
## where F(x,y) is a list expression
## surfarrows(F, [x(s,t),y(s,t),z(s,t)], s=a1 .. b1, t=a2 .. b2, options)
## for vectors F(x(s,t),y(s,t),z(s,t)) at [x(s,t),y(s,t),z(s,t)]
## where F is a list-valued function of three variables
## surfarrows(F, z(s,t), x=a1 .. b1, y=a2 .. b2, options)
## for vectors F(x,y,z(s,t)] at [x,y,z(x,y)]
## where F is a list-valued function of three variables
## "options" are the usual 3d plot options, plus
## arrowgrid= [n1, n2]
## for arrows in an n1xn2 grid, equally spaced in terms of the parameters
## of the surface (default is arrowgrid=[8,8])
## Caution: inputs are not checked for validity

> surfarrows := proc(fld,surf,r1,r2)
local opts,gspec,p1,p2,s2,f2,v1,v2,a1,a2,b1,b2,n1,n2,h1,h2,i,j;
opts := args[5 .. nargs];
v1 := op(1,r1);
v2 := op(1,r2);
a1 := op(1,op(2,r1));
b1 := op(2,op(2,r1));
a2 := op(1,op(2,r2));
b2 := op(2,op(2,r2));
gspec := indets({opts},identical('arrowgrid') = list);
if gspec = {} then gspec := arrowgrid = [8,8]
else opts := op({opts} minus gspec); gspec := gspec[1]
fi;
p1 := plot3d(surf,r1,r2,opts);
opts :=
op({opts} minus indets({opts},identical('grid') = list));
n1 := op(2,gspec)[1]-1;
n2 := op(2,gspec)[2]-1;
h1 := (b1-a1)/n1;
h2 := (b2-a2)/n2;
if type(surf,list) then s2 := surf
elif type(surf,vector) then s2 := evl(surf)
else s2 := [v1,v2,surf]
fi;
if type(fld,procedure) then f2:= fld(op(s2))
else f2:= evl(fld)
fi;
p2 := seq(seq(
myarrow(op(subs(v1 = a1+h1*i,v2 = a2+j*h2,[s2,f2])),opts),
i = 0 .. n1),j = 0 .. n2);
plots[display]({p2,p1},opts)
end;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> surf1:= [u, v, u*v]:
unit:= V -> evl(V/norm(V,2)):
tnormal:= unit(crossprod(diff(surf1,u),diff(surf1,v))):
surfarrows( tnormal/2, surf1, u=-2..2, v=-2..2, scaling=constrained);

[Maple Plot]

Another picture of the same surface:

> P1:=contourplot(x*y,x=-2..2,y=-2..2,color=grey):
P2:=fieldplot([y,x],x=-2..2,y=-2..2,color=black):
display([P1,P2]);

[Maple Plot]

Problem 4(a),section 8.6

> f:=(x,y)->x*y;

[Maple Math]

> direct_der:=proc(f,n,P)
local u,x,y,a,b,temp;
a:=P[1]; b:=P[2];
u:=n/sqrt(dotprod(n,n));
temp:=subs({x=a,y=b},dotprod(u,[diff(f(x,y),x),diff(f(x,y),y)]));
RETURN(temp);
end;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> direct_der(f,[1,1],[2,3]);

[Maple Math]

> grad(f(x,y),[x,y]);
direct_der(f,[3,2],[2,3]);

[Maple Math]

[Maple Math]

Problem 5(a), section 8.6

> grad(F(x,y)*G(x,y),[x,y]);

[Maple Math]

> F(x,y)*grad(G(x,y),[x,y])+grad(F(x,y),[x,y])*G(x,y);

[Maple Math]

> iszero(grad(F(x,y)*G(x,y),[x,y])-(F(x,y)*grad(G(x,y),[x,y])+grad(F(x,y),[x,y])*G(x,y)));

[Maple Math]

Problem 9, section 8.6

The command to plot S and the curve C_23 is given below. You need to modify it for parts (a), (b), (c).

> r:=(m,n,t)->[sin(m*t)*cos(n*t),sin(m*t)*sin(n*t),cos(m*t)];

[Maple Math]

> P1:=spacecurve(r(2,3,t),t=0..(2*Pi),color=black,thickness=3):
P2:=sphereplot(1,theta=0..(2*Pi),psi=0..(Pi),color=grey,style=wireframe):
display3d([P1,P2]);

[Maple Plot]

>