Skip to main content
Engineering LibreTexts

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{\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}}\)

    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}\).


    This page titled 12.1: Spatial Vectors is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Allen B. Downey (Green Tea Press) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?