Orthogonal projection onto a subspace: what this calculator does
This calculator computes the orthogonal projection of a vector onto a subspace spanned by up to three basis vectors. It also lets you see the connection to the standard projection matrix formula used in linear algebra, least squares, and numerical methods.
You enter the components of and up to three basis vectors . The tool then:
- Forms the matrix whose columns are the basis vectors.
- Builds the associated projection matrix.
- Computes the projected vector in the subspace.
- Computes the orthogonal component .
This is useful for visualizing projections in , checking homework, and understanding how least squares and Gram–Schmidt orthogonalization work under the hood.
How orthogonal projection works (formulas)
Let be a subspace of spanned by linearly independent vectors
with . Stack these basis vectors as columns in a matrix
The orthogonal projection matrix onto the column space of is
Here:
- is the transpose of .
- is the Gram matrix, whose entries are inner products .
- is the inverse of the Gram matrix (it exists only if the basis vectors are linearly independent).
- is a matrix that sends any to its projection in the subspace.
At the vector level, you can also think of the projection as follows. We look for coefficients such that
is the closest vector in the subspace to in the Euclidean norm. Solving the normal equations
gives
In MathML form, the projection matrix formula can be written as:
The matrix has two key properties that characterize orthogonal projection:
- Idempotent: . Applying the projection twice does nothing new.
- Symmetric: . This symmetry encodes orthogonality of the residual.
The residual (or error) vector is
and it satisfies , meaning it is orthogonal to every vector in the subspace.
Interpreting the results
When you use the calculator, you will typically see at least two key outputs:
- Projected vector : the shadow of on the chosen subspace.
- Orthogonal component : the part of that lies outside the subspace.
Geometrically, the projection is the point in the subspace that is closest to in Euclidean distance. The vector is perpendicular to the entire subspace, not just to one basis vector.
Numerically, you might also inspect:
- The length (norm) of , which tells you how large the component of inside the subspace is.
- The length of , which is the distance from to the subspace.
If the subspace is a line (one basis vector), the projection is just the component of along that line. If the subspace is a plane (two independent basis vectors), the projection is the point in the plane obtained by dropping a perpendicular from to the plane.
Worked example in
Consider and the subspace spanned by
and . This subspace is the -plane.
The matrix of basis vectors is
Then
The projection matrix is
Applying to gives
So the projection of onto the -plane is . The orthogonal component is
which points straight along the -axis. Geometrically, this corresponds to dropping a perpendicular from the point onto the -plane.
The calculator reproduces this example if you enter , set
, , and either leave or at its default value representing the -axis.
Comparison: single vector vs. subspace projection
Projecting onto a single vector is a special case of projection onto a subspace. The formulas simplify when there is only one basis vector, but the geometric idea is the same.
| Case |
Setup |
Projection formula |
Typical use |
| Projection onto a single vector |
Subspace is span of one nonzero vector . |
|
Decomposing motion along a direction, resolving forces, simple geometry. |
| Projection onto a subspace |
Subspace is span of independent vectors, collected as columns of . |
|
Least squares, regression, dimensionality reduction, numerical linear algebra. |
This calculator always uses the general subspace formula, so it works for both situations: if you only want to project onto a single direction, just provide one nonzero basis vector and leave the others at zero.
Limitations and assumptions of this calculator
The tool is designed to be simple and numerically stable for common educational and applied use cases. It makes several assumptions you should be aware of:
-
Dimension fixed to :
all vectors are three-dimensional. The calculator does not handle higher or lower dimensions.
-
Up to three basis vectors:
you can enter between one and three basis vectors. To work with a line, enter one nonzero basis vector; for a plane, enter two linearly independent basis vectors; for itself, enter three independent vectors.
-
Linear independence required:
the basis vectors you provide must be linearly independent for the Gram matrix to be invertible. If they are dependent (for example, one is a multiple of another), the calculator cannot form and will report an error instead of a projection.
-
Zero or unused vectors:
if you leave a basis vector as all zeros, it contributes nothing to the span. Use this to indicate that your subspace has lower dimension (for example, one or two active basis vectors instead of three).
-
Floating-point arithmetic:
computations are carried out numerically. If is very close to singular, small rounding errors may lead to large changes in the result. In such borderline cases the calculator may display a warning or treat the matrix as singular.
-
Euclidean inner product:
the projection is always with respect to the standard dot product on . Weighted inner products or non-Euclidean geometries are not supported.
Being aware of these conditions will help you interpret the output correctly and avoid relying on the tool in cases it is not designed to handle.
Connections and applications
Orthogonal projection is more than a geometric curiosity. It underlies several core techniques:
-
Least squares and regression:
solving an overdetermined system by least squares is equivalent to projecting onto the column space of . The residual is orthogonal to that column space.
-
Gram–Schmidt orthogonalization:
building an orthonormal basis from arbitrary vectors uses repeated projection and subtraction of orthogonal components.
-
Data analysis and dimension reduction:
in methods like principal component analysis (PCA), data is projected onto lower-dimensional subspaces capturing the most variance.
-
Computer graphics and geometry:
projecting 3D points onto planes or lines is fundamental for rendering, collision detection, and camera transformations.
The same matrix formula implemented by this calculator is used implicitly in these applications, often at a much larger scale. Working with concrete three-dimensional examples can make these abstract ideas more tangible.