Creating Hilbert Matrices in Matlab

February 06, 2019

This is a very simple snippet, yet answers a commonly asked question.

What is a Hilbert matrix?

A Hilbert matrix is a square matrix with unit fractions as entries. This is the equation for every cell of a Hilbert Matrix:

H(i, j) = 1 / (i + j -1)

Very simple! Great for testing matrix operations across the board, since the matrix for any size will always yield a consistent result.

How do I create one?

Simply use the hilb() function, passing in a matrix size into the function:

hilb(4)

    1.0000    0.5000    0.3333    0.2500
    0.5000    0.3333    0.2500    0.2000
    0.3333    0.2500    0.2000    0.1667
    0.2500    0.2000    0.1667    0.1429