Vector Calculator

Vector Calculator a & b

Enter two vectors as comma or space separated numbers (2D like 3 4 or 3D like 1 2 2). You get the sum, difference, dot product, magnitudes, the angle between them, the cross product for 3D — plus a live plane diagram for 2D, the steps, and the NumPy code.

Examples:

This free vector calculator takes two vectors — in 2D or 3D — and instantly returns their sum, difference, dot product, individual magnitudes, the angle between them, and the cross product when the vectors are three-dimensional. For 2D inputs it also draws the vectors on a plane so you can see the parallelogram rule at work, then shows every step and the matching NumPy code. Type your components above, press Compute, and you get the full picture rather than just a single number.

What a vector calculator does

A vector is an ordered list of numbers that carries both a magnitude and a direction. In two dimensions a vector like [3, 4] points from the origin to the coordinate (3, 4); in three dimensions [1, 2, 2] reaches into space. A vector calculator performs the standard operations of vector algebra on your inputs so you do not have to grind through the arithmetic by hand. Addition and subtraction combine two vectors componentwise; the dot product collapses them into a single scalar; the magnitude measures a vector's length; the angle tells you how far apart two directions point; and the cross product produces a new vector perpendicular to both. These operations are the vocabulary of linear algebra, physics, computer graphics, and machine learning, and this tool computes all of them at once so you can check your work or build intuition quickly.

Every result here is produced in your browser from the numbers you type. Nothing is uploaded, and the diagram, steps, and NumPy snippet update the moment you change a value or switch the decimal setting.

How to use the vector calculator

  1. Type Vector a and Vector b as comma or space separated numbers. Use two components for a 2D vector (3 4) or three for a 3D vector (1 2 2).
  2. Make sure both vectors have the same dimension. Mixing a 2D vector with a 3D vector is undefined, and the calculator will tell you so.
  3. Press Compute. The stat tiles fill in with the sum, difference, dot product, magnitudes, and angle. If both vectors are 3D, a cross-product tile appears as well.
  4. For 2D inputs, read the plane diagram: vector a is indigo, vector b is violet, and their sum a + b is the green dashed arrow completing the parallelogram.
  5. Use the Decimals selector to switch between automatic precision and a fixed 0, 2, or 4 places, and press Copy result to grab a one-line summary.

The example chips are the fastest way to explore: 2D loads a classic 3-4-5 style pair, 3D shows a cross product in action, Perpendicular demonstrates a 90-degree angle and a zero dot product, and Random throws two fresh 2D vectors at the plane.

A worked example

Take a = [3, 4] and b = [1, 2]. Adding componentwise gives a + b = [4, 6], and subtracting gives a − b = [2, 2]. The dot product is 3×1 + 4×2 = 3 + 8 = 11. The magnitude of a is √(3² + 4²) = √25 = 5, and the magnitude of b is √(1² + 2²) = √5 ≈ 2.236. The angle between them is acos(11 / (5 × 2.236)) = acos(0.9839) ≈ 10.30° — a small angle, which makes sense because both vectors point up and to the right in roughly the same direction. This is exactly what the calculator reports when you load the 2D example.

The formulas

Addition and subtraction work one component at a time. For two vectors the sum is a + b = [a1+b1, a2+b2, ...] and the difference flips the sign on b. Geometrically, addition places b's tail at a's head; the result is the diagonal of the parallelogram the two vectors span, which is why the diagram draws those faint parallel sides.

The dot product multiplies matching components and sums them: a·b = Σ aibi. The result is a single number, not a vector. A positive dot product means the vectors point in broadly the same direction, zero means they are perpendicular, and a negative value means they point apart.

The magnitude (or length, or Euclidean norm) of a vector is the square root of the sum of its squared components: |a| = √(Σ ai²). It is a direct application of the Pythagorean theorem generalised to any number of dimensions.

The angle between two vectors follows from the geometric form of the dot product, a·b = |a| |b| cos(θ). Rearranged, θ = acos( a·b / (|a| |b|) ). The calculator clamps the ratio to the range −1 to 1 before taking the inverse cosine, which guards against tiny floating-point overshoots that would otherwise return NaN. If either vector has zero length, the angle is undefined, because a zero vector has no direction.

The cross product is defined for 3D vectors only and returns a new vector perpendicular to both inputs: a×b = [a2b3−a3b2, a3b1−a1b3, a1b2−a2b1]. Its length equals the area of the parallelogram the two vectors span, and its direction follows the right-hand rule. When both inputs are 2D there is no cross product in the usual sense, so the calculator omits that tile.

Common mistake
The dot product returns a scalar and the cross product returns a vector — they are not interchangeable. Do not try to take a cross product of 2D vectors, and remember that vector addition requires matching dimensions: you cannot add a 2D vector to a 3D one. Another frequent slip is forgetting to clamp the cosine ratio before calling acos; floating-point rounding can push it just past 1 and produce an invalid angle.

Vectors in Python with NumPy

In real work you will handle vectors in code, and NumPy makes every operation on this page a one-liner:

import numpy as np
a = np.array([3, 4])
b = np.array([1, 2])
print(np.add(a, b)) # a + b
print(np.subtract(a, b)) # a - b
print(np.dot(a, b)) # dot product
print(np.linalg.norm(a)) # |a|
print(np.linalg.norm(b)) # |b|
cos = np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
print(np.degrees(np.arccos(np.clip(cos, -1, 1)))) # angle in degrees
# cross product needs 3D vectors:
print(np.cross([1, 2, 2], [2, 0, 1]))

The calculator returns the same values that numpy.add, numpy.dot, numpy.linalg.norm, and numpy.cross produce, so you can prototype here and reproduce the results in code with confidence. Note the np.clip call in the angle line — it plays the same protective role as the clamp inside this tool.

Where vectors show up in machine learning

Vectors are the fundamental data structure of machine learning. Every training example is usually a feature vector, and models operate on those vectors with exactly the operations on this page. The dot product is the single most important one: a linear model computes a weighted sum of features, which is just the dot product of a weight vector and a feature vector, and a neural network layer is a stack of such dot products. Vector magnitude appears whenever you normalise features or measure the size of a gradient. The angle between vectors, expressed through cosine similarity (the same a·b / (|a| |b|) ratio the angle uses), drives recommendation systems, semantic search, and the nearest-neighbour lookups behind modern embedding models. Even the cross product turns up in graphics and robotics pipelines that feed data into learning systems. Understanding these operations by hand makes the linear-algebra notation in papers and frameworks far less intimidating.

Frequently asked questions

Can this calculator handle 3D vectors?

Yes. Enter three components for each vector, such as 1 2 2 and 2 0 1, and the tool computes the sum, difference, dot product, magnitudes, angle, and the cross product. The plane diagram is drawn only for 2D vectors, but every numeric result works in 3D.

Why do both vectors need the same dimension?

Addition, subtraction, and the dot product pair up matching components, so the vectors must have the same number of them. Adding a 2D vector to a 3D vector has no defined meaning, and the calculator flags it rather than guessing.

What does an undefined angle mean?

The angle is computed from the directions of the two vectors. A zero vector — all components zero — has no direction, so the angle involving it is undefined. The calculator reports this instead of dividing by zero.

Is the cross product available for 2D vectors?

No. The standard cross product is defined only in three dimensions, where it returns a vector perpendicular to both inputs. For 2D vectors the calculator simply omits the cross-product tile.

Are the results the same as NumPy?

Yes. The sum, difference, dot product, magnitudes, angle, and cross product match numpy.add, numpy.dot, numpy.linalg.norm, and numpy.cross exactly, because they use the same definitions.

Related calculators

Explore the full linear algebra calculators hub, or dig deeper with the dot product calculator, the vector magnitude calculator, and the cross product calculator.