acalculator

What do my vectors add up to?

Type the components of two vectors A and B and a number k. The vector calculator works out A + B, A − B, k·A, both lengths, the dot product, the angle between them, the unit vector of A, and in 3D the cross product.

Your numbers

Vectors in
A + B
⟨2, 8, 2⟩

A + B = ⟨2, 8, 2⟩, and A · B = 12.

A − B
⟨4, 2, 2⟩
k·A
⟨6, 10, 4⟩
|A|
6.1644
|B|
3.1623
A · B
12
Angle between A and B (°)
52.0054
Unit vector of A
⟨0.4866642634, 0.8111071057, 0.3244428423⟩
A × B
⟨-6, -2, 14⟩

A + B: ⟨2, 8, 2⟩. A + B = ⟨2, 8, 2⟩, and A · B = 12.

How to calculate

Adds, subtracts and scales 2D or 3D vectors, and finds their lengths, dot product, the angle between them, the unit vector and the cross product.

Example with the default inputs (Vectors in 3D, A: x 3, A: y 5, A: z 2, B: x -1, B: y 3, B: z 0, Scalar k 2): A + B = ⟨2, 8, 2⟩, and A · B = 12.

Method: A ± B = ⟨a₁ ± b₁, a₂ ± b₂, a₃ ± b₃⟩; k·A = ⟨ka₁, ka₂, ka₃⟩; |A| = √(a₁² + a₂² + a₃²); A · B = a₁b₁ + a₂b₂ + a₃b₃; cos θ = A · B ÷ (|A| |B|); A × B = ⟨a₂b₃ − a₃b₂, a₃b₁ − a₁b₃, a₁b₂ − a₂b₁⟩.

  • The vectors have real components in the usual x, y (and z) directions; 2D vectors leave out z.
  • There is no angle and no unit vector for a zero vector, which has no direction.

Machine-readable copies: Markdown, JSON.

Worked examples

Each example is checked against the calculator on every build.

  1. Vectors in 3D, A: x 3, A: y 5, A: z 2, B: x -1, B: y 3, B: z 0, Scalar k 2 gives A · B 12, A + B ⟨2, 8, 2⟩, A − B ⟨4, 2, 2⟩, k·A ⟨6, 10, 4⟩, A × B ⟨-6, -2, 14⟩, |A| 6.164414, |B| 3.162278.Source: OpenStax, Calculus Volume 3, §2.3 The Dot Product (Example 2.21: u · v = 12), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product; for the sum, difference, k·A and cross product (§2.4, https://openstax.org/books/calculus-volume-3/pages/2-4-the-cross-product)
  2. Vectors in 3D, A: x 2, A: y 5, A: z 6, B: x -2, B: y -4, B: z 4, Scalar k 1 gives A · B 0, Angle between A and B (°) 90.Source: OpenStax, Calculus Volume 3, §2.3 The Dot Product (Example 2.23: cos θ = 0, θ = 90°), https://openstax.org/books/calculus-volume-3/pages/2-3-the-dot-product
  3. Vectors in 2D, A: x 1, A: y 2, B: x 3, B: y 4, Scalar k -1 gives |A| 2.236068, Unit vector of A ⟨0.4472135955, 0.894427191⟩, A + B ⟨4, 6⟩, k·A ⟨-1, -2⟩, A · B 11, |B| 5, Angle between A and B (°) 10.304846.Source: OpenStax, Calculus Volume 3, §2.1 Vectors in the Plane (Example 2.7), https://openstax.org/books/calculus-volume-3/pages/2-1-vectors-in-the-plane
  4. Vectors in 2D, A: x 0.1, A: y 0.2, B: x 0.2, B: y 0.1, Scalar k 3 gives A + B ⟨0.3, 0.3⟩, A · B 0.04, k·A ⟨0.3, 0.6⟩.Source: OpenStax, Calculus Volume 3, §2.1 Vectors in the Plane, https://openstax.org/books/calculus-volume-3/pages/2-1-vectors-in-the-plane

How it works

Let A = ⟨a₁, a₂, a₃⟩ and B = ⟨b₁, b₂, b₃⟩ (in 2D, leave out the third component), and k a number.

  • Sum and difference: A ± B = ⟨a₁ ± b₁, a₂ ± b₂, a₃ ± b₃⟩.
  • Scalar multiple: k·A = ⟨ka₁, ka₂, ka₃⟩.
  • Length: |A| = √(a₁² + a₂² + a₃²), and the same for |B|.
  • Dot product: A · B = a₁b₁ + a₂b₂ + a₃b₃.
  • Angle: θ = arccos(A · B ÷ (|A| |B|)) in degrees, from 0° to 180°. The page finds the cosine as sign(A · B) × √((A · B)² ÷ (|A|² |B|²)), with the fraction under the root exact, so very small or very large components do not underflow or overflow; it is clamped to 1. There is no angle when A or B is the zero vector.
  • Unit vector of A: A ÷ |A|. Each component is found as sign(aᵢ) × √(aᵢ² ÷ |A|²), with the fraction exact; none for the zero vector.
  • Cross product (3D only): A × B = ⟨a₂b₃ − a₃b₂, a₃b₁ − a₁b₃, a₁b₂ − a₂b₁⟩.

Rules. Every component and k is from −1,000,000,000 to 1,000,000,000.

Exact arithmetic. Each typed number is read as its exact decimal (0.1 is 1/10), so sums, differences, k·A, the dot product, the cross product and the squared lengths are exact fractions. A length is exact when its square is the square of a fraction (√25 = 5), and otherwise a double-precision square root; the angle and the unit vector are floats.

Output format. Vectors are text such as ⟨2, 8, 2⟩, each component rounded to 10 significant figures with a plain hyphen for minus and no thousands separators. Lengths, the dot product and the angle show at most 4 decimals, rounded half up.

Worked examples by hand

A = ⟨3, 5, 2⟩, B = ⟨−1, 3, 0⟩, k = 2 (OpenStax Example 2.21). A + B = ⟨2, 8, 2⟩; A − B = ⟨4, 2, 2⟩; 2A = ⟨6, 10, 4⟩. A · B = −3 + 15 + 0 = 12. |A| = √38 = 6.1644; |B| = √10 = 3.1623. A × B = ⟨5·0 − 2·3, 2·(−1) − 3·0, 3·3 − 5·(−1)⟩ = ⟨−6, −2, 14⟩.

A = ⟨2, 5, 6⟩, B = ⟨−2, −4, 4⟩ (OpenStax Example 2.23). A · B = −4 − 20 + 24 = 0, so cos θ = 0 and θ = 90°.

A = ⟨1, 2⟩, B = ⟨3, 4⟩, k = −1 (2D; OpenStax Example 2.7). |A| = √5 = 2.2361; unit vector ⟨0.4472135955, 0.894427191⟩. A + B = ⟨4, 6⟩; −A = ⟨−1, −2⟩. A · B = 3 + 8 = 11; |B| = 5; cos θ = 11 ÷ (5√5) = 0.98387, θ = 10.3048°.

A = ⟨0.1, 0.2⟩, B = ⟨0.2, 0.1⟩, k = 3. A + B = ⟨0.3, 0.3⟩; A · B = 0.02 + 0.02 = 0.04; 3A = ⟨0.3, 0.6⟩.

Other questions people ask

How do I add two vectors?

Add the matching components. ⟨3, 5, 2⟩ + ⟨−1, 3, 0⟩ = ⟨3 − 1, 5 + 3, 2 + 0⟩ = ⟨2, 8, 2⟩. Subtraction works the same way, component by component.

How do I find the length (magnitude) of a vector?

Square each component, add them, and take the square root. |⟨3, 5, 2⟩| = √(9 + 25 + 4) = √38 ≈ 6.1644.

How do I find the angle between two vectors?

Divide the dot product by the product of the lengths to get cos θ, then take the inverse cosine. For ⟨2, 5, 6⟩ and ⟨−2, −4, 4⟩ the dot product is 0, so the angle is 90°.

What is a unit vector?

A vector of length 1 that points the same way. Divide the vector by its length: ⟨1, 2⟩ has length √5, so its unit vector is ⟨1/√5, 2/√5⟩ ≈ ⟨0.4472, 0.8944⟩.

Why is there no cross product for 2D vectors?

The cross product is defined for vectors in 3D: it is the vector at right angles to both. Pick 3D and give z = 0 to treat 2D vectors as flat 3D vectors; the cross product then points along z.

What if one vector is zero?

A zero vector has length 0 and no direction, so the page leaves out the angle and, for A, the unit vector. The sum, difference and dot product still work.