gives the n×n Hilbert matrix with elements of the form
.
HilbertMatrix[{m,n}]
gives the m×n Hilbert matrix.
HilbertMatrix
gives the n×n Hilbert matrix with elements of the form
.
HilbertMatrix[{m,n}]
gives the m×n Hilbert matrix.
Details and Options
- HilbertMatrix[n] or HilbertMatrix[{m,n}] gives a matrix with exact rational entries.
- The following options can be given:
-
TargetStructure Automatic the structure of the returned matrix WorkingPrecision Infinity precision at which to create entries - Possible settings for TargetStructure include:
-
Automatic automatically choose the representation returned "Dense" represent the matrix as a dense matrix "Cauchy" represent the matrix as a Cauchy matrix "Hankel" represent the matrix as a Hankel matrix "Hermitian" represent the matrix as a Hermitian matrix "Symmetric" represent the matrix as a symmetric matrix - HilbertMatrix[…,TargetStructureAutomatic] is equivalent to HilbertMatrix[…,TargetStructure"Dense"].
Examples
open all close allBasic Examples (2)
Scope (2)
Options (2)
TargetStructure (1)
Return the Hilbert matrix as a dense matrix:
HilbertMatrix[4, TargetStructure -> "Dense"]Return the Hilbert matrix as a Cauchy matrix:
HilbertMatrix[4, TargetStructure -> "Cauchy"]Return the Hilbert matrix as a Hankel matrix:
HilbertMatrix[4, TargetStructure -> "Hankel"]Applications (2)
Hilbert matrices are often used to compare numerical algorithms:
h = HilbertMatrix[12, WorkingPrecision -> MachinePrecision];Compare methods for solving
for known
:
x = ConstantArray[1, {12}];
b = h.x;xi = Inverse[h].bSolve using LinearSolve with Gaussian elimination:
xge = LinearSolve[h, b]Solve using LinearSolve using a Cholesky decomposition:
xch = LinearSolve[h, b, Method -> "Cholesky"]Solve using LeastSquares:
xsvd = LeastSquares[h, b]Map[Norm, {x - xi, x - xge, x - xch, x - xsvd}]An expression for the Legendre polynomial in terms of the Hilbert matrix:
myLegendre[n_, x_] := (-1)^nBinomial[2n, n]FromDigits[Prepend[Reverse[LinearSolve[HilbertMatrix[n], -(1/Range[n + 1, 2n])]], 1], (1 - x/2)]Verify the expression for the first few cases:
Table[myLegendre[n, x] == LegendreP[n, x]//Simplify, {n, 20}]Properties & Relations (5)
Square Hilbert matrices are real symmetric and positive definite:
h = HilbertMatrix[RandomInteger[{1, 99}]];HermitianMatrixQ[h]MatrixQ[h, NumberQ[#] && !MatchQ[#, _Complex]&]PositiveDefiniteMatrixQ[h]Hilbert matrices can be expressed in terms of HankelMatrix:
hilbert[n_] := HankelMatrix[1 / Range[n], 1 / Range[n, 2n - 1]]Compare with HilbertMatrix:
Table[hilbert[n] == HilbertMatrix[n], {n, 2, 5}]Hilbert matrices can be expressed in terms of CauchyMatrix:
hilbert[n_] := CauchyMatrix[Range[n], Range[0, n - 1]]Compare with HilbertMatrix:
Table[hilbert[n] == HilbertMatrix[n], {n, 2, 5}]The smallest eigenvalue of a square Hilbert matrix decreases exponentially with n:
evs = Flatten[Table[Eigenvalues[HilbertMatrix[n, WorkingPrecision -> 2 n + 20], -1], {n, 32}]];ListLogPlot[evs]fit[n_] = Exp[Fit[Log[evs], {1, n}, n]] /. Exp[a_ + b_] :> Exp[N[a]] Exp[N[b]]The model is a reasonable predictor of magnitude for larger values of n:
RealExponent[fit[100]]RealExponent[Eigenvalues[HilbertMatrix[100, WorkingPrecision -> 200], -1]]The condition number increases exponentially with n:
capprox[n_] = 2 / (79.9534 E^-3.44211 n)The 2-norm condition number is the ratio of largest to smallest eigenvalue due to symmetry:
cnos = Table[Apply[Divide, Eigenvalues[HilbertMatrix[n, WorkingPrecision -> 2n + 20]][[{1, -1}]]], {n, 32}];Show[ListLogPlot[cnos], LogPlot[capprox[n], {n, 1, 32}]]Neat Examples (4)
The determinant of the Hilbert matrix can be expressed in terms of the Barnes G-function:
hilbertDet[n_] := BarnesG[n + 1] ^ 4 / BarnesG[2 n + 1]Verify the formula for the first few cases:
Table[hilbertDet[n] == Det[HilbertMatrix[n]], {n, 2, 9}]A function for computing the inverse of the Hilbert matrix:
hilbertInverse[n_] := Table[(-1) ^ (j + k) j k Binomial[n, j] Binomial[n, k] Binomial[n + j - 1, n] Binomial[n + k - 1, n] / (j + k - 1), {j, n}, {k, n}]Verify the inverse for the first few cases:
Table[hilbertInverse[n].HilbertMatrix[n] == IdentityMatrix[n], {n, 2, 9}]A function for computing the Cholesky decomposition of the Hilbert matrix:
hilbertCholesky[n_] := Table[Sqrt[2 j - 1] Binomial[2 k - 1, k - j] / ((2 k - 1) Binomial[2 k - 2, k - 1]), {j, n}, {k, n}]Verify the Cholesky decomposition for the first few cases:
Table[hilbertCholesky[n] == CholeskyDecomposition[HilbertMatrix[n]], {n, 2, 9}]Visualize the decay of the entries of the Hilbert matrix:
ListPlot3D[HilbertMatrix[10], InterpolationOrder -> 0, Mesh -> None]Related Guides
Text
Wolfram Research (2007), HilbertMatrix, Wolfram Language function, https://reference.wolfram.com/language/ref/HilbertMatrix.html (updated 2023).
CMS
Wolfram Language. 2007. "HilbertMatrix." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/HilbertMatrix.html.
APA
Wolfram Language. (2007). HilbertMatrix. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/HilbertMatrix.html
BibTeX
@misc{reference.wolfram_2026_hilbertmatrix, author="Wolfram Research", title="{HilbertMatrix}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/HilbertMatrix.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_hilbertmatrix, organization={Wolfram Research}, title={HilbertMatrix}, year={2023}, url={https://reference.wolfram.com/language/ref/HilbertMatrix.html}, note=[Accessed: 13-June-2026]}