#
#
#Maple procs for use in Andrew, Samir, and Charlie's Lab investigating tangent planes
#By Charles McGarraugh with help from Samir Murty and Andrew Youn
#This is the routine for plotting a tangent plane to a graph at a given point
GraphTan := proc(f,xrange,yrange,pt)
#Define local variables
local xmin,xmax,ymin,ymax,x0,y0,z0,dx,dy,xvec,yvec,tanfunc,gpha,gphb,tanpt;
#Allow us to use (display) command
with (plots,pointplot):
with (plots,display):
#Extract the different variables we will need from the larger variables given as input from user
x0 := op(2,pt)[1]:
y0 := op(2,pt)[2]:
xmin := op(1,op(2,xrange)):
xmax := op(2,op(2,xrange)):
ymin := op(1,op(2,yrange)):
ymax := op(2,op(2,yrange)):
#Define the surface as variable name gpha
gpha := plot3d(f,xrange,yrange,style=HIDDEN,axes=BOXED):
#Evaluate partials with respect to x and y at (x0, y0)
dx := subs(x=x0,y=y0,diff(f,x)):
dy := subs(x=x0,y=y0,diff(f,y)):
#Find height of function at x0,y0
z0 := subs(x=x0,y=y0,f):
#Use partials to get tangent vectors
xvec := [1,0,dx]:
yvec := [0,1,dy]:
#Find the parameterized plane of using the tangent vectors as basis and raise it to height z0
tanfunc := evalm(t*xvec+s*yvec+[x0,y0,z0]):
#Plot tangent point as tanpt and tangent plane as gphb
tanpt := pointplot({[x0,y0,z0]},color=black):
gphb:=plot3d(tanfunc,t=-(xmax-xmin)/4..(xmax-xmin)/4,s=-(ymax-ymin)/4..(ymax-ymin)/4,style=PATCHNOGRID):
#Display the surface graph, tangent plane, and tangent point
display ([gpha, gphb,tanpt]);
end:
#This is the routine for plotting a tangent plane to a parametric curve in variables s and t
ParamTan:= proc (f,srange,trange,pt)
#Define local variables
local planefunc,s0,t0,smin,smax,tmin,tmax,pama,dfs,dft,z0,pamb,pamc,tanpt;
#Allow us to use (display) and (pointplot) commands
with(plots,pointplot):
with(plots,display):
#Extract specific variables we need from the larger variables define as input from user
s0:= op (2,pt)[1]:
t0:= op (2,pt)[2]:
smin := op(1,op(2,srange)):
smax := op(2,op(2,srange)):
tmin := op(1,op(2,trange)):
tmax := op(2,op(2,trange)):
#Plot the parametric surface. Note: f is a 3-vector as defined by user
pama:= plot3d(f,srange,trange,style=HIDDEN,axes=BOXED):
# Find the tanget vectors by taking partials with respect to s and then to t
dfs := subs(s=s0,t=t0,diff(f,s)):
dft := subs(s=s0,t=t0,diff(f,t)):
#Find the point of tangency
z0 := subs (s=s0,t=t0,f);
#Plot point of tangency under variable name tanpt
tanpt := pointplot ({z0},color=black):
# Parameterize plane using tangent vectors and k,l as parameters, add z0 to give proper translation
planefunc := evalm (k*dfs+l*dft+z0):
#Plot the tangent plane under variable name pamb, limit parameters so as not to obstruct viewing
pamb:=plot3d(planefunc,k=-(smax-smin)/8..(smax-smin)/8,l=-(tmax-tmin)/8..(tmax-tmin)/8,style=PATCHNOGRID):
#Display the plots
display ([pama,pamb,tanpt]);
end:
#This is the routine to plot the tangent plane to an implicitly defined function
ImplicitTan := proc (F,xrange,yrange,zrange,pt)
#Define local variable names
local f,K,gradat,tanpt,x0,y0,z0,impa,impb,dx,dy,dz,vec0,planefunc;
#Allows us to use (implicitplot3D), (display), and (pointplot) commands
with(plots,pointplot):
with(plots,display):
with(plots,implicitplot3d):
# Allows (innerprod) command
with (linalg,innerprod):
#Extract different variables we need from larger variable given by user input
x0 := op (2,pt)[1]:
y0 := op (2,pt)[2]:
z0 := op (2,pt)[3]:
#Plot implicit surface under variable name impa
impa := implicitplot3d(F,xrange,yrange,zrange,style=HIDDEN,axes=BOXED):
#If F is just an expression rename it f
f := F:
#If F is an equation, extract the expression as f and the constant as K
if type(F,`=`) = 'true' then
f:= lhs (F):
K := rhs (F):
fi;
#Evaluate partials of f with repect to x, y, and z.
dx := subs(x=x0,y=y0,z=z0,diff(f,x)):
dy := subs(x=x0,y=y0,z=z0,diff(f,y)):
dz := subs(x=x0,y=y0,z=z0,diff(f,z)):
#Create the gradient vector at [x0,y0,z0] Which we know is normal to suface
gradat := [dx,dy,dz]:
#Find the fuction for tangent plane (implicitly defined)
#Using fact that plane is given by-- grad(x0,y0,z0) dot ([x-x0,y-y0,z-z0]) = 0
vec0:= (evalm([x,y,z]-[x0,y0,z0])):
planefunc:= innerprod(gradat,vec0):
#Plot tangent plane under variable name impb
impb := implicitplot3d(planefunc,xrange,yrange,zrange):
#Plot point of tangency
tanpt := pointplot({[x0,y0,z0]},color=red):
#Display surface, tangent plane, tangent point
display ([impa,impb,tanpt]);
end: