What is a dot product?

Key takeaways:

  • The dot product calculates the product of two vectors and is used in physics, engineering, and computer science.

  • The dot product can be defined in two different ways:

    • Algebraic representation of dot product: x·y = (x1 × y1) + (x2 × y2)

    • Geometric representation of dot product: x·y = |x||y|cos(θ)

  • Properties of dot product:

    • Commutative property: The order of multiplication doesn't affect the result: x⋅y = y⋅x

    • Distributive property: Multiplication distributes over addition x⋅(y+z) = x⋅y+x⋅z

    • Scalar multiplication: Scaling a dot product can be done on either vector: c(x⋅y) = (cx)⋅y = x⋅(cy)

    • Orthogonal vectors: If two vectors are perpendicular, their dot product is zero: x⋅y = 0

  • Applications of dot product: It is used in fields like physics for calculating work done, in geometry to find angles between vectors, and in computer graphics for lighting and projection calculations.

What is a dot product?

The dot product, also known as the scalarA scalar is a quantity in mathematics that has magnitude only and no direction, unlike vectors, which have both magnitude and direction. product, computes the product of two vectors and gives a scalar value that represents how much two vectors align in the same direction. It quantifies the magnitude of one vector projected onto the other. If the vectors point in the same direction, the dot product is positive and large; if they are perpendicular, the dot product is zero; and if they point in opposite directions, the dot product is negative. It is widely used in fields like physics, engineering, and computer science, particularly in understanding projections, magnitudes, and calculating work done in force fields.

What does dot product tell you?

The dot product measures how much two vectors align. Suppose you're walking along a street, and a breeze is blowing. You want to know how much of that breeze is helping push you forward versus how much is just blowing past. The direction you're walking is one vector, and the direction of the breeze is another.

If the breeze blows directly behind you, it’s fully pushing you forward, and the dot product is at its maximum. If it blows sideways at a 90-degree angle, there's no forward push, and the dot product is zero. The dot product tells you how much these directions align, with higher values indicating greater alignment.

Now, we'll take an example of two vectors xx and yy, the below diagram shows these vectors and angle between them:

Dot product of two vectors
Dot product of two vectors

The dot product can be defined in two different ways: algebraically and geometrically. Let's explore both approaches.

Algebraic definition of dot product

Algebraically, the dot product of two vectors is the summation of the products of their corresponding components. For two vectors xx and yy, the dot product is defined as:

Example

Let's consider two vectors, x=[6,8]x = [-6, 8] and y=[5,12].y = [5, 12].

The dot product of these vectors is calculated as:

Algebraical implementation of dot product

Here’s a simple code implementation of the dot product between two vectors using NumPy in Python:

import numpy as np
# Define vectors
x = np.array([-6, 8])
y = np.array([5, 12])
# Compute the dot product of vectors
product = np.dot(x, y)
# Print dot product
print('Dot Product:',product)

This calculation illustrates how easily we can compute the dot product of vectors in Python. The result is a scalar, highlighting the reason why the dot product is also called the scalar product.

Geometric definition of dot product

Geometrically, the dot product represents the product of the magnitudes of two vectors and the cosine of the angle between them. For two vectors xx and yy, the dot product can be written as:

Where:

  • x|x| and y|y|  are the magnitudes of vectors xx and yy, respectively.

  • θθ is the angle between the vectors.

Magnitude of a vector

The magnitude (or length) of a vector xx is computed as:

Angle between two vectors

The angle θθ between vectors xx and yy can be determined using the following formula:

Example

Let's consider two vectors x=[6,8]x = [-6, 8] and y=[5,12].y = [5, 12].To compute their dot product, we first calculate the magnitudes:

As the angle θθ between them is 59.5°59.5° then,

Thus the dot product of xx and yy is:

Geometrical implementation of dot product

Below is an implementation of the dot products between two vectors, taking into account their magnitudes.

import numpy as np
#define vectors
x = np.array([-6, 8])
y = np.array([5, 12])
#dot product of vectors
product = np.dot(x, y)
print('x.y =',product)
#magnitude of vectors
mag_x = np.dot(x,x)**0.5
mag_y = np.dot(y,y)**0.5
#print magnitudes
print('|x| = ', mag_x)
print('|y| = ', mag_y)
#angle between vectors
angle_rad = np.arccos(product/(mag_x*mag_y))
angle = np.degrees(angle_rad)
print('Angle between vectors:',angle)

Properties of dot product

The dot product holds several important properties that make it a fundamental operation in vector algebra. Let xx, yy, and zz be vectors and cc be a scalar. The properties governing their dot products are listed in the table below.

Properties of the dot product operation

Properties

Formulas

Description

Commutative property

x.y = y.x

The order of multiplication doesn't affect the result.

Distributive property

c(x.y) = (cx).y = x.(cy)

Multiplication distributes over addition.

Scalar multiplication

x.(y+z) = x.y + x.z

Scaling a dot product can be done on either vector.

Orthogonal vectors

x.y = 0 if x and y are perpendicular

If two vectors are perpendicular, their dot product is zero.

Applications of dot product

The dot product is used in many fields, including:

  • Physics: Calculating work done by a force along a displacement uses the dot product of the force and displacement vectors.

  • Geometry: Understanding the angle between vectors and determining if vectors are perpendicular (orthogonal).

  • Computer graphics: In 3D rendering, the dot product is crucial for lighting calculations and projections.

Conclusion

In conclusion, the dot product is a versatile vector operation used across various fields. It helps understand vector relationships, such as magnitudes and angles, and is essential for solving mathematical problems and practical applications like computing work in force fields and 3D graphics rendering.

Frequently asked questions

Haven’t found what you were looking for? Contact Us


What is the difference between inner product and dot product?

The dot product is a specific type of inner product used in Euclidean spaces, while the inner product is a broader concept applicable to various vector spaces. To learn more about the inner product, check the following: What is inner product?.


What is the rule to calculate a dot product?

The dot product of two vectors is commutative and distributive, and can be calculated as |x| |y| cos θ, where θ is the angle between them. It measures the magnitude of their projection and is zero if the vectors are orthogonal.


Can a dot product be negative?

Yes, the dot product can be negative. A negative dot product indicates that the vectors are pointing in opposite directions or at an angle greater than 90 degrees.


What is the difference between cross product and dot product?

The dot product yields a scalar that measures how much one vector projects onto another, while the cross product yields a vector that is perpendicular to both input vectors. To learn more about their comparison, please look have a look here: Dot product vs. cross product of two vectors.


Why is dot product scalar?

The dot product is scalar because it measures how much two vectors align, combining their magnitudes and the cosine of the angle between them into a single number. To learn more about scaler vs. vector, please look into this: Scalar vs. vector


Can a dot product be 1?

Yes, a dot product can be 1 if two unit vectors (vectors with a magnitude of 1) are perfectly aligned in the same direction. This happens when the angle between them is , making cos0° = 1.


When will the dot product zero?

If two vectors are perpendicular, their dot product is zero.


Free Resources

Copyright ©2024 Educative, Inc. All rights reserved