Thousands of tools! Check out Online Tools – I have now added thousands of tools.

I often have to generate diagonal matrices so I created this simple online utility that does it for me. It lets you generate square and rectangular diagonal matrices of any size you need. It works in the browser and is powered by alien technology from the future.

Diagonal Matrix Generator Options

Dimensions and Format
Align all matrix elements in nice columns.
Diagonal Elements
Element Range

Diagonal Matrix Generator Examples (click to try!)

Square Diagonal Matrix
This example generates a 10-by-10 diagonal matrix with decimal numbers with a two-digit decimal accuracy from the range 0 to 1 (both inclusive) as the diagonal elements.
0.75    0    0    0    0    0    0    0    0    0
   0 0.45    0    0    0    0    0    0    0    0
   0    0 0.37    0    0    0    0    0    0    0
   0    0    0 0.23    0    0    0    0    0    0
   0    0    0    0 0.91    0    0    0    0    0
   0    0    0    0    0 0.65    0    0    0    0
   0    0    0    0    0    0 0.11    0    0    0
   0    0    0    0    0    0    0 0.07    0    0
   0    0    0    0    0    0    0    0 0.19    0
   0    0    0    0    0    0    0    0    0 0.55
Number of rows.
Number of columns.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Random Decimals
Zero element.
Starting value (inclusive).
Ending value (inclusive).
Decimal precision (works only if random decimals is selected).
Rectangle Diagonal Matrix
In this example, we create a rectangular 4x9 matrix with integer numbers from the range 0 to 9 (both inclusive) as the diagonal elements. Columns 5 to 9 are all zero as the matrix is not a square matrix.
4 0 0 0 0 0 0 0 0
0 7 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 5 0 0 0 0 0
Number of rows.
Number of columns.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Random Integers
Zero element.
Starting value (inclusive).
Ending value (inclusive).
Custom Diagonal Elements
This example selects the "Custom Elements" option and uses a custom Unicode font for the diagonal elements. The custom elements are space-separated and contain numbers 𝟙 to 𝟡. It also uses a custom zero element 𝟘.
𝟠 𝟘 𝟘 𝟘 𝟘 𝟘 𝟘
𝟘 𝟚 𝟘 𝟘 𝟘 𝟘 𝟘
𝟘 𝟘 𝟙 𝟘 𝟘 𝟘 𝟘
𝟘 𝟘 𝟘 𝟛 𝟘 𝟘 𝟘
𝟘 𝟘 𝟘 𝟘 𝟡 𝟘 𝟘
𝟘 𝟘 𝟘 𝟘 𝟘 𝟞 𝟘
𝟘 𝟘 𝟘 𝟘 𝟘 𝟘 𝟠
Number of rows.
Number of columns.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Custom Elements
Enter custom elements here.
Zero element.
Zero Matrix
In this example, we set the custom elements field to zero and as a result, we get a 5×5 square matrix that contains only zeros.
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
Number of rows.
Number of columns.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Custom Elements
Enter custom elements here.
Zero element.
Print the Diagonal
This example unsets the zero element. In this case, the space character is printed in place of zeros. This makes it print only the diagonal elements that are all two-digit whole numbers.
59               
   34            
      25         
         46      
            97   
               35
Number of rows.
Number of columns.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Random Integers
Starting value (inclusive).
Ending value (inclusive).
Zero element.
Hide the Diagonal
In this example, we hide the diagonal elements by using the custom elements option. We set it to the space character and this character gets printed on the diagonal, thus effectively hiding the diagonal of the matrix.
  0 0 0 0 0
0   0 0 0 0
0 0   0 0 0
0 0 0   0 0
0 0 0 0   0
0 0 0 0 0  
Number of rows.
Number of columns.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Custom Elements
Enter custom elements here.
Zero element.

How Does This Diagonal Matrix Generator Work?

This diagonal matrix generator works entirely in your browser and is written in JavaScript. It uses a modified Kronecker delta function δij to construct a diagonal matrix. If i = j, then it puts a diagonal element in the position mij of the matrix. If i != j, then it puts a zero element in the position mij. It can generate square matrices of size n×n and rectangular matrices of sizes n×m or m×n. The diagonal elements can be random integers (both negative and positive) or decimal numbers (also both negative and positive). If the diagonal elements are decimal numbers, then you can also specify the precision of these numbers in the options. It can also put custom elements on the diagonal. The custom elements can be entered as a space-separated list of symbols. For example, you can use Greek letters α β γ δ ε as the diagonal elements. In this case, this tool will pick one of the custom elements for each diagonal element via a code snippet mij = pickOne(['α', 'β', 'γ', 'δ', 'ε']). If the diagonal elements have multiple characters in them, then you can prettify the matrix and neatly align all columns. By default, it uses the space character to separate all matrix columns and the newline character to separate all matrix rows. These characters can also be customized in the options.

Created by Browserling

This diagonal matrix generator was created by me and my team at Browserling. Behind the scenes, it's actually powered by our web developer tools that are used by millions of people every month. Browserling itself is an online cross-browser testing service powered by alien technology. Check it out!

Secret message: If you love my tools, then I love you, too! Use coupon code TOOLLING to get a discount at my company.