Read the notes for details.
The notes define a few useful functions, replicated here. (If the MTH229
package is installed, this can all be replaced by using MTH229
)
using LinearAlgebra # for norm, dot, and cross
using PyPlot # for plotting
using SymPy # for symbolic math
using Roots # to find zeros numerically
using QuadGK # to integerate numerically
using ForwardDiff # for derivatives
uvec(r) = r / norm(r) # unit vector
D(r::Function, n=1) = n > 1 ? D(D(r),n-1) : t -> ForwardDiff.derivative(r, float(t))
Base.adjoint(r::Function) = D(r)
xs_ys(vs) = (A=hcat(vs...); Tuple([A[i,:] for i in eachindex(vs[1])]))
xs_ys(v,vs...) = xs_ys([v, vs...])
xs_ys(r::Function, a, b, n=100) = xs_ys(r.(range(a, stop=b, length=n)))
function arrow!(plt::Plots.Plot, p, v; kwargs...)
if length(p) == 2
quiver!(plt, xs_ys([p])..., quiver=Tuple(xs_ys([v])); kwargs...)
elseif length(p) == 3
# 3d quiver needs support
# https://github.com/JuliaPlots/Plots.jl/issues/319#issue-159652535
# headless arrow instead
plot!(plt, xs_ys(p, p+v)...; kwargs...)
end
end
arrow!(p,v;kwargs...) = arrow!(Plots.current(), p, v; kwargs...)
arrow! (generic function with 2 methods)
Let $u =\langle 1,2,3 \rangle$, $v=\langle 1,1,1 \rangle$, and $w = \langle 1, -4, 3 \rangle$. Use vector calculus with julia
to find:
The sum $u + v$:
The value of $\| v \|$:
A unit vector $\hat{u}$:
The angle between the vectors $u$ and $v$:
The volume of the parallelpiped formed by $u$, $v$, and $w$:
Verify that the cross product is anti-commutative by showing $u \times v + v \times u = 0$:
Verify that the cross product is not associative by computing both $(u \times v) \times w$ and $u \times (v \times w)$ and comparing the answers:
Let $p = \langle 3,4,5 \rangle$ and $v = \langle 1,2,1 \rangle$. Write a function, r(t)
, that parameterizes the line in the direction of $v$ going through the point $p$.
Find the distance between $r(0)$ and $r(3)$ using julia
:
Let r(t) = [sin(t), 2cos(t), 0]
.
Make a plot of r
over the interval $[0,2pi]$, what kind of shape is it?
Let er
be the unit vector of r
. Write this as a function of t
:
Show that r(t) × r'(t)
is a constant in t
by taking 3 different values of t
and comparing:
Show that r''(t)
and r(t)
are parallel by showing the for a 3 different values of t
the cross product of the two vectors is basically 0 (up to numeric round off).
Using SymPy
, define a symbolic variable t
:
using SymPy
@vars t real=true
(t,)
The Bernoulli spiral is parameterized by r(t) = exp(t) * [cos(4t), sin(4t)]
. Plot this over $[-10, 3]$:
Show the following symbolically for the Bernoulli spiral: the angle between the position vector $r(t)$ and the tangent vector $r'(t)$ is constant, that is it does not depend on $t$:
A spiraling curve is given by $r(t) = [t \cdot \cos(4t), t \cdot \sin(4t)]$.
Make a plot over $[0, 3\pi]$:
Compute $\| r'(t) \|$ symbolically and assign its simplified output to ds
.
Compute the arclength over $[0,3\pi]$ via integrate(ds, t, 0, 3PI)
Let Viviani's curve be given by $r(t) = \langle 1 + \cos(t), \sin(t), 2\sin(t/2) \rangle$.
Plot this over $[0, 2\pi]$:
Compute the curvature of the curve at time $t$ and compare with
Let $r(t) = [\sin(t), t, 0]$. Find the curvature for all $t$. Plot it. Where is it maximal? What part of the $\sin(t)$ curve would this correspond to?