12.1: Spatial Vectors
- Page ID
- 84547
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\dsum}{\displaystyle\sum\limits} \)
\( \newcommand{\dint}{\displaystyle\int\limits} \)
\( \newcommand{\dlim}{\displaystyle\lim\limits} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\(\newcommand{\longvect}{\overrightarrow}\)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\ket}[1]{\left| #1 \right>}\)
\(\newcommand{\bra}[1]{\left< #1 \right|}\)
\(\newcommand{\braket}[2]{\left< #1 \vphantom{#2} \right| \left. #2 \vphantom{#1} \right>}\)
\(\newcommand{\braopket}[3]{\left< #1 \vphantom{#2}\vphantom{#3} \right| #2 \vphantom{#1}\vphantom{#3} \left| #3 \vphantom{#1}\vphantom{#2} \right>}\)
\(\newcommand{\qmvec}[1]{\mathbf{\vec{#1}}}\)
\(\newcommand{\op}[1]{\hat{\mathbf{#1}}}\)
\(\newcommand{\expect}[1]{\langle #1 \rangle}\)
\(\newcommand{\dfn}[1]{\emph{\textbf{#1}}}\)
The word vector means different things to different people. In MATLAB, a vector is a matrix that has either one row or one column. So far, we’ve used MATLAB vectors to represent the following:
Sequences
A mathematical sequence, like the Fibonacci numbers, is a set of values identified by integer indices; in Chapter 4.5, we used a MATLAB vector to store the elements of a sequence.
State vectors
A state vector is a set of values that describes the state of a physical system. When you callode45, you give it initial conditions in a state vector. Then, when ode45 calls your rate function, it gives you a state vector.
Time series
One of the results from ode45 is a vector that represents a sequence of time values.
In this chapter, we’ll see another use of MATLAB vectors: representing spatial vectors. A spatial vector represents a multidimensional physical quantity like position, velocity, acceleration, or force.
For example, to represent a position in two-dimensional space, we can use a vector with two elements:
>> P = [3 4]
To interpret this vector, we have to know the coordinate system it is defined in. Most commonly, we use a Cartesian system where the x-axis points east and the y-axis points north. In that case P represents a point 3 units east and 4 units north of the origin.
When a spatial vector is represented in this way, we can use it to compute the magnitude and direction of a physical quantity. For example, the magnitude of P is the distance from the origin to P, which is the hypotenuse of the triangle with sides P(1) and P(2). We can compute it using the Pythagorean theorem:
>> sqrt(P(1)^2 + P(2)^2)
ans = 5
Or we can do the same thing using the function norm, which computes the Euclidean norm of a vector, which is its magnitude:
>> norm(P)
ans = 5
There are two ways to get the direction of a vector. One convention is to compute the angle between the vector and the x-axis:
>> atan2(P(2), P(1))
ans = 0.9273
In this example, the angle is about 0.9. But for computational purposes, we often represent direction with a unit vector, which is a vector with length 1. To get a unit vector we can divide a vector by its length:
function res = hat(V)
res = V / norm(V)
end
This function takes a vector, V, and returns a unit vector with the same direction as V. It’s called hat because in mathematical notation, unit vectors are written with a “hat” symbol. For example, the unit vector with the same direction as \(\textbf{P}\) would be written \(\hat{P}\).


