13.7: Dot Product of Two 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.7: Dot Product of Two Vectors

    The dot product, also called the scalar product, combines two vectors and returns a single scalar value. For two three-dimensional vectors A and B, the dot product is:

    \(
    \mathbf{A} \cdot \mathbf{B} = A_xB_x + A_yB_y + A_zB_z
    \)

    In MATLAB, use the dot function:

    A = [4 -1 2];
    B = [2 -2 -1];
    C = dot(A,B)

    Let us calculate this by hand to understand what MATLAB is doing:

    C = 4(2) + (-1)(-2) + 2(-1) = 8 + 2 - 2 = 8

    What Does the Dot Product Tell Us?

    The dot product is useful because it is related to the angle between two vectors:

    A dot B = |A||B|cos(theta)

    This means the dot product can help us determine whether two vectors point in similar directions, opposite directions, or perpendicular directions.

    • If the dot product is positive, the angle between the vectors is less than 90 degrees.
    • If the dot product is negative, the angle between the vectors is greater than 90 degrees.
    • If the dot product is zero, the vectors are perpendicular.
    Example \(\PageIndex{1}\)

    Using MATLAB to compute dot([1 0 0], [0 1 0]). What does the result tell you about the angle between these two vectors?

    v1 = [1 0 0];
    v2 = [0 1 0];
    
    result = dot(v1, v2)
    Solution

    result = 0

    Because the length of both vectors is 1, the dot product is equal to the cosine of the angle between the two vectors. The result shows that the two vectors are perpendicular.

    Work Done by a Force

    A common physical example of the dot product is calculating work done by a force. When a force moves an object, the work done is the dot product of the force vector and the displacement vector. This means that only the component of the force in the direction of motion contributes to the work.

    In physics, work is defined as:

    \(
    W = \vec{F} \times \vec{d}
    \)

    where \( \vec{F} \) is the force vector and \(\vec{d}\) is the displacement vector.

    For example, suppose a person pulls a box across the floor with a force of 50 N at an angle, and the box moves horizontally. Even though the force is not completely horizontal, only the horizontal component of the force contributes to moving the box forward.

    In vector form, if:

    F = [40 30];

    and

    d = [5 0];

    then the work can be calculated in MATLAB as:

    W = dot(F, d)

    This gives:

    W = 200

    So the force does 200 J of work.

    The vertical component of the force does not contribute to the work in this case because the box does not move vertically. This is exactly why the dot product is useful: it measures how much one vector acts in the direction of another vector.

    You could add this to the chapter:

    A physical example of the dot product is the calculation of work. When a force moves an object, the work done is the dot product of the force vector and the displacement vector. This means that only the component of the force in the direction of motion contributes to the work.

    Exercise \(\PageIndex{1}\)

    A box is pulled on a horizontal surface through a 3 meter distance using a 50 N force, which makes a 30 degree angle. Use the definition of dot product to calculate the work done by the force.

    F = 50       % Newtons
    d = 3;       % meters
    theta = 30   % degrees
    
    % Fx =  
    % Fy = 
    
    % dx = 50;
    % dy = 0;
    
    % F_vec = 
    % d_vec = 
    
    % Work = 
    
    
    
    Answer
    W = 2165.1

    This page titled 13.7: Dot Product of Two Vectors was last modified on Tue, 30 Jun 2026 02:11:58 GMT and is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Zara Noroozi.