68 lines
2.3 KiB
Markdown

---
layout: default
---
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
<h1 id="function-matrix">Function matrix <a href="#function-matrix" title="Permalink">#</a></h1>
Create a Matrix. The function creates a new `math.Matrix` object from
an `Array`. A Matrix has utility functions to manipulate the data in the
matrix, like getting the size and getting or setting values in the matrix.
Supported storage formats are 'dense' and 'sparse'.
<h2 id="syntax">Syntax <a href="#syntax" title="Permalink">#</a></h2>
```js
math.matrix() // creates an empty matrix using default storage format (dense).
math.matrix(data) // creates a matrix with initial data using default storage format (dense).
math.matrix('dense') // creates an empty matrix using the given storage format.
math.matrix(data, 'dense') // creates a matrix with initial data using the given storage format.
math.matrix(data, 'sparse') // creates a sparse matrix with initial data.
math.matrix(data, 'sparse', 'number') // creates a sparse matrix with initial data, number data type.
```
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
Parameter | Type | Description
--------- | ---- | -----------
`data` | Array &#124; Matrix | A multi dimensional array
`format` | string | The Matrix storage format, either `'dense'` or `'sparse'`
`datatype` | string | Type of the values
<h3 id="returns">Returns <a href="#returns" title="Permalink">#</a></h3>
Type | Description
---- | -----------
Matrix | The created matrix
<h3 id="throws">Throws <a href="#throws" title="Permalink">#</a></h3>
Type | Description
---- | -----------
<h2 id="examples">Examples <a href="#examples" title="Permalink">#</a></h2>
```js
let m = math.matrix([[1, 2], [3, 4]])
m.size() // Array [2, 2]
m.resize([3, 2], 5)
m.valueOf() // Array [[1, 2], [3, 4], [5, 5]]
m.get([1, 0]) // number 3
```
<h2 id="see-also">See also <a href="#see-also" title="Permalink">#</a></h2>
[bignumber](bignumber.html),
[boolean](boolean.html),
[complex](complex.html),
[index](index.html),
[number](number.html),
[string](string.html),
[unit](unit.html),
[sparse](sparse.html)