Skip to content

HilbertMatrix

Status: Stable

documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

Description

HilbertMatrix[n] gives the n x n Hilbert matrix with entries 1/(i + j - 1).
HilbertMatrix[{m, n}] gives the m x n Hilbert matrix.
Entries are exact Rationals unless the WorkingPrecision option requests MachinePrecision or a digit count.

Examples

All examples below are verified against the current Mathilda build.

In[1]:= HilbertMatrix[3]
Out[1]= {{1, 1/2, 1/3}, {1/2, 1/3, 1/4}, {1/3, 1/4, 1/5}}

In[2]:= HilbertMatrix[{3, 5}]
Out[2]= {{1, 1/2, 1/3, 1/4, 1/5}, {1/2, 1/3, 1/4, 1/5, 1/6}, {1/3, 1/4, 1/5, 1/6, 1/7}}

In[3]:= HilbertMatrix[3, WorkingPrecision -> MachinePrecision]
Out[3]= {{1.0, 0.5, 0.333333}, {0.5, 0.333333, 0.25}, {0.333333, 0.25, 0.2}}

In[4]:= Det[HilbertMatrix[3]]
Out[4]= 1/2160

In[5]:= Inverse[HilbertMatrix[3]]
Out[5]= {{9, -36, 30}, {-36, 192, -180}, {30, -180, 180}}

Implementation notes

Algorithm. builtin_hilbertmatrix constructs the m×n Hilbert matrix with entry (i,j) = 1/(i+j-1). The dimension spec (hm_parse_dims) is a positive integer n (square) or a pair {m, n} of positive integers; bad specs emit HilbertMatrix::dims, zero arguments emit HilbertMatrix::argx. The only recognised option is WorkingPrecision (hm_parse_working_precision, last-valid-setting-wins): Infinity (default) yields exact Rational entries via make_rational; MachinePrecision (or a digit count at/below machine precision) yields machine-precision Reals; a larger digit count yields MPFR reals (mpfr_div_ui) when built with USE_MPFR, degrading to machine reals otherwise (HilbertMatrix::wprec). Any trailing non-option argument triggers HilbertMatrix::nonopt.

Data structures. A List of Lists built row by row; each entry is created by hm_entry according to the selected hm_prec_mode (EXACT/MACHINE/MPFR). Complexity is O(mn) entry constructions.

  • Protected.
  • Entries are exact Rationals by default. The matrix is symmetric and

Attributes: Protected.

Implementation status

Stable — documented, exercised by the test suite and/or worked examples, with no known limitations recorded.

References

Notes & additional examples

Worked examples

In[1]:= HilbertMatrix[3]
Out[1]= {{1, 1/2, 1/3}, {1/2, 1/3, 1/4}, {1/3, 1/4, 1/5}}

Rectangular Hilbert matrices are available too:

In[1]:= HilbertMatrix[{2, 4}]
Out[1]= {{1, 1/2, 1/3, 1/4}, {1/2, 1/3, 1/4, 1/5}}

The Hilbert matrix is the textbook ill-conditioned matrix, yet its exact rational inverse is integer-valued:

In[1]:= Inverse[HilbertMatrix[3]]
Out[1]= {{9, -36, 30}, {-36, 192, -180}, {30, -180, 180}}

Its determinant is a tiny but exact rational (these are reciprocals of the Hilbert determinants), illustrating the near-singularity:

In[1]:= Det[HilbertMatrix[5]]
Out[1]= 1/266716800000

Because entries are kept exact, eigenvalues come out in closed form:

In[1]:= Eigenvalues[HilbertMatrix[2]]
Out[1]= {1/24 (16 + 4 Sqrt[13]), 1/24 (16 - 4 Sqrt[13])}

Notes

HilbertMatrix[n] has entries 1/(i + j - 1) and is the canonical ill-conditioned test matrix. Entries are exact Rationals, so Det, Inverse, and Eigenvalues return exact answers; request WorkingPrecision -> MachinePrecision (or a digit count) for an inexact version.