Easily Create and Visualize Hilbert Matrices in MATLAB

Creating and visualizing a standard Hilbert matrix for further linear algebra applications

Crimson
Nerd For Tech
2 min readAug 2, 2023

--

In simple words, a Hilbert matrix is defined as a square matrix in which the (i, j)-th element is given by the formula:

Hilbert matrix formula

This means we would only need to create an MxM matrix and apply this operation to each value, then we would visualize this matrix.

So, first, create the array and apply the operation on each element using nested for loops:

To visualize the matrix, use the ‘imagesc’ function in MATLAB. This function will help us see the Hilbert matrix as an image.

That’s it! Just run the code, and you will get a Hilbert Matrix.

If, for some reason, you wish to make changes to the colors of the image, you will need to change its colormap choosing a default map or creating one of your own. For example, by adding this line of code after displaying the image:

colormap('summer');

We would get this result:

That concludes it! By following the steps and using the provided MATLAB code, you can easily create and visualize a Hilbert matrix. Feel free to experiment with different matrix sizes and colormaps to suit your needs.

I hope you found this article helpful. If you have any suggestions or questions, please leave a comment below. Don’t forget to clap and follow for more exciting MATLAB tutorials!

--

--