Orthogonalize[{v1,v2,…}]
gives an orthonormal basis found by orthogonalizing the vectors vi.
Orthogonalize[{e1,e2,…},f]
gives an orthonormal basis found by orthogonalizing the elements ei with respect to the inner product function f.
Orthogonalize
Orthogonalize[{v1,v2,…}]
gives an orthonormal basis found by orthogonalizing the vectors vi.
Orthogonalize[{e1,e2,…},f]
gives an orthonormal basis found by orthogonalizing the elements ei with respect to the inner product function f.
Details and Options
- Orthogonalize[{v1,v2,…}] uses the ordinary scalar product
as an inner product. - The output from Orthogonalize always contains the same number of vectors as the input. If some of the input vectors are not linearly independent, the output will contain zero vectors.
- All nonzero vectors in the output are normalized to unit length.
- The inner product function f is applied to pairs of linear combinations of the ei.
- The ei can be any expressions for which f always yields real results. »
- Orthogonalize[{v1,v2,…},Dot] effectively assumes that all elements of the vi are real. »
- Orthogonalize by default generates a Gram–Schmidt basis.
- Other bases can be obtained by giving alternative settings for the Method option. Possible settings include: "GramSchmidt", "ModifiedGramSchmidt", "Reorthogonalization", and "Householder".
- Orthogonalize[list,Tolerance->t] sets to zero elements whose relative norm falls below t.
Examples
open all close allBasic Examples (3)
Find an orthonormal basis for the span of two 3D vectors:
Orthogonalize[{{1, 0, 1}, {1, 1, 1}}]Construct an orthonormal basis from three 3D vectors:
{Subscript[v, 1], Subscript[v, 2], Subscript[v, 3]} = Orthogonalize[{{8, 1, 8}, {8, 1, 4}, {6, 0, 5}}]Confirm the result is orthonormal:
{Subscript[v, 1].Subscript[v, 1], Subscript[v, 2].Subscript[v, 2], Subscript[v, 3].Subscript[v, 3]}{Subscript[v, 1].Subscript[v, 2], Subscript[v, 1].Subscript[v, 3], Subscript[v, 2].Subscript[v, 3]}Orthogonalize vectors containing symbolic entries:
Orthogonalize[{{a, 0}, {1, 1}}]//FullSimplifyScope (13)
Basic Uses (6)
Orthogonalize a set of machine-precision vectors:
Orthogonalize[{{1.25, 3}, {7.9, -1.4}}]Orthogonalize complex vectors:
Orthogonalize[{{1. + I, 2., 3. - 2. I}, {0, 4., 5.I}, {1. + I, 6., 3. + 3.I}}]//MatrixFormOrthogonalize[{{2, 3}, {0, 2}, {3, 1}}]Orthogonalize arbitrary-precision vectors:
Orthogonalize[RandomReal[6, {3, 3}, WorkingPrecision -> 25]]Orthogonalize symbolic vectors:
Orthogonalize[{{1, a}, {2, b}}]Simplify the result assuming a and b are real-valued:
Simplify[%, {a, b}∈Reals]Large numerical matrices are handled efficiently:
mat = RandomReal[{3, 9}, {800, 800}];Orthogonalize[mat];//TimingSpecial Matrices (4)
Orthogonalize the rows of a sparse matrix:
SparseArray[{{1, 1} -> 3, {1, 2} -> 2, {2, 3} -> 1}, {3, 3}]Orthogonalize[%]Orthogonalize the rows of structured matrices:
SymmetrizedArray[{{1, 1} -> 2., {1, 2} -> 1}, {2, 2}, Symmetric[All]]Orthogonalize[%]QuantityArray[{{1, 2}, {3, 4}}, {"Meters", "Meters"}]Orthogonalize[%]Orthogonalizing a diagonal matrix produces another diagonal matrix:
Orthogonalize[DiagonalMatrix[{a, b, c}]]Orthogonalize HilbertMatrix:
Orthogonalize[HilbertMatrix[3]]Orthogonalize[HilbertMatrix[{3, 2}]]General Inner Products (3)
Find a symbolic basis, assuming all variables are real:
Orthogonalize[{{a, b}, {x, y}}, Dot]Orthogonalize vectors that are not lists using an explicit inner product:
ip[p1_, p2_] := Integrate[p1 p2, {x, -1, 1}]Orthogonalize[{1, x, x ^ 2, x ^ 3}, ip]Specify the inner product using a pure function:
Orthogonalize[{Exp[-x ^ 2], x Exp[-x ^ 2], x ^ 2 Exp[-x ^ 2]}, {f, g} Subsuperscript[∫, -∞, ∞]Conjugate[f]gⅆx]//FullSimplifyOptions (3)
Method (2)
m forms a set of vectors that are nearly linearly dependent:
n = 10;m = N[HilbertMatrix[n]];Deviation from orthonormality for the default method:
gs = Orthogonalize[m];Max[Abs[gs.Transpose[gs] - IdentityMatrix[n]]]Deviation for all of the methods:
methods = {"GramSchmidt", "ModifiedGramSchmidt", "Householder", "Reorthogonalization"};
TableForm[Table[{method, gs = Orthogonalize[m, Method -> method];Max[Abs[gs.Transpose[gs] - IdentityMatrix[n]]]},
{method, methods}]]For a large numerical matrix, the Householder method is usually fastest:
m = RandomReal[1, {1000, 1000}];methods = {"GramSchmidt", "ModifiedGramSchmidt", "Householder", "Reorthogonalization"};
TableForm[Table[{method, First[Timing[Orthogonalize[m, Method -> method]]]},
{method, methods}]]Applications (12)
Geometry (3)
Project the vector
on the plane spanned by the vectors
and
:
v = {1, 2, 1 / 2};
b1 = {2, 4, -2};
b2 = {-3, 3, 0};Construct an orthonormal basis that spans the same space as the
:
{e1, e2} = Orthogonalize[{b1, b2}]The projection in the plane is the sum of the projections onto
:
p = (v.e1)e1 + (v.e2)e2//SimplifyFind the component perpendicular to the plane:
v - pConfirm the result by projecting
onto the normal to the plane:
% == Projection[v, b1⨯b2]Visualize the plane, the vector and its parallel and perpendicular components:
Graphics3D[{FaceForm[Opacity[.25]], InfinitePlane[{0, 0, 0}, {b1, b2}], Arrow[{{0, 0, 0}, v}], {Directive[StandardMagenta, Thick], Arrow[{{0, 0, 0}, p}]}, Directive[Thick, Dotted], Arrow[{p, v}]}, PlotRangePadding -> 1, Axes -> True]The Frenet–Serret system encodes every space curve's properties in a vector basis and scalar functions. Consider the following curve:
c[t_] := {Cos[t], Sin[t], (t/2π)}Construct an orthonormal basis from the first three derivatives using Orthogonalize:
{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]} = Orthogonalize[{c'[t], c''[t], c'''[t]}, Dot]//SimplifyEnsure that the basis is right-handed:
Subscript[e, 3] = Simplify[Det[{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]}]]Subscript[e, 3];Compute the curvature,
, and torsion,
, which quantify how the curve bends:
{κ, τ} = {(D[Subscript[e, 1], t].Subscript[e, 2]/Sqrt[c'[t].c'[t]]), -(D[Subscript[e, 3], t].Subscript[e, 2]/Sqrt[c'[t].c'[t]])}//SimplifyVerify the answers using FrenetSerretSystem:
Simplify[{{κ, τ}, {Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]}} == FrenetSerretSystem[c[t], t], t∈Reals]Visualize the curve and the associated moving basis, also called a frame:
DynamicModule[{s}, Labeled[Show[ParametricPlot3D[c[t], {t, 0, 6π}, PlotRangePadding -> {.5, .5, .9}], Graphics3D[{StandardBlue, Arrow[{c[t], c[t] + Subscript[e, 1]}], StandardRed, Arrow[{c[t], c[t] + Subscript[e, 2]}], StandardPurple, Arrow[{c[t], c[t] + Subscript[e, 3]}]}] /. t -> Dynamic[s]], Animator[Dynamic[s], {0, 6π}], Top]]Find the orthogonal projection of the vector
onto the space spanned by the vectors
,
and
:
v = {3 - 3 I, 3, 3 + I, -2 - 2 I};First, construct an orthonormal basis for the space:
{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]} = Orthogonalize[{{2 - I, 2 - I, 1, 2 - 2 I}, {1, 1, -I, 1 - I}, {2, 1, 1 - I, 2 - 2 I}}]The component in the space is given by
:
vp = Sum[Conjugate[Subscript[e, i]].v Subscript[e, i], {i, 3}]//FullSimplifyThe difference
is perpendicular to any vector in the span of the
:
Conjugate[v - vp].Sum[C[i]Subscript[e, i], {i, 3}] == 0//FullSimplifyLeast Squares and Curve Fitting (3)
If the linear system
has no solution, the best approximate solution is the least-squares solution. That is the solution to
, where
is the orthogonal projection of
onto the column space of
. Consider the following
and
:
m = {{1, 2}, {3, -4}, {1, -1}};
b = {0, -2, 1};The linear system is inconsistent:
LinearSolve[m, b]Find an orthonormal basis for the space spanned by the columns of
:
{e1, e2} = Orthogonalize[Transpose[m]]Compute the orthogonal projection
of
onto the spaced spanned by the
:
bPerp = (e1.b)e1 + (e2.b)e2//FullSimplifyVisualize
, its projections
onto the
and
:
Graphics3D[{Thick, {StandardBlue, Arrow[{{0, 0, 0}, b}], Text[HoldForm[b], 1.05b]}, {StandardRed, Arrow[{{0, 0, 0}, bPerp}], Text[HoldForm[Superscript[b, "⟂"]], 1.1bPerp], Dashed, Arrow[{{0, 0, 0}, e1.b e1}], Text[HoldForm[Subscript[b, 1]], 1.1e1.b e1], Arrow[{{0, 0, 0}, e2.b e2}], Text[HoldForm[Subscript[b, 2]], 1.3e2.b e2]}, {StandardPurple, Dashed, Arrow[{bPerp, b}]}, Opacity[.25], InfinitePlane[{{0, 0, 0}, e1, e2}]}]LinearSolve[m, bPerp]Confirm the result using LeastSquares:
LeastSquares[m, b]Orthogonalize can be used to find a best-fit curve to data. Consider the following data:
data = IconizedObject[«Data»];
ListPlot[data]Extract the
and
coordinates from the data:
{x, y} = Extract[data, {{All, 1}, {All, 2}}];Let
have the columns
and
, so that minimizing
will be fitting to a line
:
m = Map[x |-> {1, x}, x];Get the coefficients
and
for a linear least‐squares fit:
{e1, e2} = Orthogonalize[Transpose[m]];
yPerp = (e1.y)e1 + (e2.y)e2;
{a, b} = LinearSolve[m, yPerp]Verify the coefficients using Fit:
Fit[data, {1, s}, s]Plot the best-fit curve along with the data:
Show[Plot[a + b x, {x, 0, 1}], ListPlot[data]]Find the best-fit parabola to the following data:
data = IconizedObject[«Data»];
ListPlot[data]Extract the
and
coordinates from the data:
{x, y} = Extract[data, {{All, 1}, {All, 2}}];Let
have the columns
,
and
, so that minimizing
will be fitting to
:
m = Map[x |-> {1, x, x ^ 2}, x];Construct orthonormal vectors
that have the same column space as
:
{e1, e2, e3} = Orthogonalize[{ConstantArray[1, Length[data]], x, x ^ 2}];Get the coefficients
,
and
for a least‐squares fit:
yPerp = Projection[y, e1] + Projection[y, e2] + Projection[y, e3];
{a, b, c} = LinearSolve[m, yPerp]Verify the coefficients using Fit:
Fit[data, {1, s, s ^ 2}, s]Plot the best-fit curve along with the data:
Show[Plot[a + b x + c x ^ 2, {x, 0, 3}], ListPlot[data]]Matrix Decompositions (2)
Find an orthonormal basis for the column space of the following matrix
, and then use that basis to find a QR factorization of
:
a = (| | | |
| -- | -- | -- |
| 1 | 3 | 7 |
| -1 | 2 | -3 |
| -1 | 2 | -9 |
| 1 | -4 | 7 |
| 1 | 2 | 1 |);Apply Gram–Schmidt to the columns of
, then define
as the matrix whose columns are those vectors:
(Q = Transpose[Orthogonalize[Transpose[a]]])//MatrixForm(R = Transpose[Q].a)//MatrixFormQ.R == aCompare with the result given by QRDecomposition; the
matrices are the same:
{q, r} = QRDecomposition[a];
r == RThe
matrices differ by a transposition because QRDecomposition gives the row-orthonormal result:
q == Transpose[Q]For a Hermitian matrix (more generally, any normal matrix), the eigenvectors are orthogonal, and it is conventional to define the projection matrices
, where
is a normalized eigenvector. Show that the action of the projection matrices on a general vector is the same as projecting the vector onto the eigenspace for the following matrix
:
(h = {{23, 3 I Sqrt[6], -3}, {-3 I Sqrt[6], 26, -I Sqrt[6]}, {-3, I Sqrt[6], 31}})//MatrixFormHermitianMatrixQ[h]Find the eigenvalues and eigenvectors:
{{Subscript[λ, 1], Subscript[λ, 2], Subscript[λ, 3]}, {Subscript[v, 1], Subscript[v, 2], Subscript[v, 3]}} = Eigensystem[h]
and
are both orthogonal to
since they come from different eigenspaces:
Conjugate[Subscript[v, 1]].Subscript[v, 3] == Conjugate[Subscript[v, 2]].Subscript[v, 3] == 0They need not and are not orthogonal to each other, since they have the same eigenvalue:
Conjugate[Subscript[v, 1]].Subscript[v, 2]Use Orthogonalize to create an orthonormal basis out of the
:
{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]} = Orthogonalize[{Subscript[v, 1], Subscript[v, 2], Subscript[v, 3]}]//FullSimplifyCompute the projection matrices:
Table[MatrixForm[Subscript[p, i] = FullSimplify[Transpose[{Subscript[e, i]}].Conjugate[{Subscript[e, i]}]]], {i, 3}]Confirm that multiplying a general vector by
equals the projection of the vector onto
:
Table[FullSimplify[Subscript[p, k].{x, y, z} == Projection[{x, y, z}, Subscript[e, k]]], {k, 3}]Since the
form an orthonormal basis, the sum of the
must be the identity matrix:
Sum[Subscript[p, k], {k, 3}]//FullSimplifyMoreover, the sum of
is the original matrix
:
Sum[Subscript[λ, k]Subscript[p, k], {k, 3}] == h//FullSimplifyGeneral Inner Products and Function Spaces (4)
A positive-definite, real symmetric matrix or metric
defines an inner product by
:
(g = {{7, 2, 0}, {2, 6, -2}, {0, -2, 5}})//MatrixFormip[u_, v_] := u.g.vBeing positive-definite means that the associated quadratic form
is positive for
:
FunctionSign[{ip[{x, y, z}, {x, y, z}], {x, y, z} != {0, 0, 0}}, {x, y, z}, StrictInequalities -> True]Note that Dot itself is the inner product associated with the identity matrix:
{u, v, w}.{x, y, z} == {u, v, w}.IdentityMatrix[3].{x, y, z}Orthogonalize the standard basis of
to find an orthonormal basis:
{Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]} = Orthogonalize[IdentityMatrix[3], ip]Confirm that this basis is orthonormal with respect to the inner product
:
Table[ip[Subscript[e, i], Subscript[e, j]], {i, 3}, {j, 3}]//SimplifyFourier series are projections onto an orthonormal basis in the inner product space
. Define the standard inner product on square-integrable functions:
ip[f_, g_] := Subsuperscript[∫, -π, π]Conjugate[f]gⅆxOrthogonalize functions of the form
in this inner product:
e = Orthogonalize[Table[Exp[I n x], {n, 3, -3, -1}], ip]
equals the symmetric Fourier coefficient corresponding to FourierParameters{0,1}:
f[x_] := x ^ 3 + 3x ^ 2 + 4 + x + 2ip[e[[2]], f[x]]Confirm using FourierCoefficient:
% == FourierCoefficient[f[x], x, 2, FourierParameters -> {0, 1}]The Fourier series is the projection of
onto the space spanned by the
:
Sum[Projection[f[x], e[[n]], ip], {n, -3, 3}]//FullSimplifyConfirm the result using FourierSeries:
% == FourierSeries[f[x], x, 3]//FullSimplifyLegendreP defines a family of orthogonal polynomials with respect to the inner product
. Orthogonalize the polynomials
for
from zero through four to compute scalar multiples of the first five Legendre polynomials:
ip[f_, g_] := Subsuperscript[∫, -1, 1]f gⅆx
Orthogonalize[Table[x ^ k, {k, 0, 4}], ip]//ExpandCompare to the conventional Legendre polynomials:
Table[LegendreP[k, x], {k, 0, 4}]For each
,
and
differ by a factor of
:
Simplify[% / %%]HermiteH defines a family of orthogonal polynomials with respect to the inner product
. Apply the unnormalized Gram–Schmidt process to the polynomials
for
from zero through four to compute scalar multiples of the first five Hermite polynomials:
ip[f_, g_] := Subsuperscript[∫, -∞, ∞]Conjugate[f] g Exp[-x^2]ⅆx
Orthogonalize[Table[x ^ k, {k, 0, 4}], ip]Compare
to the conventional Hermite polynomials:
Table[HermiteH[k, x], {k, 0, 4}]For each
,
and
differ by a constant multiple:
% / %%//SimplifyProperties & Relations (9)
For linearly independent vectors, the result is an orthonormal set:
u = Orthogonalize[RandomComplex[1 + I, {3, 3}]];
Table[Conjugate[u[[i]]].u[[j]]//Chop, {i, Length[u]}, {j, Length[u]}]This extends to any inner product:
u = Orthogonalize[{1, x, x ^ 2, x ^ 3}, {f, g} |-> Integrate[f g, {x, -1, 1}]]Outer[{f, g} |-> Integrate[f g, {x, -1, 1}], u, u]For
linearly independent
-vectors, the result is a unitary matrix:
v = (| | | |
| ------------------------------------------ | ------------------------------------------ | ------------------------------------------- |
| 0.6160672125266595 + 0.9586749100889576 I | 0.35872535784947535 + 0.9645221638753674 I | 0.13827954957926747 + 0.17817526159971364 I |
| 0.42405813464846265 + 0.0680850121536889 I | 0.3637494273180719 + 0.10505153570045755 I | 0.8236939319417382 + 0.36664921759249114 I |
| 0.9850636055989179 + 0.6597772065295842 I | 0.883592064489747 + 0.19618942800047567 I | 0.01277221199945 + 0.24899103940126932 I |);
UnitaryMatrixQ[Orthogonalize[v]]If the vectors are real-valued, the matrix is additionally orthogonal:
w = (| | | |
| ------------------- | ------------------ | ------------------ |
| 0.21803104601332235 | 0.6369834814294155 | 0.759379674824946 |
| 0.40666513791386927 | 0.7496511578289624 | 0.3639804654290877 |
| 0.5500030894933041 | 0.73343475659407 | 0.9925342488909947 |);
OrthogonalMatrixQ[Orthogonalize[w]]If input vectors are not linearly independent, the result is padded with zero vectors to a matching length:
vecs = {{1, 0, 1}, {1, 1, 1}, {2, 1, 2}};
Det[vecs]Orthogonalize[vecs]If
is the result of Orthogonalize[vecs],
is a diagonal matrix:
u = Orthogonalize[RandomReal[1, {6, 5}]];
DiagonalMatrixQ[u.ConjugateTranspose[u]]It only has ones and zeroes on the diagonal:
Diagonal[u.ConjugateTranspose[u]]Zeroes on the diagonal correspond to zero vectors in the result:
Last[u]In
dimensions, there can be at most
elements in the orthonormal basis:
Orthogonalize[{{1, 2}, {3, 1}, {6, 9}, {7, 8}}]u = %Most sets of random
-dimensional vectors are spanned by exactly
basis vectors:
Orthogonalize[RandomReal[{-1, 1}, {10, 3}]]With the default method, the first element of the basis is always a multiple of the first vector:
Orthogonalize[{{2, 3, 0}, {2, 7, 1}, {4, 5, 1}}]Orthogonalize can be implemented by repeated application of Projection and Normalize:
{Subscript[v, 1], Subscript[v, 2], Subscript[v, 3]} = RandomInteger[{0, 10}, {3, 3}];
Subscript[e, 1] = Normalize[Subscript[v, 1]];
Subscript[e, 2] = Normalize[Subscript[v, 2] - Projection[Subscript[v, 2], Subscript[e, 1]]];
Subscript[e, 3] = Normalize[Subscript[v, 3] - Projection[Subscript[v, 3], Subscript[e, 1]] - Projection[Subscript[v, 3], Subscript[e, 2]]];
Orthogonalize[{Subscript[v, 1], Subscript[v, 2], Subscript[v, 3]}] == {Subscript[e, 1], Subscript[e, 2], Subscript[e, 3]}//SimplifyOrthogonalize[m] is related to QRDecomposition[Transpose[m]]:
m = RandomReal[1, {3, 3}];q1 = Orthogonalize[m];
r1 = q1.Transpose[m];
{MatrixForm[q1], MatrixForm[Chop[r1]]}{q, r} = QRDecomposition[Transpose[m]];
{MatrixForm[q], MatrixForm[r]}See Also
OrthogonalMatrixQ UnitaryMatrixQ Projection Normalize Dot Inner QRDecomposition LinearSolve
Function Repository: FullQRDecomposition
Tech Notes
Related Guides
History
Text
Wolfram Research (2007), Orthogonalize, Wolfram Language function, https://reference.wolfram.com/language/ref/Orthogonalize.html.
CMS
Wolfram Language. 2007. "Orthogonalize." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Orthogonalize.html.
APA
Wolfram Language. (2007). Orthogonalize. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Orthogonalize.html
BibTeX
@misc{reference.wolfram_2026_orthogonalize, author="Wolfram Research", title="{Orthogonalize}", year="2007", howpublished="\url{https://reference.wolfram.com/language/ref/Orthogonalize.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_orthogonalize, organization={Wolfram Research}, title={Orthogonalize}, year={2007}, url={https://reference.wolfram.com/language/ref/Orthogonalize.html}, note=[Accessed: 12-June-2026]}