13.9: Magnitude and Unit Vectors

Fundamentals of MATLAB Programming · LibreTexts

0%

Contents

    Text

    Size
    100%
    Theme
    Typeface
    Line length
    Spacing

    From LibreTexts, under CC BY-NC-SA, as the source states it; its equations are written in TeX, which the PDF shows typeset. This page at LibreTexts.

    13.9: Magnitude and Unit Vectors

    The magnitude of a vector is its length. For a vector A = [Ax Ay Az], the magnitude is calculated using the square root of the sum of the squares of the components:

    \(|A| = sqrt(Ax^2 + Ay^2 + Az^2)\)

    In MATLAB, the norm function calculates this for us.

    A = [4 -1 2];
    magA = norm(A)
    

    A unit vector is a vector with magnitude 1. It keeps the direction of the original vector but removes the size. To create a unit vector, divide the vector by its magnitude:

    unitVec = A / norm(A)
    norm(unitVec)
    

    The second command should return 1, or a number very close to 1 because of numerical rounding.


    This page titled 13.9: Magnitude and Unit Vectors was last modified on Tue, 30 Jun 2026 02:11:59 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.