MUNIT returns an identity matrix of a specified dimension: a square array with 1s on the main diagonal and 0s everywhere else. It is useful for linear algebra, matrix checks, and building structured test data in Excel.
=MUNIT(dimension)What does MUNIT do?
MUNIT is a Math & trigonometry function that builds an identity matrix of any size you choose. An identity matrix is square, with 1s running from top-left to bottom-right and 0s in every other cell. For example, =MUNIT(3) spills a 3-by-3 block of cells with 1s on the diagonal and 0s elsewhere.
Identity matrices matter because they behave like the number 1 in matrix arithmetic: multiplying any compatible matrix by an identity matrix leaves it unchanged. That makes MUNIT handy for checking matrix calculations, setting up linear algebra homework, or creating clean diagonal patterns for models and dashboards.
In practice, office workers and students often need a quick diagonal block for a spreadsheet model, a teaching example, or a test of array formulas. Instead of typing dozens of 0s and 1s by hand, MUNIT produces the whole block in one formula, and it resizes automatically when you change the dimension.
When to use MUNIT
- Creating a diagonal of 1s for matrix multiplication checks
- Teaching or studying linear algebra in Excel
- Building test data for array and dynamic array formulas
- Setting up identity matrices for regression or transformation models
- Producing clean diagonal patterns for charts or conditional formatting
- Verifying that a matrix inverse calculation returns the identity
MUNIT syntax
=MUNIT(dimension)| Argument | Required? | What to enter |
|---|---|---|
dimension | Required | The number of rows and columns in the square identity matrix. Must be a positive whole number; for example, =MUNIT(4) returns a 4-by-4 matrix. |
What it returns: A square array (spilling into neighbouring cells) with the specified number of rows and columns, containing 1 on the main diagonal and 0 in all other positions. If dimension is not a positive whole number, MUNIT returns an error.
MUNIT examples
1 Example 1: A 3-by-3 identity matrix
The goal is to see exactly what MUNIT produces for a small size. The formula =MUNIT(3) asks for a 3-by-3 identity matrix. Excel spills nine cells: 1s on the diagonal and 0s elsewhere. The top-left cell of the spill is the target cell D2, and it contains 1.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Item | Value | |||
| 2 | Alpha | 10 | 1 | ||
| 3 | Beta | 20 | |||
| 4 | Gamma | 30 | |||
| 5 |
2 Example 2: Identity matrix sized from a cell
Here the dimension comes from a cell so the matrix resizes when the number changes. Cell B2 holds 4, so =MUNIT(B2) returns a 4-by-4 identity matrix. The spill covers 16 cells, and the top-left cell D2 contains 1. Change B2 to 2 and the matrix shrinks to 2-by-2 automatically.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Label | Size | |||
| 2 | Matrix size | 4 | 1 | ||
| 3 | Rows | 4 | |||
| 4 | Columns | 4 | |||
| 5 |
3 Example 3: Check a matrix inverse
A common linear algebra check is that a matrix times its inverse equals the identity matrix. The table stores a 2-by-2 matrix in A2:B3 and its inverse in D2:E3. The formula =MUNIT(2) creates the expected 2-by-2 identity matrix starting at G2. Comparing the product of the two matrices with this block confirms the inverse is correct; the top-left cell G2 is 1.
| A | B | C | D | E | F | G | H | |
|---|---|---|---|---|---|---|---|---|
| 1 | a | b | inv a | inv b | ||||
| 2 | 2 | 1 | 1 | -1 | 1 | |||
| 3 | 1 | 1 | -1 | 2 | ||||
| 4 |
4 Example 4: Identity matrix for a 5-department model
A five-department budget model needs a 5-by-5 identity block for its allocation matrix. Cell B2 stores 5, and =MUNIT(B2) spills a 5-by-5 identity matrix beginning at D2. The diagonal of 1s lines up with each department, and all off-diagonal cells are 0. The top-left cell D2 returns 1.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Department | Count | |||
| 2 | Sales | 5 | 1 | ||
| 3 | Marketing | 5 | |||
| 4 | Operations | 5 | |||
| 5 | Finance | 5 | |||
| 6 | HR | 5 | |||
| 7 |
5 Example 5: Sum the diagonal of a 6-by-6 identity
The goal is to confirm the trace of an identity matrix equals its dimension. The formula =SUM(MUNIT(6)) builds a 6-by-6 identity matrix and adds all its cells. Because there are six 1s and thirty 0s, the total is 6. The result appears in the single target cell D2.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Check | Value | |||
| 2 | Dimension | 6 | 6 | ||
| 3 | Expected trace | 6 | |||
| 4 | Tolerance | 0 | |||
| 5 |
Common MUNIT errors and how to fix them
| Error | Why it happens | How to fix it |
|---|---|---|
| #VALUE! | The dimension argument is text, a blank cell, or a non-numeric value. | Enter a positive whole number or refer to a cell that contains one. |
| #NUM! | The dimension is zero, negative, or too large for Excel to spill. | Use a positive whole number that fits on the sheet, such as 3 or 10. |
| #SPILL! | There is not enough empty space for the matrix to spill into. | Clear the cells to the right and below the target cell, or move the formula. |
| #NAME? | The function name is misspelled or the Excel version does not support MUNIT. | Check the spelling and use a Microsoft 365 or Excel 2021+ version that includes dynamic arrays. |
Tips for using MUNIT
- Store the dimension in a cell and refer to it so the matrix resizes automatically.
- Leave plenty of empty space to the right and below the formula to avoid #SPILL! errors.
- Use
=SUM(MUNIT(n))as a quick check that the trace equals the dimension. - Combine MUNIT with MMULT to verify matrix inverses or transformations.
- Remember MUNIT returns an array; wrap it in functions like SUM or INDEX when you need a single value.
Frequently asked questions
What does the MUNIT function do in Excel?
MUNIT returns an identity matrix of a given size: a square array with 1s on the main diagonal and 0s everywhere else.
Why do I get a #SPILL! error with MUNIT?
The identity matrix needs empty cells to expand into. Clear the cells to the right and below the formula, or move it to an empty area.
Can I use MUNIT with a cell reference for the size?
Yes. For example, =MUNIT(B2) uses the number in B2 as the dimension, and the matrix resizes when B2 changes.
Is MUNIT available in older Excel versions?
MUNIT requires dynamic arrays, so it is available in Microsoft 365 and Excel 2021 and later. Older versions return #NAME?.
Related functions
Every example on this page was recalculated by SheetSkill’s spreadsheet engine. MUNIT reference