All published worksheets from http://sagenb.org
Image: ubuntu2004
The Hilbert Matrix
The Hilbert matrix is a very ill-conditioned matrix. See http://en.wikipedia.org/wiki/Hilbert_matrix for some background information.
Exact Arithmetic
First, let's define a Hilbert matrix. We will be using exact arithmetic first.
As expected, the matrix times its inverse is the identity matrix. However, this happens because we are dealing with exact arithmetic, with no rounding. In a sense, we have infinite precision here.
Matlab-like precision
Now let's try floating point precision, which is what Matlab uses. We will first change to have entries over "RealField(53)", which is the precision that is used for double-precision floating point numbers.
Notice that the matrix times its inverse is not anything like the identity matrix. The roundoff error was magnified so that the inverse really doesn't mean much.
Higher Precision Floating Point
In Sage (and other systems, but not Matlab), we can compute in higher precision than double-precision. Here, we do the computations in 100-bit precision, instead of double-precision (53-bit precision).
While we don't quite get the identity matrix exactly, we get something that is very, very close to the identity matrix. The diagonal entries are almost one, and the off-diagonal entries are almost zero.