MathsLinear Algebra

Vector
calculator.

Add, scale and multiply 2D or 3D vectors, and find lengths, unit vectors and angles.

How it's worked out

A vector is written by its components, one number per axis, such as ⟨3, 1⟩ in 2D or ⟨2, 2, −1⟩ in 3D. Adding vectors and multiplying by a scalar work one component at a time. A scalar is a plain number k, and kA stretches A by the size of k, flipping it when k is negative.

A+B\displaystyle A + B=⟨a1+b1, a2+b2⟩\displaystyle {}= \langle a_1 + b_1,\ a_2 + b_2 \rangle

The length, or magnitude, comes from the Pythagorean theorem. A unit vector has length 1; you get one by dividing each component by the length, which is called normalizing.

|A|\displaystyle |A|=a12+a22+a32\displaystyle {}= \sqrt{a_1^2 + a_2^2 + a_3^2}
Aˆ\displaystyle \hat{A}=A|A|\displaystyle {}= \frac{A}{|A|}

The dot product multiplies matching components and adds the results, so it gives a number, not a vector. It also equals the two lengths times the cosine of the angle between them, which is how the tool finds the angle.

A⋅B\displaystyle A \cdot B=a1b1+a2b2+a3b3\displaystyle {}= a_1 b_1 + a_2 b_2 + a_3 b_3
cos⁡θ\displaystyle \cos\theta=A⋅B|A||B|\displaystyle {}= \frac{A \cdot B}{|A|\,|B|}

The cross product needs three components. It gives a vector at right angles to both A and B, and its length is the area of the parallelogram the two vectors span. For the angle, the tool uses the dot product and the length of the cross product together, which stays accurate when the two vectors point almost the same way.

Worked examples

Sam adds two pulls on a crate

Sam pulls a crate with 30 N toward the east while a friend pulls with 40 N toward the north. With east as x and north as y, the pulls are two vectors.

⟨30,0⟩+⟨0,40⟩\displaystyle \langle 30, 0 \rangle + \langle 0, 40 \rangle=⟨30,40⟩\displaystyle {}= \langle 30, 40 \rangle

The total pull is ⟨30, 40⟩ newtons. Its length is 50 N, not the 70 N you get by adding the two sizes, because the pulls are at right angles. It points 53.1° north of east, the angle between the total and the x axis.

Open this example in the tool

Is one direction at right angles to another?

A level designer wants a wall at right angles to a path that runs along ⟨2, 3⟩. She tries the direction ⟨−3, 2⟩, made by swapping the components and changing one sign.

⟨2,3⟩⋅⟨−3,2⟩\displaystyle \langle 2, 3 \rangle \cdot \langle -3, 2 \rangle=2×(−3)+3×2\displaystyle {}= 2 \times (-3) + 3 \times 2=0\displaystyle {}= 0

Two vectors that are not zero are orthogonal exactly when their dot product is 0, and here it is 0. So the angle is 90°, and the wall is square to the path.

Open this example in the tool

The angle between two 3D vectors

For ⟨2, 2, −1⟩ and ⟨5, −3, 2⟩ the dot product is 2. The lengths are 3 and √38, so the cosine is small.

cos⁡θ\displaystyle \cos\theta=2338\displaystyle {}= \frac{2}{3\sqrt{38}}=3857\displaystyle {}= \frac{\sqrt{38}}{57}

That is about 0.1081, so θ is 83.79°, a little under a right angle. The exact view keeps the cosine as a root over a whole number until the last step.

Open this example in the tool

Reading your result

The sign of the dot product. Positive means the angle is under 90°, zero means a right angle, and negative means over 90°. For ⟨1, 0⟩ and ⟨−1, 1⟩ the dot product is -1 and the angle is 135°.

Angles run from 0° to 180°. The angle between two vectors has no direction of turn, so it never goes past 180°. An angle of 0° means the vectors point the same way, and 180° means opposite ways.

A unit vector keeps only direction. ⟨3, 4⟩ has length 5, so its unit vector is ⟨0.6, 0.8⟩. The zero vector is the only vector without a direction, so it has no unit vector and no angle with anything.

The cross product has an order. ⟨1, 2, 3⟩ × ⟨4, 5, 6⟩ is ⟨−3, 6, −3⟩, while the other order gives ⟨3, −6, 3⟩. The two point in opposite directions with the same length.

Common mistakes

  • Adding the sizes instead of the components. Two pulls of 30 N and 40 N at right angles give 50 N in total, not 70 N. Lengths add only when the vectors point the same way.
  • Reading the dot product as a vector. A · B is one number. If your answer has components, you worked out something else, such as a sum or a cross product.
  • Using a calculator set to the wrong angle unit. The inverse cosine of the same number gives degrees or radians depending on the setting. The tool lets you pick either, so match what your course uses.
  • Trying a cross product in 2D. Put the vectors in 3D with a third component of 0 instead. The result then points straight along the z axis.

Questions people ask

It means the angle between the two vectors is more than 90°, so they point broadly away from each other. The cosine of an obtuse angle is negative, and the dot product is the lengths times that cosine. A negative result is not an error.

Sources