PREP Quickstart, Multivariable Calculus
system:sage


<h1 style="font-size: 2em;">Sage Quickstart for Multivariable Calculus</h1>
<p>This&nbsp;<a href="http://www.sagemath.org" target="_blank">Sage</a>&nbsp;worksheet was developed for the MAA PREP Workshop "Sage: Using Open-Source Mathematics Software with Undergraduates" (funding provided by NSF DUE 0817071).</p>
<p>&nbsp;</p>

<h2><span style="color: #ff0000;">Vector Calculus</span></h2>
<p><span style="color: #ff0000;"><span style="color: #000000;">In Sage, vectors are primarly linear algebra objects, but they are slowly becoming simultaneously analytic continuous functions. (Mostly due to the efforts of Jason Grout.)</span><br /></span></p>

<h4>Dot Product, Cross Product</h4>

{{{id=2|
v = vector(RR, [1.2, 3.5, 4.6])
w = vector(RR, [1.7,-2.3,5.2])
v*w
///
}}}

{{{id=1|
v.cross_product(w)
///
}}}

<h4>Lines and Planes</h4>
<p>Intersect $x-2y-7z=6$ with $\frac{x-3}{2}=\frac{y+4}{-3}=\frac{z-1}{1}$</p>

{{{id=6|
# designed with intersection at t = 2, i.e. (7, -10, 3)
var('t, x, y')
line = parametric_plot3d([2*t+3, -3*t-4, t+1], (t, 0, 4),color='red')
plane = plot3d((1/5)*(-12+x-2*y), (x, 4, 10), (y, -13,-7), opacity=0.5)
intersect=point3d([7,-10,3],color='black')
line+plane+intersect
///
}}}

<h4>Vector-Valued Functions</h4>

{{{id=9|
var('t')
r(t)=(2*t-4, t^2, (1/4)*t^3)
///
}}}

{{{id=10|
rprime(t)=list(r.diff(t))
///
}}}

{{{id=13|
rprime.norm()
///
}}}

{{{id=11|
velocity(t)=list((1/rprime.norm())*rprime)
///
}}}

{{{id=12|
velocity(4)
///
}}}

<p>Notice: the syntax is <strong>not</strong>&nbsp; numerical_integral(f(t), (t, 0, 1)).</p>

{{{id=14|
arc_length = numerical_integral(rprime.norm(), 0,1)
arc_length
///
}}}

<h2><span style="color: #ff0000;">Functions of Several Variables</span></h2>

{{{id=33|
# import matplotlib.cm; matplotlib.cm.datad.keys()
# 'Spectral', 'summer', 'blues'
g(x,y)=e^-x*sin(y)
contour_plot(g, (x, -2, 2), (y, -4*pi, 4*pi), cmap = 'Blues', contours=10, colorbar=True)
///
}}}

<h2><span style="color: #ff0000;">Partial Differentiation</span></h2>

{{{id=18|
# Hass, Weir, Thomas, University Calculus, Exercise 12.7.35
#
# Local min at (4, -2)
#
var('x y')
f(x, y) = x^2 + x*y + y^2 - 6*x + 2
///
}}}

{{{id=25|
fx(x,y)= f.diff(x)
fy(x,y) = f.diff(y)
print fx
print fy
///
}}}

{{{id=26|
f.gradient()
///
}}}

{{{id=27|
solve([fx==0, fy==0], (x, y))
///
}}}

{{{id=28|
H = f.hessian()
H
///
}}}

{{{id=29|
print "f_xx: ", H(4,-2)[0,0]
print "D: ", H(4,-2).det()
///
}}}

<h2><span style="color: #ff0000;">Multiple Integration</span></h2>

<p>Vvolume under $f(x,y)=x^2y$ above the triangle bounded by $y=0$, $x=3$ and $y=4x$.</p>

{{{id=39|
var('x y')
f(x,y)=x^2*y
///
}}}

{{{id=37|
# dy dx
integrate( integrate(f(x,y), (y, 0, 4*x)), (x, 0, 3) )
///
}}}

{{{id=35|
# dx dy
integrate( integrate(f(x,y), (x, y/4, 3)), (y, 0, 12) )
///
}}}

{{{id=31|
var('u v')
surface = plot3d(f(x,y), (x, 0, 3.2), (y, 0, 12.3), color = 'blue', opacity=0.3)
domain = parametric_plot3d([3*u, 4*(3*u)*v,0], (u, 0, 1), (v, 0,1), color = 'green', opacity = 0.75)
image = parametric_plot3d([3*u, 4*(3*u)*v, f(3*u, 12*u*v)], (u, 0, 1), (v, 0,1), color = 'green', opacity = 1.00)
surface+domain+image
///
}}}