Vector Valued Functions
Section 12.1
From our text, we have:
Definition: A vector-valued function is a rule that assigns a vector to each input number. Typically a vector-valued function has the form
where x, y and z are scalar-valued functions.
The domain consists of those \(t\) in the domain of x, y, and z.
So the range is a collection of vectors.
Below is an example of a vector valued function plotted in Sage:
t = var('t')
# Define the tuple or vector
r = (cos(t), sin(t), t)
# Use parametric_plot3d for curves
# Syntax: parametric_plot3d( (x, y, z), (variable, start, end) )
parametric_plot3d(r, (t, 0, 6*pi), thickness=2).show(aspect_ratio=(4,4,1))
t = var('t')
f1 = 4 - 2*t
f2 = 2 - t
r2 = vector((t, f1, f2))
parametric_plot3d(r2, (t, 0, 2), thickness=2).show()
Limits
The limit of a vector valued function (so it appears) is also a vector:

We can’t find such limits directly in sage, but we can write a function to do it easily:
# Do assignment 12.1 with our new function
t = var('t')
V = vector([4*t^2 - t - 2, (t^2 + 2*t -63)/(t-7), 2*cos(t)])
latex(V)
\left(4 \, t^{2} - t - 2,\,\frac{t^{2} + 2 \, t - 63}{t - 7},\,2 \, \cos\left(t\right)\right)
def vvf_limit(fn, v, a):
"""Returns a list with the limit of a vector valued function
Parameters:
fn: The vector, list, or tuple representing the vector valued function
v: The variable used in the function
a: The "endpoint" or target of the limit, e.g. oo for infinity, 0, etc.
Returns:
A list of values with the limit of each component of the function
"""
l = list(fn)
return [limit(x, v, a) for x in l]
t = var('t')
r5 = [cos(t), sqrt(4 + t), 3*e**(2*t)]
print(vvf_limit(r5, t, 0))
[1, 2, 3]
%display plain
t = var('t')
x(t) = 4*t^2 - t -2
y(t) = (t^2 + 2*t -63)/(t-7)
z(t) = 2 * cos(t)
V = [x(t), y(t), z(t)]
print("12.1 question 5")
print(V)
print(vvf_limit(V, t, 7))
print("\n12.1 question 5")
V2 = [2*t^2 + 3*t -1, (t^2 + 2*t -24)/(t-4), 4*cos(t)]
print(V2)
vvf_limit(V2, t, 4)
lim(sin(t)/t, t, 0)
12.1 question 5
[4*t^2 - t - 2, (t^2 + 2*t - 63)/(t - 7), 2*cos(t)]
[187, 16, 2*cos(7)]
12.1 question 5
[2*t^2 + 3*t - 1, (t^2 + 2*t - 24)/(t - 4), 4*cos(t)]
1
Continutity
A vector valued function \(r(t)\) is continuous at \(t_0\) if \(\lim\limits_{t \to t_0} r(t) = r(t_0)\)
# An ellipse and an eliptical helix, comment out one or the other
x = var('x')
# parametric_plot([sin(x), 2*cos(x)], (x, 0, 2*pi))
parametric_plot3d([sin(x), 2*cos(x), x], (x, 0, 8*pi))
# Sustitution example:
r5(t) = [cos(t), sqrt(4 + t), 3*e**(2*t)]
print(r5(9), N(r5(9)))
(cos(9), sqrt(13), 3*e^18) (-0.911130261884677, 3.60555127546399, 1.96979907411992e8)
# 1. Import the Cylinder shape
from sage.plot.plot3d.shapes import Cylinder
# 2. Create the cylinder object: Cylinder(radius, height)
C = Cylinder(1, 2, color='blue', opacity=0.4)
# 3. Display the graph
C.show(aspect_ratio=(1,1,1))
# aspect_ratio=(1,1,1) ensures the axes are scaled equally, so it looks circular
Section 12.2 - The Derivative of vector-valued functions
The derivative of a vector valued function is simply the derivative of each component, so as in the case of limits, we can implement a function to find one easily in Sage.
def vvf_diff(fn, v, diff_n=1):
"""Returns a list representing the limit of a vector valued function
Parameters:
fn : The vector, list, or tuple representing the vector valued function
v : The variable used in the function
diff_n : 1 for first derivative, 2 for second, etc.
Returns:
A list of values with the limit of each component of the function
"""
l = list(fn)
return [diff(x, v, diff_n) for x in l]
# Test out the vvf_diff function
var('x')
V = vector([x^3 + 3*x, ln(x), 5*x + 3])
V_prime = vvf_diff(V, x)
assert V_prime == [3*x^2 + 3, 1/x, 5]
print(V_prime)
[3*x^2 + 3, 1/x, 5]
# Solve a problem (12.2, q 3):
t = var('t')
print("Problem 12.2, q 3")
V = vector([-3*t^5 - 2, 4*e^(3*t), -5*sin(-3*t)])
print(V)
print(vvf_diff(V, t))
print("\nProblem 12.2, q 4")
V = vector([(-4)/(-t+6), (2*t)/(3*t^2 + 1), (-t^2)/(-7*t^3 - 2)])
print(V)
print(vvf_diff(V, t))
print("\nProblem 12.2, q 5 (second derivative)")
V = vector([6*t + 3*sin(t), 5*t + 6*cos(t)])
print (V)
print(vvf_diff(V, t, 2))
print(vvf_diff(vvf_diff(V, t), t))
Problem 12.2, q 3
(-3*t^5 - 2, 4*e^(3*t), -5*sin(-3*t))
[-15*t^4, 12*e^(3*t), 15*cos(-3*t)]
Problem 12.2, q 4
(4/(t - 6), 2*t/(3*t^2 + 1), t^2/(7*t^3 + 2))
[-4/(t - 6)^2, -12*t^2/(3*t^2 + 1)^2 + 2/(3*t^2 + 1), -21*t^4/(7*t^3 + 2)^2 + 2*t/(7*t^3 + 2)]
Problem 12.2, q 5 (second derivative)
(6*t + 3*sin(t), 5*t + 6*cos(t))
[-3*sin(t), -6*cos(t)]
[-3*sin(t), -6*cos(t)]
Velocity/Acceleration of Vector Valued Functions
In either \(\mathbb{R}^2\) or \(\mathbb{R}^3\) if a vector-valued function, \(r(t)\) represents the curve of position (e.g. at point \(t\)), then \(v(t) = r^{\prime}(t)\) is the velocity, and \(r^{\prime\prime}(t)\) is the acceleration. The speed is given by the magnitude of the velocity vector, \(\|v(t)\|\).
To do this in code, see the following example based on functions we’ve already defined.
# Find the velocity vector and speed given a position vector
# Our results agree with the example shown in the Video assignment 12.2 Q4, so they are correct,
# but the simplification on the speed value leaves room for improvement.
t = var('t')
pos_vector = vector([cos(pi * t), sin(pi*t), t^2/2])
velocity_vector = vector(vvf_diff(pos_vector, t)) # Need to wrap list in a vector again for "norm"
acceleration_vector = vvf_diff(pos_vector, t, 2)
speed = velocity_vector.norm().simplify()
print(velocity_vector)
print(acceleration_vector)
print(speed)
(-pi*sin(pi*t), pi*cos(pi*t), t)
[-pi^2*cos(pi*t), -pi^2*sin(pi*t), 1]
sqrt(pi^2*cos(pi*t)^2 + pi^2*sin(pi*t)^2 + t^2)
The Unit Tangent Vector.
A unit tangent vector for a VVF, \(r(t)\) is given by the derivative of the vector over the magnitude of that derivative. (So it’s similar to the formula for a unit vector.)
That is, assuming \(r^{\prime}(t) \ne 0\),
Calculating and Plotting a Unit Tangent Vector in SageMath
Let’s calculate one for \(r(t) = \langle t^3, 2t^2\rangle\), with a tangency point at t = 1. We get the correct values, but this vector would need to be graphed with the origin at the tangency point, (1,2). W
# Set up the curve
t = var('t')
r = vector([t**3, 2*t^2])
# Get the derivative, and plug in the point at which we want to draw the unit tangent vector
r_prime = vector(vvf_diff(r, t))
tangency_point = r(t=1)
print("Tangency point: ", tangency_point)
# Calculate the tangent vector using the formula above
tangent_vector = r_prime/r_prime.norm()
print("Tangent vector:", tangent_vector(t=1))
# Get a plot for the curve
plt = parametric_plot(r, (t, .75, 1.4), linestyle="dashed")
# Plot the unit tangent vector. By setting start equal to our tangency point, we place
# the vector tail where it belongs
plt2 = plot(tangent_vector(t=1), start=tangency_point, color="red")
plt += plt2
plt.show(aspect_ratio=1)
Tangency point: (1, 2)
Tangent vector: (3/5, 4/5)
Anti-Derivatives: Integration of Vector Valued Functions
Given our discussion of limits and derivatives, we might have guessed that the integral of a vector valued function is calculated by taking the integral of each of the components. Thus, for example, given an indefinite integral for \(r(t) = \langle f(t), g(t), h(t)\rangle\), then the definite integral is as follows:
For the definite integral, we have: $\( \begin{aligned} \int_{a}^{b} \mathbf{r}(t) \, dt = \left( \int_{a}^{b} f(t) \, dt \right) \mathbf{i} + \left( \int_{a}^{b} g(t) \, dt \right) \mathbf{j} + \left( \int_{a}^{b} h(t) \, dt \right) \mathbf{k} \end{aligned} \)$
As we did before for limits and derivatives, we can easily implement this in sage
def vvf_integrate(fn, v, limits=None):
"""Returns a list with the integral of each component of a vector-valued function
Parameters:
fn: The vector, list, or tuple representing the vector valued function
v: The variable used in the function
limits: Either none or a two-element iterable for a definite integral.
Returns:
A list of values with the limit of each component of the function
Notes:
Initial condition problems are not yet handled by this function.
"""
l = list(fn)
if limits is None:
return [integrate(x, v) for x in l]
else:
return [integrate(x, v, limits[0], limits[1]) for x in l]
t = var('t')
r5 = [cos(t), sqrt(4 + t), 3*e**(2*t)]
# Test it out
print(vvf_integrate(r5, t))
print(vvf_integrate(r5, t, (0, pi/2)))
[sin(t), 2/3*(t + 4)^(3/2), 3/2*e^(2*t)]
[1, 2/3*(1/2*pi + 4)^(3/2) - 16/3, 3/2*e^pi - 3/2]
# Solve some problems with it. Let's start with 12.2, Q6
t = var('t')
r = vector([-4*t^2 + 1, -1*e^(-1 * t), 5 * sin(-4*t)])
print("12.2 Q6", vvf_integrate(r, t))
print("\nAdd initial conditions manually\nto each term for the next problem:")
r = vector([3 + 4*t, cos(t), 6*e^(3*t)])
print("\t12.2 Q7", vvf_integrate(r, t))
12.2 Q6 [-4/3*t^3 + t, e^(-t), 5/4*cos(4*t)]
Add initial conditions manually
to each term for the next problem:
12.2 Q7 [2*t^2 + 3*t, sin(t), 2*e^(3*t)]
diff(ln(2*t))
1/t
# Solving 12.2 Q9. We're asked to find the angle of
# intersection between two vectors. Originally I though we could just
# use get_angle_between_vectors with respect to the two vectors "as is",
# but it turns out we needed the angle between the tangent vectors
# of each funciton, so get the derivative first.
# Copied from another notebook -- at some point this needs to be a library!
def get_angle_between_vectors(v: vector, w: vector):
"""returns the angle between two vectors in radians."""
cos_theta = (v*w)/(v.norm() * w.norm())
return acos(cos_theta)
r1 = vector([2*t, t^3, -1*t^4])
r2 = vector([sin(-2 * t), sin(2*t), t - pi])
angle_as_fn = get_angle_between_vectors(diff(r1, t), diff(r2, t))
print(N(angle_as_fn(t=0)))
2.30052398302186
Solving another unit tangent vector problem
Question 12.2 # 10 asks us to find the unit tangent vector at the point \(t = 0\) for the function \(r(t) = \langle 4t^5 -2, -2 e^{3t}, -2 sin(5t) \rangle\)
Let’s do this using the technique we developed earlier:
# Set up the curve
t = var('t')
r = vector([4*t^5 - 2, -2*e^(3*t), -2 * sin(5*t)])
print(r)
# Get the derivative, and plug in the point at which we want to draw the unit tangent vector
r_prime = vector(vvf_diff(r, t))
tangency_point = r(t=0)
print("Tangency point: ", tangency_point)
# Calculate the tangent vector using the formula above
tangent_vector = r_prime/r_prime.norm()
print("Unit tangent vector:", tangent_vector(t=0))
(4*t^5 - 2, -2*e^(3*t), -2*sin(5*t))
Tangency point: (-2, -2, 0)
Unit tangent vector: (0, -3/34*sqrt(34), -5/34*sqrt(34))