# identity() Function & Examples

Use the identity() matrix function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## identity

#### identity(n)

#### identity(m, n)

#### identity([m, n])

Try it yourself:

```calculio
identity(3)
identity(3, 5)
a = [1, 2, 3; 4, 5, 6]
identity(size(a))
```

[concat](https://calcul.io/function/concat/index.md)

[det](https://calcul.io/function/det/index.md)

[diag](https://calcul.io/function/diag/index.md)

[inv](https://calcul.io/function/inv/index.md)

[ones](https://calcul.io/function/ones/index.md)

[range](https://calcul.io/function/range/index.md)

[size](https://calcul.io/function/size/index.md)

[squeeze](https://calcul.io/function/squeeze/index.md)

[subset](https://calcul.io/function/subset/index.md)

[trace](https://calcul.io/function/trace/index.md)

[transpose](https://calcul.io/function/transpose/index.md)

[zeros](https://calcul.io/function/zeros/index.md)

---

## Create an identity matrix

**identity(n)** creates an n-by-n matrix with ones on the main diagonal and zeros elsewhere. The identity matrix is the multiplicative neutral element of matrix algebra: multiplying a compatible matrix by it leaves that matrix unchanged.

## Example and applications

`identity(3)` creates a 3-by-3 diagonal matrix of ones. It is useful for initializing transforms, constructing linear systems, and expressing formulas such as A + λI. Combine it with [multiply](https://calcul.io/function/multiply/index.md) to verify the neutral property, [zeros](https://calcul.io/function/zeros/index.md) to start from an all-zero matrix, and [diag](https://calcul.io/function/diag/index.md) to work with diagonals.

## Input and shape caveats

n should be a non-negative integer. The identity matrix is square, so its size must match the relevant dimension for multiplication or addition; use [size](https://calcul.io/function/size/index.md) to check. Do not confuse identity with an all-ones matrix, which [ones](https://calcul.io/function/ones/index.md) creates.

[All functions](https://calcul.io/functions/index.md)
