mirror of
https://github.com/josdejong/mathjs.git
synced 2025-12-08 19:46:04 +00:00
979 B
979 B
Function eye
Create a 2-dimensional identity matrix with size m x n or n x n. The matrix has ones on the diagonal and zeros elsewhere.
Syntax
math.eye(n)
math.eye(m, n)
math.eye([m, n])
Parameters
| Parameter | Type | Description |
|---|---|---|
size |
...Number | Matrix | Array | The size for the matrix |
Returns
| Type | Description |
|---|---|
| Matrix | Array | Number | A matrix with ones on the diagonal. |
Examples
math.eye(3); // returns [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
math.eye(3, 2); // returns [[1, 0], [0, 1], [0, 0]]
var A = [[1, 2, 3], [4, 5, 6]];
math.eye(math.size(b)); // returns [[1, 0, 0], [0, 1, 0]]