mathjs
Version:
Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with a large set of built-in functions and constants, and offers an integrated solution to work with dif
49 lines (33 loc) • 1.42 kB
Markdown
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
Create a matrix by evaluating a generating function at each index.
The simplest overload returns a multi-dimensional array as long as `size` is an array.
Passing `size` as a Matrix or specifying a `format` will result in returning a Matrix.
```js
math.matrixFromFunction(size, fn)
math.matrixFromFunction(size, fn, format)
math.matrixFromFunction(size, fn, format, datatype)
math.matrixFromFunction(size, format, fn)
math.matrixFromFunction(size, format, datatype, fn)
```
Parameter | Type | Description
--------- | ---- | -----------
`size` | Array &
`fn` | function | Callback function invoked for every entry in the matrix
`format` | string | The Matrix storage format, either `'dense'` or `'sparse'`
`datatype` | string | Type of the values
Type | Description
---- | -----------
Array &
```js
math.matrixFromFunction([3,3], i => i[0] - i[1]) // an antisymmetric matrix
math.matrixFromFunction([100, 100], 'sparse', i => i[0] - i[1] === 1 ? 4 : 0) // a sparse subdiagonal matrix
math.matrixFromFunction([5], i => math.random()) // a random vector
```
[ ](matrix.md),
[ ](zeros.md)