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

Identity Matrix Generator Options

Dimension and Format
Output Format
Align all matrix elements in nice columns.

Identity Matrix Generator Examples (click to try!)

5x5 Unit Matrix
In this example, we generate a 5 by 5 unit matrix with 1's on the main diagonal.
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
Number of rows and columns.
Diagonal element.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Identity Matrix with α's
This example creates a 10x10 identity matrix that uses the Greek letter α as the identity symbol on the diagonal.
α 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 α 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 α 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 and columns.
Diagonal element.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix
Prettified Unit Matrix
This example sets three digits 111 as the unit symbols and enables matrix beautification option to make all columns evenly aligned.
111   0   0   0   0   0
  0 111   0   0   0   0
  0   0 111   0   0   0
  0   0   0 111   0   0
  0   0   0   0 111   0
  0   0   0   0   0 111
Number of rows and columns.
Diagonal element.
Separate matrix elements with this character.
Separate matrix rows with this character.
Prettify Matrix

How Does This Identity Matrix Generator Work?

This unit matrix generator works entirely in your browser and is written in JavaScript. As the identity matrix is a sparse matrix with unit elements only on the diagonal, then it uses two nested loops, indexed by i and j to print it. If i is equal to j, then it prints the unit element, otherwise, it prints a 0. The loop runs until i and j reach size (matrix dimension; specified in options). The unit element is 1 by default but you can customize it to any other symbol. Additionally, there are two separators that you can change. The first is the element separator. It's the symbol that gets put between elements on every row. The second is the row separator that gets put after one row of elements get printed. If the unit element is more than 1 character in length, then you can also prettify columns so that they look neat.

Created by Browserling

This identity matrix generator was created by me and my team at Browserling. Behind the scenes, it's actually powered by Browserling's programmer 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 Browserling.