Intial Commit

This commit is contained in:
valki
2020-10-17 18:42:50 +02:00
commit 664c6d8ca3
5892 changed files with 759183 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
# Class Reference
This page lists all the various class types in Math.js. Every top-level function is listed here and links to its detailed reference to other parts of the documentation.
## math
The "math" namespace contains the entire math.js functionality. All of the mathematical functions are available in the "math" namespace, and allow for inputs of various types.
- [Function reference](functions.md)
- [Constant reference](constants.md)
## Unit
Stores values for a scalar unit and its postfix. (eg `100 mm` or `100 kg`). Although the `Unit` class contains public functions documented as follows, using the following API directly is *not* recommended. Prefer using the functions in the "math" namespace wherever possible.
- [Overview](../datatypes/units.md)
- [Class API](classes/unit.md)
## Fraction
Stores values for a fractional number.
- [Overview](../datatypes/fractions.md)
- [Class API](https://github.com/infusion/Fraction.js/)
## BigNumber
Stores values for a arbitrary-precision floating point number.
- [Overview](../datatypes/bignumbers.md)
- [Class API](http://mikemcl.github.io/decimal.js/)
## Matrix
Two types of matrix classes are available in math.js, for storage of dense and sparse matrices. Although they contain public functions documented as follows, using the following API directly is *not* recommended. Prefer using the functions in the "math" namespace wherever possible.
- [Overview](../datatypes/matrices.md)
- [DenseMatrix](classes/densematrix.md)
- [SparseMatrix](classes/sparsematrix.md)
Classes used internally that may be of use to developers:
- [Index](classes/matrixindex.md)
- [Range](classes/matrixrange.md)
- [ResultSet](classes/matrixrange.md)
- [FibonacciHeap](classes/fibonacciheap.md)
## Complex
Stores values for a complex number.
- [Overview](../datatypes/complex_numbers.md)
- [Class API](https://github.com/infusion/Complex.js/)
## Parser
The Parser object returned by `math.parser()`.
- [Overview](../expressions/parsing.md)
## Node
A node in an expression-tree, which can be used to analyze, manipulate, and evaluate expressions.
- [Overview](../expressions/expression_trees.md)
`Node` is the base class of all other node classes:
- [AccessorNode](../expressions/expression_trees.md#accessornode)
- [ArrayNode](../expressions/expression_trees.md#arraynode)
- [AssignmentNode](../expressions/expression_trees.md#assignmentnode)
- [BlockNode](../expressions/expression_trees.md#blocknode)
- [ConditionalNode](../expressions/expression_trees.md#conditionalnode)
- [ConstantNode](../expressions/expression_trees.md#constantnode)
- [FunctionAssignmentNode](../expressions/expression_trees.md#functionassignmentnode)
- [FunctionNode](../expressions/expression_trees.md#functionnode)
- [IndexNode](../expressions/expression_trees.md#indexnode)
- [ObjectNode](../expressions/expression_trees.md#objectnode)
- [OperatorNode](../expressions/expression_trees.md#operatornode)
- [ParenthesisNode](../expressions/expression_trees.md#parenthesisnode)
- [RangeNode](../expressions/expression_trees.md#rangenode)
- [SymbolNode](../expressions/expression_trees.md#symbolnode)
- [UpdateNode](../expressions/expression_trees.md#updatenode)

View File

@@ -0,0 +1,247 @@
<a name="DenseMatrix"></a>
## DenseMatrix
Dense Matrix implementation. This type implements an efficient Array format
for dense matrices.
* _instance_
* [.storage()](#DenseMatrix+storage) ⇒ <code>string</code>
* [.datatype()](#DenseMatrix+datatype) ⇒ <code>string</code>
* [.create(data, [datatype])](#DenseMatrix+create)
* [.subset(index, [replacement], [defaultValue])](#DenseMatrix+subset)
* [.get(index)](#DenseMatrix+get) ⇒ <code>\*</code>
* [.set(index, value, [defaultValue])](#DenseMatrix+set) ⇒ <code>DenseMatrix</code>
* [.resize(size, [defaultValue], [copy])](#DenseMatrix+resize) ⇒ <code>Matrix</code>
* [.clone()](#DenseMatrix+clone) ⇒ <code>DenseMatrix</code>
* [.size()](#DenseMatrix+size) ⇒ <code>Array.&lt;number&gt;</code>
* [.map(callback)](#DenseMatrix+map) ⇒ <code>DenseMatrix</code>
* [.forEach(callback)](#DenseMatrix+forEach)
* [.toArray()](#DenseMatrix+toArray) ⇒ <code>Array</code>
* [.valueOf()](#DenseMatrix+valueOf) ⇒ <code>Array</code>
* [.format([options])](#DenseMatrix+format) ⇒ <code>string</code>
* [.toString()](#DenseMatrix+toString) ⇒ <code>string</code>
* [.toJSON()](#DenseMatrix+toJSON) ⇒ <code>Object</code>
* [.diagonal([k])](#DenseMatrix+diagonal) ⇒ <code>Array</code>
* [.swapRows(i, j)](#DenseMatrix+swapRows) ⇒ <code>Matrix</code>
* _static_
* [.diagonal(size, value, [k], [defaultValue])](#DenseMatrix.diagonal) ⇒ <code>DenseMatrix</code>
* [.fromJSON(json)](#DenseMatrix.fromJSON) ⇒ <code>DenseMatrix</code>
* [.preprocess(data)](#DenseMatrix.preprocess) ⇒ <code>Array</code>
<a name="DenseMatrix+storage"></a>
### denseMatrix.storage() ⇒ <code>string</code>
Get the storage format used by the matrix.
Usage:
```js
var format = matrix.storage() // retrieve storage format
```
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>string</code> - The storage format.
<a name="DenseMatrix+datatype"></a>
### denseMatrix.datatype() ⇒ <code>string</code>
Get the datatype of the data stored in the matrix.
Usage:
```js
var format = matrix.datatype() // retrieve matrix datatype
```
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>string</code> - The datatype.
<a name="DenseMatrix+create"></a>
### denseMatrix.create(data, [datatype])
Create a new DenseMatrix
**Kind**: instance method of <code>DenseMatrix</code>
| Param | Type |
| --- | --- |
| data | <code>Array</code> |
| [datatype] | <code>string</code> |
<a name="DenseMatrix+subset"></a>
### denseMatrix.subset(index, [replacement], [defaultValue])
Get a subset of the matrix, or replace a subset of the matrix.
Usage:
```js
var subset = matrix.subset(index) // retrieve subset
var value = matrix.subset(index, replacement) // replace subset
```
**Kind**: instance method of <code>DenseMatrix</code>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| index | <code>Index</code> | | |
| [replacement] | <code>Array</code> &#124; <code>DenseMatrix</code>&#124; <code>\*</code> | | |
| [defaultValue] | <code>\*</code> | <code>0</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be filled with zeros. |
<a name="DenseMatrix+get"></a>
### denseMatrix.get(index) ⇒ <code>\*</code>
Get a single element from the matrix.
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>\*</code> - value
| Param | Type | Description |
| --- | --- | --- |
| index | <code>Array.&lt;number&gt;</code> | Zero-based index |
<a name="DenseMatrix+set"></a>
### denseMatrix.set(index, value, [defaultValue]) ⇒ <code>DenseMatrix</code>
Replace a single element in the matrix.
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>DenseMatrix</code>- self
| Param | Type | Description |
| --- | --- | --- |
| index | <code>Array.&lt;number&gt;</code> | Zero-based index |
| value | <code>\*</code> | |
| [defaultValue] | <code>\*</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be left undefined. |
<a name="DenseMatrix+resize"></a>
### denseMatrix.resize(size, [defaultValue], [copy]) ⇒ <code>Matrix</code>
Resize the matrix to the given size. Returns a copy of the matrix when
`copy=true`, otherwise return the matrix itself (resize in place).
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>Matrix</code> - The resized matrix
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| size | <code>Array.&lt;number&gt;</code> | | The new size the matrix should have. |
| [defaultValue] | <code>\*</code> | <code>0</code> | Default value, filled in on new entries. If not provided, the matrix elements will be filled with zeros. |
| [copy] | <code>boolean</code> | | Return a resized copy of the matrix |
<a name="DenseMatrix+clone"></a>
### denseMatrix.clone() ⇒ <code>DenseMatrix</code>
Create a clone of the matrix
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>DenseMatrix</code>- clone
<a name="DenseMatrix+size"></a>
### denseMatrix.size() ⇒ <code>Array.&lt;number&gt;</code>
Retrieve the size of the matrix.
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>Array.&lt;number&gt;</code> - size
<a name="DenseMatrix+map"></a>
### denseMatrix.map(callback) ⇒ <code>DenseMatrix</code>
Create a new matrix with the results of the callback function executed on
each entry of the matrix.
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>DenseMatrix</code>- matrix
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
<a name="DenseMatrix+forEach"></a>
### denseMatrix.forEach(callback)
Execute a callback function on each entry of the matrix.
**Kind**: instance method of <code>DenseMatrix</code>
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
<a name="DenseMatrix+toArray"></a>
### denseMatrix.toArray() ⇒ <code>Array</code>
Create an Array with a copy of the data of the DenseMatrix
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>Array</code> - array
<a name="DenseMatrix+valueOf"></a>
### denseMatrix.valueOf() ⇒ <code>Array</code>
Get the primitive value of the DenseMatrix: a multidimensional array
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>Array</code> - array
<a name="DenseMatrix+format"></a>
### denseMatrix.format([options]) ⇒ <code>string</code>
Get a string representation of the matrix, with optional formatting options.
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>string</code> - str
| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> &#124; <code>number</code> &#124; <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. |
<a name="DenseMatrix+toString"></a>
### denseMatrix.toString() ⇒ <code>string</code>
Get a string representation of the matrix
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>string</code> - str
<a name="DenseMatrix+toJSON"></a>
### denseMatrix.toJSON() ⇒ <code>Object</code>
Get a JSON representation of the matrix
**Kind**: instance method of <code>DenseMatrix</code>
<a name="DenseMatrix+diagonal"></a>
### denseMatrix.diagonal([k]) ⇒ <code>Array</code>
Get the kth Matrix diagonal.
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>Array</code> - The array vector with the diagonal values.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [k] | <code>number</code> &#124; <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will retrieved. |
<a name="DenseMatrix+swapRows"></a>
### denseMatrix.swapRows(i, j) ⇒ <code>Matrix</code>
Swap rows i and j in Matrix.
**Kind**: instance method of <code>DenseMatrix</code>
**Returns**: <code>Matrix</code> - The matrix reference
| Param | Type | Description |
| --- | --- | --- |
| i | <code>number</code> | Matrix row index 1 |
| j | <code>number</code> | Matrix row index 2 |
<a name="DenseMatrix.diagonal"></a>
### DenseMatrix.diagonal(size, value, [k], [defaultValue]) ⇒ <code>DenseMatrix</code>
Create a diagonal matrix.
**Kind**: static method of <code>DenseMatrix</code>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| size | <code>Array</code> | | The matrix size. |
| value | <code>number</code> &#124; <code>Array</code> | | The values for the diagonal. |
| [k] | <code>number</code> &#124; <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will be filled in. |
| [defaultValue] | <code>number</code> | | The default value for non-diagonal |
<a name="DenseMatrix.fromJSON"></a>
### DenseMatrix.fromJSON(json) ⇒ <code>DenseMatrix</code>
Generate a matrix from a JSON object
**Kind**: static method of <code>DenseMatrix</code>
| Param | Type | Description |
| --- | --- | --- |
| json | <code>Object</code> | An object structured like `{"mathjs": "DenseMatrix", data: [], size: []}`, where mathjs is optional |
<a name="DenseMatrix.preprocess"></a>
### DenseMatrix.preprocess(data) ⇒ <code>Array</code>
Preprocess data, which can be an Array or DenseMatrix with nested Arrays and
Matrices. Replaces all nested Matrices with Arrays
**Kind**: static method of <code>DenseMatrix</code>
**Returns**: <code>Array</code> - data
| Param | Type |
| --- | --- |
| data | <code>Array</code> |

View File

@@ -0,0 +1,70 @@
<a name="FibonacciHeap"></a>
## FibonacciHeap
* [new FibonacciHeap()](#new_FibonacciHeap_new)
* _instance_
* [.insert()](#FibonacciHeap+insert)
* [.size()](#FibonacciHeap+size)
* [.clear()](#FibonacciHeap+clear)
* [.isEmpty()](#FibonacciHeap+isEmpty)
* [.extractMinimum()](#FibonacciHeap+extractMinimum)
* [.remove()](#FibonacciHeap+remove)
* _static_
* [._decreaseKey()](#FibonacciHeap._decreaseKey)
* [._cut()](#FibonacciHeap._cut)
* [._cascadingCut()](#FibonacciHeap._cascadingCut)
* [._linkNodes()](#FibonacciHeap._linkNodes)
<a name="new_FibonacciHeap_new"></a>
### new FibonacciHeap()
Creates a new instance of a Fibonacci Heap.
<a name="FibonacciHeap+insert"></a>
### fibonacciHeap.insert()
Inserts a new data element into the heap. No heap consolidation is
performed at this time, the new node is simply inserted into the root
list of this heap. Running time: O(1) actual.
**Kind**: instance method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap+size"></a>
### fibonacciHeap.size()
Returns the number of nodes in heap. Running time: O(1) actual.
**Kind**: instance method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap+clear"></a>
### fibonacciHeap.clear()
Removes all elements from this heap.
**Kind**: instance method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap+isEmpty"></a>
### fibonacciHeap.isEmpty()
Returns true if the heap is empty, otherwise false.
**Kind**: instance method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap+extractMinimum"></a>
### fibonacciHeap.extractMinimum()
Extracts the node with minimum key from heap. Amortized running
time: O(log n).
**Kind**: instance method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap+remove"></a>
### fibonacciHeap.remove()
Removes a node from the heap given the reference to the node. The trees
in the heap will be consolidated, if necessary. This operation may fail
to remove the correct element if there are nodes with key value -Infinity.
Running time: O(log n) amortized.
**Kind**: instance method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap._decreaseKey"></a>
### FibonacciHeap._decreaseKey()
Decreases the key value for a heap node, given the new value to take on.
The structure of the heap may be changed and will not be consolidated.
Running time: O(1) amortized.
**Kind**: static method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap._cut"></a>
### FibonacciHeap._cut()
The reverse of the link operation: removes node from the child list of parent.
This method assumes that min is non-null. Running time: O(1).
**Kind**: static method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap._cascadingCut"></a>

View File

@@ -0,0 +1,133 @@
<a name="Index"></a>
## Index
* [new Index(...ranges)](#new_Index_new)
* _instance_
* [.valueOf](#Index+valueOf) ⇒ <code>Array</code>
* [.clone()](#Index+clone) ⇒ <code>[Index](#Index)</code>
* [.size()](#Index+size) ⇒ <code>Array.&lt;number&gt;</code>
* [.max()](#Index+max) ⇒ <code>Array.&lt;number&gt;</code>
* [.min()](#Index+min) ⇒ <code>Array.&lt;number&gt;</code>
* [.forEach(callback)](#Index+forEach)
* [.dimension(dim)](#Index+dimension) ⇒ <code>Range</code> &#124; <code>null</code>
* [.isScalar()](#Index+isScalar) ⇒ <code>boolean</code>
* [.toArray()](#Index+toArray) ⇒ <code>Array</code>
* [.toString()](#Index+toString) ⇒ <code>String</code>
* [.toJSON()](#Index+toJSON) ⇒ <code>Object</code>
* _static_
* [.fromJSON(json)](#Index.fromJSON) ⇒ <code>[Index](#Index)</code>
<a name="new_Index_new"></a>
### new Index(...ranges)
Create an index. An Index can store ranges and sets for multiple dimensions.
Matrix.get, Matrix.set, and math.subset accept an Index as input.
Usage:
```js
var index = new Index(range1, range2, matrix1, array1, ...);
```
Where each parameter can be any of:
- A number
- An instance of Range
- An Array with the Set values
- A Matrix with the Set values
The parameters start, end, and step must be integer numbers.
| Param | Type |
| --- | --- |
| ...ranges | <code>\*</code> |
<a name="Index+valueOf"></a>
### index.valueOf ⇒ <code>Array</code>
Get the primitive value of the Index, a two dimensional array.
Equivalent to Index.toArray().
**Kind**: instance property of <code>[Index](#Index)</code>
**Returns**: <code>Array</code> - array
<a name="Index+clone"></a>
### index.clone() ⇒ <code>[Index](#Index)</code>
Create a clone of the index
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>[Index](#Index)</code> - clone
<a name="Index+size"></a>
### index.size() ⇒ <code>Array.&lt;number&gt;</code>
Retrieve the size of the index, the number of elements for each dimension.
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>Array.&lt;number&gt;</code> - size
<a name="Index+max"></a>
### index.max() ⇒ <code>Array.&lt;number&gt;</code>
Get the maximum value for each of the indexes ranges.
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>Array.&lt;number&gt;</code> - max
<a name="Index+min"></a>
### index.min() ⇒ <code>Array.&lt;number&gt;</code>
Get the minimum value for each of the indexes ranges.
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>Array.&lt;number&gt;</code> - min
<a name="Index+forEach"></a>
### index.forEach(callback)
Loop over each of the ranges of the index
**Kind**: instance method of <code>[Index](#Index)</code>
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | Called for each range with a Range as first argument, the dimension as second, and the index object as third. |
<a name="Index+dimension"></a>
### index.dimension(dim) ⇒ <code>Range</code> &#124; <code>null</code>
Retrieve the dimension for the given index
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>Range</code> &#124; <code>null</code> - range
| Param | Type | Description |
| --- | --- | --- |
| dim | <code>Number</code> | Number of the dimension |
<a name="Index+isScalar"></a>
### index.isScalar() ⇒ <code>boolean</code>
Test whether this index contains only a single value.
This is the case when the index is created with only scalar values as ranges,
not for ranges resolving into a single value.
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>boolean</code> - isScalar
<a name="Index+toArray"></a>
### index.toArray() ⇒ <code>Array</code>
Expand the Index into an array.
For example new Index([0,3], [2,7]) returns [[0,1,2], [2,3,4,5,6]]
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>Array</code> - array
<a name="Index+toString"></a>
### index.toString() ⇒ <code>String</code>
Get the string representation of the index, for example '[2:6]' or '[0:2:10, 4:7, [1,2,3]]'
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>String</code> - str
<a name="Index+toJSON"></a>
### index.toJSON() ⇒ <code>Object</code>
Get a JSON representation of the Index
**Kind**: instance method of <code>[Index](#Index)</code>
**Returns**: <code>Object</code> - Returns a JSON object structured as:
`{"mathjs": "Index", "ranges": [{"mathjs": "Range", start: 0, end: 10, step:1}, ...]}`
<a name="Index.fromJSON"></a>
### Index.fromJSON(json) ⇒ <code>[Index](#Index)</code>
Instantiate an Index from a JSON object
**Kind**: static method of <code>[Index](#Index)</code>
| Param | Type | Description |
| --- | --- | --- |
| json | <code>Object</code> | A JSON object structured as: `{"mathjs": "Index", "dimensions": [{"mathjs": "Range", start: 0, end: 10, step:1}, ...]}` |

View File

@@ -0,0 +1,158 @@
<a name="Range"></a>
## Range
* [new Range(start, end, [step])](#new_Range_new)
* _instance_
* [.size()](#Range+size) ⇒ <code>Array.&lt;number&gt;</code>
* [.min()](#Range+min) ⇒ <code>number</code> &#124; <code>undefined</code>
* [.max()](#Range+max) ⇒ <code>number</code> &#124; <code>undefined</code>
* [.forEach(callback)](#Range+forEach)
* [.map(callback)](#Range+map) ⇒ <code>Array</code>
* [.toArray()](#Range+toArray) ⇒ <code>Array</code>
* [.valueOf()](#Range+valueOf) ⇒ <code>Array</code>
* [.format([options])](#Range+format) ⇒ <code>string</code>
* [.toString()](#Range+toString) ⇒ <code>string</code>
* [.toJSON()](#Range+toJSON) ⇒ <code>Object</code>
* _static_
* [.parse(str)](#Range.parse) ⇒ <code>[Range](#Range)</code> &#124; <code>null</code>
* [.fromJSON(json)](#Range.fromJSON) ⇒ <code>[Range](#Range)</code>
<a name="new_Range_new"></a>
### new Range(start, end, [step])
Create a range. A range has a start, step, and end, and contains functions
to iterate over the range.
A range can be constructed as:
```js
var range = new Range(start, end);
var range = new Range(start, end, step);
```
To get the result of the range:
```js
range.forEach(function (x) {
console.log(x);
});
range.map(function (x) {
return math.sin(x);
});
range.toArray();
```
Example usage:
```js
var c = new Range(2, 6); // 2:1:5
c.toArray(); // [2, 3, 4, 5]
var d = new Range(2, -3, -1); // 2:-1:-2
d.toArray(); // [2, 1, 0, -1, -2]
```
| Param | Type | Description |
| --- | --- | --- |
| start | <code>number</code> | included lower bound |
| end | <code>number</code> | excluded upper bound |
| [step] | <code>number</code> | step size, default value is 1 |
<a name="Range+size"></a>
### range.size() ⇒ <code>Array.&lt;number&gt;</code>
Retrieve the size of the range.
Returns an array containing one number, the number of elements in the range.
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>Array.&lt;number&gt;</code> - size
<a name="Range+min"></a>
### range.min() ⇒ <code>number</code> &#124; <code>undefined</code>
Calculate the minimum value in the range
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>number</code> &#124; <code>undefined</code> - min
<a name="Range+max"></a>
### range.max() ⇒ <code>number</code> &#124; <code>undefined</code>
Calculate the maximum value in the range
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>number</code> &#124; <code>undefined</code> - max
<a name="Range+forEach"></a>
### range.forEach(callback)
Execute a callback function for each value in the range.
**Kind**: instance method of <code>[Range](#Range)</code>
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | The callback method is invoked with three parameters: the value of the element, the index of the element, and the Range being traversed. |
<a name="Range+map"></a>
### range.map(callback) ⇒ <code>Array</code>
Execute a callback function for each value in the Range, and return the
results as an array
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>Array</code> - array
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | The callback method is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
<a name="Range+toArray"></a>
### range.toArray() ⇒ <code>Array</code>
Create an Array with a copy of the Ranges data
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>Array</code> - array
<a name="Range+valueOf"></a>
### range.valueOf() ⇒ <code>Array</code>
Get the primitive value of the Range, a one dimensional array
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>Array</code> - array
<a name="Range+format"></a>
### range.format([options]) ⇒ <code>string</code>
Get a string representation of the range, with optional formatting options.
Output is formatted as 'start:step:end', for example '2:6' or '0:0.2:11'
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>string</code> - str
| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> &#124; <code>number</code> &#124; <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. |
<a name="Range+toString"></a>
### range.toString() ⇒ <code>string</code>
Get a string representation of the range.
**Kind**: instance method of <code>[Range](#Range)</code>
<a name="Range+toJSON"></a>
### range.toJSON() ⇒ <code>Object</code>
Get a JSON representation of the range
**Kind**: instance method of <code>[Range](#Range)</code>
**Returns**: <code>Object</code> - Returns a JSON object structured as:
`{"mathjs": "Range", "start": 2, "end": 4, "step": 1}`
<a name="Range.parse"></a>
### Range.parse(str) ⇒ <code>[Range](#Range)</code> &#124; <code>null</code>
Parse a string into a range,
The string contains the start, optional step, and end, separated by a colon.
If the string does not contain a valid range, null is returned.
For example str='0:2:11'.
**Kind**: static method of <code>[Range](#Range)</code>
**Returns**: <code>[Range](#Range)</code> &#124; <code>null</code> - range
| Param | Type |
| --- | --- |
| str | <code>string</code> |
<a name="Range.fromJSON"></a>
### Range.fromJSON(json) ⇒ <code>[Range](#Range)</code>
Instantiate a Range from a JSON object
**Kind**: static method of <code>[Range](#Range)</code>
| Param | Type | Description |
| --- | --- | --- |
| json | <code>Object</code> | A JSON object structured as: `{"mathjs": "Range", "start": 2, "end": 4, "step": 1}` |

View File

@@ -0,0 +1,47 @@
<a name="ResultSet"></a>
## ResultSet
* [new ResultSet(entries)](#new_ResultSet_new)
* _instance_
* [.valueOf()](#ResultSet+valueOf) ⇒ <code>Array</code>
* [.toString()](#ResultSet+toString) ⇒ <code>string</code>
* [.toJSON()](#ResultSet+toJSON) ⇒ <code>Object</code>
* _static_
* [.fromJSON(json)](#ResultSet.fromJSON) ⇒ <code>[ResultSet](#ResultSet)</code>
<a name="new_ResultSet_new"></a>
### new ResultSet(entries)
A ResultSet contains a list or results
| Param | Type |
| --- | --- |
| entries | <code>Array</code> |
<a name="ResultSet+valueOf"></a>
### resultSet.valueOf() ⇒ <code>Array</code>
Returns the array with results hold by this ResultSet
**Kind**: instance method of <code>[ResultSet](#ResultSet)</code>
**Returns**: <code>Array</code> - entries
<a name="ResultSet+toString"></a>
### resultSet.toString() ⇒ <code>string</code>
Returns the stringified results of the ResultSet
**Kind**: instance method of <code>[ResultSet](#ResultSet)</code>
**Returns**: <code>string</code> - string
<a name="ResultSet+toJSON"></a>
### resultSet.toJSON() ⇒ <code>Object</code>
Get a JSON representation of the ResultSet
**Kind**: instance method of <code>[ResultSet](#ResultSet)</code>
**Returns**: <code>Object</code> - Returns a JSON object structured as:
`{"mathjs": "ResultSet", "entries": [...]}`
<a name="ResultSet.fromJSON"></a>
### ResultSet.fromJSON(json) ⇒ <code>[ResultSet](#ResultSet)</code>
Instantiate a ResultSet from a JSON object
**Kind**: static method of <code>[ResultSet](#ResultSet)</code>
| Param | Type | Description |
| --- | --- | --- |
| json | <code>Object</code> | A JSON object structured as: `{"mathjs": "ResultSet", "entries": [...]}` |

View File

@@ -0,0 +1,245 @@
<a name="SparseMatrix"></a>
## SparseMatrix
Sparse Matrix implementation. This type implements a Compressed Column Storage format
for sparse matrices.
* _instance_
* [.storage()](#SparseMatrix+storage) ⇒ <code>string</code>
* [.datatype()](#SparseMatrix+datatype) ⇒ <code>string</code>
* [.create(data, [datatype])](#SparseMatrix+create)
* [.density()](#SparseMatrix+density) ⇒ <code>number</code>
* [.subset(index, [replacement], [defaultValue])](#SparseMatrix+subset)
* [.get(index)](#SparseMatrix+get) ⇒ <code>\*</code>
* [.set(index, value, [defaultValue])](#SparseMatrix+set) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
* [.resize(size, [defaultValue], [copy])](#SparseMatrix+resize) ⇒ <code>Matrix</code>
* [.clone()](#SparseMatrix+clone) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
* [.size()](#SparseMatrix+size) ⇒ <code>Array.&lt;number&gt;</code>
* [.map(callback, [skipZeros])](#SparseMatrix+map) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
* [.forEach(callback, [skipZeros])](#SparseMatrix+forEach)
* [.toArray()](#SparseMatrix+toArray) ⇒ <code>Array</code>
* [.valueOf()](#SparseMatrix+valueOf) ⇒ <code>Array</code>
* [.format([options])](#SparseMatrix+format) ⇒ <code>string</code>
* [.toString()](#SparseMatrix+toString) ⇒ <code>string</code>
* [.toJSON()](#SparseMatrix+toJSON) ⇒ <code>Object</code>
* [.diagonal([k])](#SparseMatrix+diagonal) ⇒ <code>Matrix</code>
* [.swapRows(i, j)](#SparseMatrix+swapRows) ⇒ <code>Matrix</code>
* _static_
* [.fromJSON(json)](#SparseMatrix.fromJSON) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
* [.diagonal(size, value, [k], [datatype])](#SparseMatrix.diagonal) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
<a name="SparseMatrix+storage"></a>
### sparseMatrix.storage() ⇒ <code>string</code>
Get the storage format used by the matrix.
Usage:
```js
var format = matrix.storage() // retrieve storage format
```
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>string</code> - The storage format.
<a name="SparseMatrix+datatype"></a>
### sparseMatrix.datatype() ⇒ <code>string</code>
Get the datatype of the data stored in the matrix.
Usage:
```js
var format = matrix.datatype() // retrieve matrix datatype
```
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>string</code> - The datatype.
<a name="SparseMatrix+create"></a>
### sparseMatrix.create(data, [datatype])
Create a new SparseMatrix
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
| Param | Type |
| --- | --- |
| data | <code>Array</code> |
| [datatype] | <code>string</code> |
<a name="SparseMatrix+density"></a>
### sparseMatrix.density() ⇒ <code>number</code>
Get the matrix density.
Usage:
```js
var density = matrix.density() // retrieve matrix density
```
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>number</code> - The matrix density.
<a name="SparseMatrix+subset"></a>
### sparseMatrix.subset(index, [replacement], [defaultValue])
Get a subset of the matrix, or replace a subset of the matrix.
Usage:
```js
var subset = matrix.subset(index) // retrieve subset
var value = matrix.subset(index, replacement) // replace subset
```
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| index | <code>Index</code> | | |
| [replacement] | <code>Array</code> &#124; <code>Maytrix</code> &#124; <code>\*</code> | | |
| [defaultValue] | <code>\*</code> | <code>0</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be filled with zeros. |
<a name="SparseMatrix+get"></a>
### sparseMatrix.get(index) ⇒ <code>\*</code>
Get a single element from the matrix.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>\*</code> - value
| Param | Type | Description |
| --- | --- | --- |
| index | <code>Array.&lt;number&gt;</code> | Zero-based index |
<a name="SparseMatrix+set"></a>
### sparseMatrix.set(index, value, [defaultValue]) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
Replace a single element in the matrix.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>[SparseMatrix](#SparseMatrix)</code> - self
| Param | Type | Description |
| --- | --- | --- |
| index | <code>Array.&lt;number&gt;</code> | Zero-based index |
| value | <code>\*</code> | |
| [defaultValue] | <code>\*</code> | Default value, filled in on new entries when the matrix is resized. If not provided, new matrix elements will be set to zero. |
<a name="SparseMatrix+resize"></a>
### sparseMatrix.resize(size, [defaultValue], [copy]) ⇒ <code>Matrix</code>
Resize the matrix to the given size. Returns a copy of the matrix when
`copy=true`, otherwise return the matrix itself (resize in place).
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>Matrix</code> - The resized matrix
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| size | <code>Array.&lt;number&gt;</code> | | The new size the matrix should have. |
| [defaultValue] | <code>\*</code> | <code>0</code> | Default value, filled in on new entries. If not provided, the matrix elements will be filled with zeros. |
| [copy] | <code>boolean</code> | | Return a resized copy of the matrix |
<a name="SparseMatrix+clone"></a>
### sparseMatrix.clone() ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
Create a clone of the matrix
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>[SparseMatrix](#SparseMatrix)</code> - clone
<a name="SparseMatrix+size"></a>
### sparseMatrix.size() ⇒ <code>Array.&lt;number&gt;</code>
Retrieve the size of the matrix.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>Array.&lt;number&gt;</code> - size
<a name="SparseMatrix+map"></a>
### sparseMatrix.map(callback, [skipZeros]) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
Create a new matrix with the results of the callback function executed on
each entry of the matrix.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>[SparseMatrix](#SparseMatrix)</code> - matrix
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
| [skipZeros] | <code>boolean</code> | Invoke callback function for non-zero values only. |
<a name="SparseMatrix+forEach"></a>
### sparseMatrix.forEach(callback, [skipZeros])
Execute a callback function on each entry of the matrix.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
| Param | Type | Description |
| --- | --- | --- |
| callback | <code>function</code> | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix being traversed. |
| [skipZeros] | <code>boolean</code> | Invoke callback function for non-zero values only. |
<a name="SparseMatrix+toArray"></a>
### sparseMatrix.toArray() ⇒ <code>Array</code>
Create an Array with a copy of the data of the SparseMatrix
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>Array</code> - array
<a name="SparseMatrix+valueOf"></a>
### sparseMatrix.valueOf() ⇒ <code>Array</code>
Get the primitive value of the SparseMatrix: a two dimensions array
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>Array</code> - array
<a name="SparseMatrix+format"></a>
### sparseMatrix.format([options]) ⇒ <code>string</code>
Get a string representation of the matrix, with optional formatting options.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>string</code> - str
| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> &#124; <code>number</code> &#124; <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. |
<a name="SparseMatrix+toString"></a>
### sparseMatrix.toString() ⇒ <code>string</code>
Get a string representation of the matrix
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>string</code> - str
<a name="SparseMatrix+toJSON"></a>
### sparseMatrix.toJSON() ⇒ <code>Object</code>
Get a JSON representation of the matrix
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
<a name="SparseMatrix+diagonal"></a>
### sparseMatrix.diagonal([k]) ⇒ <code>Matrix</code>
Get the kth Matrix diagonal.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>Matrix</code> - The matrix vector with the diagonal values.
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [k] | <code>number</code> &#124; <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will retrieved. |
<a name="SparseMatrix+swapRows"></a>
### sparseMatrix.swapRows(i, j) ⇒ <code>Matrix</code>
Swap rows i and j in Matrix.
**Kind**: instance method of <code>[SparseMatrix](#SparseMatrix)</code>
**Returns**: <code>Matrix</code> - The matrix reference
| Param | Type | Description |
| --- | --- | --- |
| i | <code>number</code> | Matrix row index 1 |
| j | <code>number</code> | Matrix row index 2 |
<a name="SparseMatrix.fromJSON"></a>
### SparseMatrix.fromJSON(json) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
Generate a matrix from a JSON object
**Kind**: static method of <code>[SparseMatrix](#SparseMatrix)</code>
| Param | Type | Description |
| --- | --- | --- |
| json | <code>Object</code> | An object structured like `{"mathjs": "SparseMatrix", "values": [], "index": [], "ptr": [], "size": []}`, where mathjs is optional |
<a name="SparseMatrix.diagonal"></a>
### SparseMatrix.diagonal(size, value, [k], [datatype]) ⇒ <code>[SparseMatrix](#SparseMatrix)</code>
Create a diagonal matrix.
**Kind**: static method of <code>[SparseMatrix](#SparseMatrix)</code>
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| size | <code>Array</code> | | The matrix size. |
| value | <code>number</code> &#124; <code>Array</code> &#124; <code>Matrix</code> | | The values for the diagonal. |
| [k] | <code>number</code> &#124; <code>BigNumber</code> | <code>0</code> | The kth diagonal where the vector will be filled in. |
| [datatype] | <code>string</code> | | The Matrix datatype, values must be of this datatype. |

View File

@@ -0,0 +1,242 @@
<a name="Unit"></a>
## Unit
* [new Unit([value], [name])](#new_Unit_new)
* _instance_
* [.valueOf](#Unit+valueOf) ⇒ <code>string</code>
* [.clone()](#Unit+clone) ⇒ <code>Unit</code>
* [._isDerived()](#Unit+_isDerived) ⇒ <code>boolean</code>
* [.hasBase(base)](#Unit+hasBase)
* [.equalBase(other)](#Unit+equalBase) ⇒ <code>boolean</code>
* [.equals(other)](#Unit+equals) ⇒ <code>boolean</code>
* [.multiply(other)](#Unit+multiply) ⇒ <code>Unit</code>
* [.divide(other)](#Unit+divide) ⇒ <code>Unit</code>
* [.pow(p)](#Unit+pow) ⇒ <code>Unit</code>
* [.abs(x)](#Unit+abs) ⇒ <code>Unit</code>
* [.to(valuelessUnit)](#Unit+to) ⇒ <code>Unit</code>
* [.toNumber(valuelessUnit)](#Unit+toNumber) ⇒ <code>number</code>
* [.toNumeric(valuelessUnit)](#Unit+toNumeric) ⇒ <code>number</code> &#124; <code>BigNumber</code> &#124; <code>Fraction</code>
* [.toString()](#Unit+toString) ⇒ <code>string</code>
* [.toJSON()](#Unit+toJSON) ⇒ <code>Object</code>
* [.formatUnits()](#Unit+formatUnits) ⇒ <code>string</code>
* [.format([options])](#Unit+format) ⇒ <code>string</code>
* _static_
* [.parse(str)](#Unit.parse) ⇒ <code>Unit</code>
* [.isValuelessUnit(name)](#Unit.isValuelessUnit) ⇒ <code>boolean</code>
* [.fromJSON(json)](#Unit.fromJSON) ⇒ <code>Unit</code>
<a name="new_Unit_new"></a>
### new Unit([value], [name])
A unit can be constructed in the following ways:
```js
var a = new Unit(value, name);
var b = new Unit(null, name);
var c = Unit.parse(str);
```
Example usage:
```js
var a = new Unit(5, 'cm'); // 50 mm
var b = Unit.parse('23 kg'); // 23 kg
var c = math.in(a, new Unit(null, 'm'); // 0.05 m
var d = new Unit(9.81, "m/s^2"); // 9.81 m/s^2
```
| Param | Type | Description |
| --- | --- | --- |
| [value] | <code>number</code> &#124; <code>BigNumber</code> &#124; <code>Fraction</code> &#124; <code>Complex</code> &#124; <code>boolean</code> | A value like 5.2 |
| [name] | <code>string</code> | A unit name like "cm" or "inch", or a derived unit of the form: "u1[^ex1] [u2[^ex2] ...] [/ u3[^ex3] [u4[^ex4]]]", such as "kg m^2/s^2", where each unit appearing after the forward slash is taken to be in the denominator. "kg m^2 s^-2" is a synonym and is also acceptable. Any of the units can include a prefix. |
<a name="Unit+valueOf"></a>
### unit.valueOf ⇒ <code>string</code>
Returns the string representation of the unit.
**Kind**: instance property of <code>Unit</code>
<a name="Unit+clone"></a>
### unit.clone() ⇒ <code>Unit</code>
create a copy of this unit
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>Unit</code> - Returns a cloned version of the unit
<a name="Unit+_isDerived"></a>
### unit._isDerived() ⇒ <code>boolean</code>
Return whether the unit is derived (such as m/s, or cm^2, but not N)
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>boolean</code> - True if the unit is derived
<a name="Unit+hasBase"></a>
### unit.hasBase(base)
check if this unit has given base unit
If this unit is a derived unit, this will ALWAYS return false, since by definition base units are not derived.
**Kind**: instance method of <code>Unit</code>
| Param | Type |
| --- | --- |
| base | <code>BASE_UNITS</code> &#124; <code>STRING</code> &#124; <code>undefined</code> |
<a name="Unit+equalBase"></a>
### unit.equalBase(other) ⇒ <code>boolean</code>
Check if this unit has a base or bases equal to another base or bases
For derived units, the exponent on each base also must match
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>boolean</code> - true if equal base
| Param | Type |
| --- | --- |
| other | <code>Unit</code> |
<a name="Unit+equals"></a>
### unit.equals(other) ⇒ <code>boolean</code>
Check if this unit equals another unit
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>boolean</code> - true if both units are equal
| Param | Type |
| --- | --- |
| other | <code>Unit</code> |
<a name="Unit+multiply"></a>
### unit.multiply(other) ⇒ <code>Unit</code>
Multiply this unit with another one
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>Unit</code> - product of this unit and the other unit
| Param | Type |
| --- | --- |
| other | <code>Unit</code> |
<a name="Unit+divide"></a>
### unit.divide(other) ⇒ <code>Unit</code>
Divide this unit by another one
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>Unit</code> - result of dividing this unit by the other unit
| Param | Type |
| --- | --- |
| other | <code>Unit</code> |
<a name="Unit+pow"></a>
### unit.pow(p) ⇒ <code>Unit</code>
Calculate the power of a unit
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>Unit</code> - The result: this^p
| Param | Type |
| --- | --- |
| p | <code>number</code> &#124; <code>Fraction</code> &#124; <code>BigNumber</code> |
<a name="Unit+abs"></a>
### unit.abs(x) ⇒ <code>Unit</code>
Calculate the absolute value of a unit
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>Unit</code> - The result: |x|, absolute value of x
| Param | Type |
| --- | --- |
| x | <code>number</code> &#124; <code>Fraction</code> &#124; <code>BigNumber</code> |
<a name="Unit+to"></a>
### unit.to(valuelessUnit) ⇒ <code>Unit</code>
Convert the unit to a specific unit name.
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>Unit</code> - Returns a clone of the unit with a fixed prefix and unit.
| Param | Type | Description |
| --- | --- | --- |
| valuelessUnit | <code>string</code> &#124; <code>Unit</code> | A unit without value. Can have prefix, like "cm" |
<a name="Unit+toNumber"></a>
### unit.toNumber(valuelessUnit) ⇒ <code>number</code>
Return the value of the unit when represented with given valueless unit
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>number</code> - Returns the unit value as number.
| Param | Type | Description |
| --- | --- | --- |
| valuelessUnit | <code>string</code> &#124; <code>Unit</code> | For example 'cm' or 'inch' |
<a name="Unit+toNumeric"></a>
### unit.toNumeric(valuelessUnit) ⇒ <code>number</code> &#124; <code>BigNumber</code> &#124; <code>Fraction</code>
Return the value of the unit in the original numeric type
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>number</code> &#124; <code>BigNumber</code> &#124; <code>Fraction</code> - Returns the unit value
| Param | Type | Description |
| --- | --- | --- |
| valuelessUnit | <code>string</code> &#124; <code>Unit</code> | For example 'cm' or 'inch' |
<a name="Unit+toString"></a>
### unit.toString() ⇒ <code>string</code>
Get a string representation of the unit.
**Kind**: instance method of <code>Unit</code>
<a name="Unit+toJSON"></a>
### unit.toJSON() ⇒ <code>Object</code>
Get a JSON representation of the unit
**Kind**: instance method of <code>Unit</code>
**Returns**: <code>Object</code> - Returns a JSON object structured as:
`{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false}`
<a name="Unit+formatUnits"></a>
### unit.formatUnits() ⇒ <code>string</code>
Get a string representation of the units of this Unit, without the value.
**Kind**: instance method of <code>Unit</code>
<a name="Unit+format"></a>
### unit.format([options]) ⇒ <code>string</code>
Get a string representation of the Unit, with optional formatting options.
**Kind**: instance method of <code>Unit</code>
| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>Object</code> &#124; <code>number</code> &#124; <code>function</code> | Formatting options. See lib/utils/number:format for a description of the available options. |
<a name="Unit.parse"></a>
### Unit.parse(str) ⇒ <code>Unit</code>
Parse a string into a unit. The value of the unit is parsed as number,
BigNumber, or Fraction depending on the math.js config setting `number`.
Throws an exception if the provided string does not contain a valid unit or
cannot be parsed.
**Kind**: static method of <code>Unit</code>
**Returns**: <code>Unit</code> - unit
| Param | Type | Description |
| --- | --- | --- |
| str | <code>string</code> | A string like "5.2 inch", "4e2 cm/s^2" |
<a name="Unit.isValuelessUnit"></a>
### Unit.isValuelessUnit(name) ⇒ <code>boolean</code>
Test if the given expression is a unit.
The unit can have a prefix but cannot have a value.
**Kind**: static method of <code>Unit</code>
**Returns**: <code>boolean</code> - true if the given string is a unit
| Param | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | A string to be tested whether it is a value less unit. The unit can have prefix, like "cm" |
<a name="Unit.fromJSON"></a>
### Unit.fromJSON(json) ⇒ <code>Unit</code>
Instantiate a Unit from a JSON object
**Kind**: static method of <code>Unit</code>
| Param | Type | Description |
| --- | --- | --- |
| json | <code>Object</code> | A JSON object structured as: `{"mathjs": "Unit", "value": 2, "unit": "cm", "fixPrefix": false}` |

View File

@@ -0,0 +1,29 @@
# Constant reference
Math.js contains the following constants.
Constant | Description | Value
--------------- | ----------- | -----
`e`, `E` | Euler's number, the base of the natural logarithm. | 2.718281828459045
`i` | Imaginary unit, defined as i*i=-1. A complex number is described as a + b*i, where a is the real part, and b is the imaginary part. | `sqrt(-1)`
`Infinity` | Infinity, a number which is larger than the maximum number that can be handled by a floating point number. | `Infinity`
`LN2` | Returns the natural logarithm of 2. | `0.6931471805599453`
`LN10` | Returns the natural logarithm of 10. | `2.302585092994046`
`LOG2E` | Returns the base-2 logarithm of E. | `1.4426950408889634`
`LOG10E` | Returns the base-10 logarithm of E. | `0.4342944819032518`
`NaN` | Not a number. | `NaN`
`null` | Value null. | `null`
`phi` | Phi is the golden ratio. Two quantities are in the golden ratio if their ratio is the same as the ratio of their sum to the larger of the two quantities. Phi is defined as `(1 + sqrt(5)) / 2` | `1.618033988749895`
`pi`, `PI` | The number pi is a mathematical constant that is the ratio of a circle\'s circumference to its diameter. | `3.141592653589793`
`SQRT1_2` | Returns the square root of 1/2. | `0.7071067811865476`
`SQRT2` | Returns the square root of 2. | `1.4142135623730951`
`tau` | Tau is the ratio constant of a circle\'s circumference to radius, equal to `2 * pi`. | `6.283185307179586`
`uninitialized` | Constant used as default value when resizing a matrix to leave new entries uninitialized.
`version` | Returns the version number of math.js. | For example `0.24.1`
Example usage:
```js
math.sin(math.pi / 4); // 0.70711
math.multiply(math.i, math.i); // -1
```

View File

@@ -0,0 +1,267 @@
# Function reference
## Core functions
Function | Description
---- | -----------
[math.config(config:&nbsp;Object):&nbsp;Object](functions/config.md) | Set configuration options for math.
[math.typed(name,&nbsp;signatures)&nbsp;:&nbsp;function](functions/typed.md) | Create a typed-function which checks the types of the arguments and can match them against multiple provided signatures.
## Construction functions
Function | Description
---- | -----------
[math.bignumber(x)](functions/bignumber.md) | Create a BigNumber, which can store numbers with arbitrary precision.
[math.boolean(x)](functions/boolean.md) | Create a boolean or convert a string or number to a boolean.
[math.chain(value)](functions/chain.md) | Wrap any value in a chain, allowing to perform chained operations on the value.
[math.complex(re,&nbsp;im)](functions/complex.md) | Create a complex value or convert a value to a complex value.
[math.createUnit(units)](functions/createUnit.md) | Create a user-defined unit and register it with the Unit type.
[math.fraction(numerator,&nbsp;denominator)](functions/fraction.md) | Create a fraction convert a value to a fraction.
[math.index(range1,&nbsp;range2,&nbsp;...)](functions/index.md) | Create an index.
[math.matrix(x)](functions/matrix.md) | Create a Matrix.
[math.number(value)](functions/number.md) | Create a number or convert a string, boolean, or unit to a number.
[math.sparse(x)](functions/sparse.md) | Create a Sparse Matrix.
[math.splitUnit(unit,&nbsp;parts)](functions/splitUnit.md) | Split a unit in an array of units whose sum is equal to the original unit.
[math.string(value)](functions/string.md) | Create a string or convert any object into a string.
[math.unit(x)](functions/unit.md) | Create a unit.
## Expression functions
Function | Description
---- | -----------
[math.compile(expr)](functions/compile.md) | Parse and compile an expression.
[math.eval(expr&nbsp;[,&nbsp;scope])](functions/eval.md) | Evaluate an expression.
[math.help(search)](functions/help.md) | Retrieve help on a function or data type.
[math.parse(expr&nbsp;[,&nbsp;scope])](functions/parse.md) | Parse an expression.
[math.parser()](functions/parser.md) | Create a parser.
## Algebra functions
Function | Description
---- | -----------
[derivative(expr,&nbsp;variable)](functions/derivative.md) | Takes the derivative of an expression expressed in parser Nodes.
[math.lsolve(L,&nbsp;b)](functions/lsolve.md) | Solves the linear equation system by forwards substitution.
[math.lup(A)](functions/lup.md) | Calculate the Matrix LU decomposition with partial pivoting.
[math.lusolve(A,&nbsp;b)](functions/lusolve.md) | Solves the linear system `A * x = b` where `A` is an [n x n] matrix and `b` is a [n] column vector.
[simplify(expr)](functions/simplify.md) | Simplify an expression tree.
[math.slu(A,&nbsp;order,&nbsp;threshold)](functions/slu.md) | Calculate the Sparse Matrix LU decomposition with full pivoting.
[math.usolve(U,&nbsp;b)](functions/usolve.md) | Solves the linear equation system by backward substitution.
## Arithmetic functions
Function | Description
---- | -----------
[math.abs(x)](functions/abs.md) | Calculate the absolute value of a number.
[math.add(x,&nbsp;y)](functions/add.md) | Add two or more values, `x + y`.
[math.cbrt(x&nbsp;[,&nbsp;allRoots])](functions/cbrt.md) | Calculate the cubic root of a value.
[math.ceil(x)](functions/ceil.md) | Round a value towards plus infinity If `x` is complex, both real and imaginary part are rounded towards plus infinity.
[math.cube(x)](functions/cube.md) | Compute the cube of a value, `x * x * x`.
[math.divide(x,&nbsp;y)](functions/divide.md) | Divide two values, `x / y`.
[math.dotDivide(x,&nbsp;y)](functions/dotDivide.md) | Divide two matrices element wise.
[math.dotMultiply(x,&nbsp;y)](functions/dotMultiply.md) | Multiply two matrices element wise.
[math.dotPow(x,&nbsp;y)](functions/dotPow.md) | Calculates the power of x to y element wise.
[math.exp(x)](functions/exp.md) | Calculate the exponent of a value.
[math.fix(x)](functions/fix.md) | Round a value towards zero.
[math.floor(x)](functions/floor.md) | Round a value towards minus infinity.
[math.gcd(a,&nbsp;b)](functions/gcd.md) | Calculate the greatest common divisor for two or more values or arrays.
[math.hypot(a,&nbsp;b,&nbsp;...)](functions/hypot.md) | Calculate the hypotenusa of a list with values.
[math.lcm(a,&nbsp;b)](functions/lcm.md) | Calculate the least common multiple for two or more values or arrays.
[math.log(x&nbsp;[,&nbsp;base])](functions/log.md) | Calculate the logarithm of a value.
[math.log10(x)](functions/log10.md) | Calculate the 10-base logarithm of a value.
[math.mod(x,&nbsp;y)](functions/mod.md) | Calculates the modulus, the remainder of an integer division.
[math.multiply(x,&nbsp;y)](functions/multiply.md) | Multiply two or more values, `x * y`.
[math.norm(x&nbsp;[,&nbsp;p])](functions/norm.md) | Calculate the norm of a number, vector or matrix.
[math.nthRoot(a)](functions/nthRoot.md) | Calculate the nth root of a value.
[math.pow(x,&nbsp;y)](functions/pow.md) | Calculates the power of x to y, `x ^ y`.
[math.round(x&nbsp;[,&nbsp;n])](functions/round.md) | Round a value towards the nearest integer.
[math.sign(x)](functions/sign.md) | Compute the sign of a value.
[math.sqrt(x)](functions/sqrt.md) | Calculate the square root of a value.
[math.square(x)](functions/square.md) | Compute the square of a value, `x * x`.
[math.subtract(x,&nbsp;y)](functions/subtract.md) | Subtract two values, `x - y`.
[math.unaryMinus(x)](functions/unaryMinus.md) | Inverse the sign of a value, apply a unary minus operation.
[math.unaryPlus(x)](functions/unaryPlus.md) | Unary plus operation.
[math.xgcd(a,&nbsp;b)](functions/xgcd.md) | Calculate the extended greatest common divisor for two values.
## Bitwise functions
Function | Description
---- | -----------
[math.bitAnd(x,&nbsp;y)](functions/bitAnd.md) | Bitwise AND two values, `x & y`.
[math.bitNot(x)](functions/bitNot.md) | Bitwise NOT value, `~x`.
[math.bitOr(x,&nbsp;y)](functions/bitOr.md) | Bitwise OR two values, `x | y`.
[math.bitXor(x,&nbsp;y)](functions/bitXor.md) | Bitwise XOR two values, `x ^ y`.
[math.leftShift(x,&nbsp;y)](functions/leftShift.md) | Bitwise left logical shift of a value x by y number of bits, `x << y`.
[math.rightArithShift(x,&nbsp;y)](functions/rightArithShift.md) | Bitwise right arithmetic shift of a value x by y number of bits, `x >> y`.
[math.rightLogShift(x,&nbsp;y)](functions/rightLogShift.md) | Bitwise right logical shift of value x by y number of bits, `x >>> y`.
## Combinatorics functions
Function | Description
---- | -----------
[math.bellNumbers(n)](functions/bellNumbers.md) | The Bell Numbers count the number of partitions of a set.
[math.catalan(n)](functions/catalan.md) | The Catalan Numbers enumerate combinatorial structures of many different types.
[math.composition(n,&nbsp;k)](functions/composition.md) | The composition counts of n into k parts.
[math.stirlingS2(n,&nbsp;k)](functions/stirlingS2.md) | The Stirling numbers of the second kind, counts the number of ways to partition a set of n labelled objects into k nonempty unlabelled subsets.
## Complex functions
Function | Description
---- | -----------
[math.arg(x)](functions/arg.md) | Compute the argument of a complex value.
[math.conj(x)](functions/conj.md) | Compute the complex conjugate of a complex value.
[math.im(x)](functions/im.md) | Get the imaginary part of a complex number.
[math.re(x)](functions/re.md) | Get the real part of a complex number.
## Geometry functions
Function | Description
---- | -----------
[math.distance([x1,&nbsp;y1],&nbsp;[x2,&nbsp;y2])](functions/distance.md) | Calculates: The eucledian distance between two points in 2 and 3 dimensional spaces.
[math.intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)](functions/intersect.md) | Calculates the point of intersection of two lines in two or three dimensions and of a line and a plane in three dimensions.
## Logical functions
Function | Description
---- | -----------
[math.and(x,&nbsp;y)](functions/and.md) | Logical `and`.
[math.not(x)](functions/not.md) | Logical `not`.
[math.or(x,&nbsp;y)](functions/or.md) | Logical `or`.
[math.xor(x,&nbsp;y)](functions/xor.md) | Logical `xor`.
## Matrix functions
Function | Description
---- | -----------
[math.concat(a,&nbsp;b,&nbsp;c,&nbsp;...&nbsp;[,&nbsp;dim])](functions/concat.md) | Concatenate two or more matrices.
[math.cross(x,&nbsp;y)](functions/cross.md) | Calculate the cross product for two vectors in three dimensional space.
[math.det(x)](functions/det.md) | Calculate the determinant of a matrix.
[math.diag(X)](functions/diag.md) | Create a diagonal matrix or retrieve the diagonal of a matrix When `x` is a vector, a matrix with vector `x` on the diagonal will be returned.
[math.dot(x,&nbsp;y)](functions/dot.md) | Calculate the dot product of two vectors.
[math.eye(n)](functions/eye.md) | Create a 2-dimensional identity matrix with size m x n or n x n.
[math.filter(x,&nbsp;test)](functions/filter.md) | Filter the items in an array or one dimensional matrix.
[math.flatten(x)](functions/flatten.md) | Flatten a multi dimensional matrix into a single dimensional matrix.
[math.forEach(x,&nbsp;callback)](functions/forEach.md) | Iterate over all elements of a matrix/array, and executes the given callback function.
[math.inv(x)](functions/inv.md) | Calculate the inverse of a square matrix.
[math.kron(x,&nbsp;y)](functions/kron.md) | Calculates the kronecker product of 2 matrices or vectors.
[math.map(x,&nbsp;callback)](functions/map.md) | Create a new matrix or array with the results of the callback function executed on each entry of the matrix/array.
[math.ones(m,&nbsp;n,&nbsp;p,&nbsp;...)](functions/ones.md) | Create a matrix filled with ones.
[math.partitionSelect(x,&nbsp;k)](functions/partitionSelect.md) | Partition-based selection of an array or 1D matrix.
[math.range(start,&nbsp;end&nbsp;[,&nbsp;step])](functions/range.md) | Create an array from a range.
[math.resize(x,&nbsp;size&nbsp;[,&nbsp;defaultValue])](functions/resize.md) | Resize a matrix.
[math.size(x)](functions/size.md) | Calculate the size of a matrix or scalar.
[math.sort(x)](functions/sort.md) | Sort the items in a matrix.
[math.squeeze(x)](functions/squeeze.md) | Squeeze a matrix, remove inner and outer singleton dimensions from a matrix.
[math.subset(x,&nbsp;index&nbsp;[,&nbsp;replacement])](functions/subset.md) | Get or set a subset of a matrix or string.
[math.trace(x)](functions/trace.md) | Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.
[math.transpose(x)](functions/transpose.md) | Transpose a matrix.
[math.zeros(m,&nbsp;n,&nbsp;p,&nbsp;...)](functions/zeros.md) | Create a matrix filled with zeros.
## Probability functions
Function | Description
---- | -----------
[math.combinations(n,&nbsp;k)](functions/combinations.md) | Compute the number of ways of picking `k` unordered outcomes from `n` possibilities.
[math.factorial(n)](functions/factorial.md) | Compute the factorial of a value Factorial only supports an integer value as argument.
[math.gamma(n)](functions/gamma.md) | Compute the gamma function of a value using Lanczos approximation for small values, and an extended Stirling approximation for large values.
[math.kldivergence(x,&nbsp;y)](functions/kldivergence.md) | Calculate the Kullback-Leibler (KL) divergence between two distributions.
[math.multinomial(a)](functions/multinomial.md) | Multinomial Coefficients compute the number of ways of picking a1, a2, .
[math.permutations(n&nbsp;[,&nbsp;k])](functions/permutations.md) | Compute the number of ways of obtaining an ordered subset of `k` elements from a set of `n` elements.
[math.pickRandom(array)](functions/pickRandom.md) | Random pick one or more values from a one dimensional array.
[math.random([min,&nbsp;max])](functions/random.md) | Return a random number larger or equal to `min` and smaller than `max` using a uniform distribution.
[math.randomInt([min,&nbsp;max])](functions/randomInt.md) | Return a random integer number larger or equal to `min` and smaller than `max` using a uniform distribution.
## Relational functions
Function | Description
---- | -----------
[math.compare(x,&nbsp;y)](functions/compare.md) | Compare two values.
[math.deepEqual(x,&nbsp;y)](functions/deepEqual.md) | Test element wise whether two matrices are equal.
[math.equal(x,&nbsp;y)](functions/equal.md) | Test whether two values are equal.
[math.larger(x,&nbsp;y)](functions/larger.md) | Test whether value x is larger than y.
[math.largerEq(x,&nbsp;y)](functions/largerEq.md) | Test whether value x is larger or equal to y.
[math.smaller(x,&nbsp;y)](functions/smaller.md) | Test whether value x is smaller than y.
[math.smallerEq(x,&nbsp;y)](functions/smallerEq.md) | Test whether value x is smaller or equal to y.
[math.unequal(x,&nbsp;y)](functions/unequal.md) | Test whether two values are unequal.
## Special functions
Function | Description
---- | -----------
[math.erf(x)](functions/erf.md) | Compute the erf function of a value using a rational Chebyshev approximations for different intervals of x.
## Statistics functions
Function | Description
---- | -----------
[math.mad(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/mad.md) | Compute the median absolute deviation of a matrix or a list with values.
[math.max(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/max.md) | Compute the maximum value of a matrix or a list with values.
[math.mean(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/mean.md) | Compute the mean value of matrix or a list with values.
[math.median(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/median.md) | Compute the median of a matrix or a list with values.
[math.min(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/min.md) | Compute the maximum value of a matrix or a list of values.
[math.mode(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/mode.md) | Computes the mode of a set of numbers or a list with values(numbers or characters).
[math.prod(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/prod.md) | Compute the product of a matrix or a list with values.
[math.quantileSeq(A,&nbsp;prob[,&nbsp;sorted])](functions/quantileSeq.md) | Compute the prob order quantile of a matrix or a list with values.
[math.std(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/std.md) | Compute the standard deviation of a matrix or a list with values.
[math.sum(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/sum.md) | Compute the sum of a matrix or a list with values.
[math.var(a,&nbsp;b,&nbsp;c,&nbsp;...)](functions/var.md) | Compute the variance of a matrix or a list with values.
## String functions
Function | Description
---- | -----------
[math.format(value&nbsp;[,&nbsp;precision])](functions/format.md) | Format a value of any type into a string.
[math.print(template, values [, precision])](functions/print.md) | Interpolate values into a string template.
## Trigonometry functions
Function | Description
---- | -----------
[math.acos(x)](functions/acos.md) | Calculate the inverse cosine of a value.
[math.acosh(x)](functions/acosh.md) | Calculate the hyperbolic arccos of a value, defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`.
[math.acot(x)](functions/acot.md) | Calculate the inverse cotangent of a value, defined as `acot(x) = atan(1/x)`.
[math.acoth(x)](functions/acoth.md) | Calculate the hyperbolic arccotangent of a value, defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
[math.acsc(x)](functions/acsc.md) | Calculate the inverse cosecant of a value, defined as `acsc(x) = asin(1/x)`.
[math.acsch(x)](functions/acsch.md) | Calculate the hyperbolic arccosecant of a value, defined as `acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))`.
[math.asec(x)](functions/asec.md) | Calculate the inverse secant of a value.
[math.asech(x)](functions/asech.md) | Calculate the hyperbolic arcsecant of a value, defined as `asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)`.
[math.asin(x)](functions/asin.md) | Calculate the inverse sine of a value.
[math.asinh(x)](functions/asinh.md) | Calculate the hyperbolic arcsine of a value, defined as `asinh(x) = ln(x + sqrt(x^2 + 1))`.
[math.atan(x)](functions/atan.md) | Calculate the inverse tangent of a value.
[math.atan2(y,&nbsp;x)](functions/atan2.md) | Calculate the inverse tangent function with two arguments, y/x.
[math.atanh(x)](functions/atanh.md) | Calculate the hyperbolic arctangent of a value, defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`.
[math.cos(x)](functions/cos.md) | Calculate the cosine of a value.
[math.cosh(x)](functions/cosh.md) | Calculate the hyperbolic cosine of a value, defined as `cosh(x) = 1/2 * (exp(x) + exp(-x))`.
[math.cot(x)](functions/cot.md) | Calculate the cotangent of a value.
[math.coth(x)](functions/coth.md) | Calculate the hyperbolic cotangent of a value, defined as `coth(x) = 1 / tanh(x)`.
[math.csc(x)](functions/csc.md) | Calculate the cosecant of a value, defined as `csc(x) = 1/sin(x)`.
[math.csch(x)](functions/csch.md) | Calculate the hyperbolic cosecant of a value, defined as `csch(x) = 1 / sinh(x)`.
[math.sec(x)](functions/sec.md) | Calculate the secant of a value, defined as `sec(x) = 1/cos(x)`.
[math.sech(x)](functions/sech.md) | Calculate the hyperbolic secant of a value, defined as `sech(x) = 1 / cosh(x)`.
[math.sin(x)](functions/sin.md) | Calculate the sine of a value.
[math.sinh(x)](functions/sinh.md) | Calculate the hyperbolic sine of a value, defined as `sinh(x) = 1/2 * (exp(x) - exp(-x))`.
[math.tan(x)](functions/tan.md) | Calculate the tangent of a value.
[math.tanh(x)](functions/tanh.md) | Calculate the hyperbolic tangent of a value, defined as `tanh(x) = (exp(2 * x) - 1) / (exp(2 * x) + 1)`.
## Unit functions
Function | Description
---- | -----------
[math.to(x,&nbsp;unit)](functions/to.md) | Change the unit of a value.
## Utils functions
Function | Description
---- | -----------
[math.clone(x)](functions/clone.md) | Clone an object.
[math.isInteger(x)](functions/isInteger.md) | Test whether a value is an integer number.
[math.isNaN(x)](functions/isNaN.md) | Test whether a value is NaN (not a number).
[math.isNegative(x)](functions/isNegative.md) | Test whether a value is negative: smaller than zero.
[math.isNumeric(x)](functions/isNumeric.md) | Test whether a value is an numeric value.
[math.isPositive(x)](functions/isPositive.md) | Test whether a value is positive: larger than zero.
[math.isPrime(x)](functions/isPrime.md) | Test whether a value is prime: has no divisors other than itself and one.
[math.isZero(x)](functions/isZero.md) | Test whether a value is zero.
[math.typeof(x)](functions/typeof.md) | Determine the type of a variable.
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function abs
Calculate the absolute value of a number. For matrices, the function is
evaluated element wise.
## Syntax
```js
math.abs(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix &#124; Unit | A number or matrix for which to get the absolute value
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix &#124; Unit | Absolute value of `x`
## Examples
```js
math.abs(3.5); // returns number 3.5
math.abs(-4.2); // returns number 4.2
math.abs([3, -5, -1, 0, 2]); // returns Array [3, 5, 1, 0, 2]
```
## See also
[sign](sign.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function acos
Calculate the inverse cosine of a value.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.acos(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | The arc cosine of x
## Examples
```js
math.acos(0.5); // returns number 1.0471975511965979
math.acos(math.cos(1.5)); // returns number 1.5
math.acos(2); // returns Complex 0 + 1.3169578969248166 i
```
## See also
[cos](cos.md),
[atan](atan.md),
[asin](asin.md)

View File

@@ -0,0 +1,41 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function acosh
Calculate the hyperbolic arccos of a value,
defined as `acosh(x) = ln(sqrt(x^2 - 1) + x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.acosh(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic arccosine of x
## Examples
```js
math.acosh(1.5); // returns 0.9624236501192069
```
## See also
[cosh](cosh.md),
[asinh](asinh.md),
[atanh](atanh.md)

View File

@@ -0,0 +1,42 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function acot
Calculate the inverse cotangent of a value, defined as `acot(x) = atan(1/x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.acot(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | The arc cotangent of x
## Examples
```js
math.acot(0.5); // returns number 0.4636476090008061
math.acot(math.cot(1.5)); // returns number 1.5
math.acot(2); // returns Complex 1.5707963267948966 -1.3169578969248166 i
```
## See also
[cot](cot.md),
[atan](atan.md)

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function acoth
Calculate the hyperbolic arccotangent of a value,
defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.acoth(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic arccotangent of x
## Examples
```js
math.acoth(0.5); // returns 0.8047189562170503
```
## See also
[acsch](acsch.md),
[asech](asech.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function acsc
Calculate the inverse cosecant of a value, defined as `acsc(x) = asin(1/x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.acsc(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | The arc cosecant of x
## Examples
```js
math.acsc(0.5); // returns number 0.5235987755982989
math.acsc(math.csc(1.5)); // returns number ~1.5
math.acsc(2); // returns Complex 1.5707963267948966 -1.3169578969248166 i
```
## See also
[csc](csc.md),
[asin](asin.md),
[asec](asec.md)

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function acsch
Calculate the hyperbolic arccosecant of a value,
defined as `acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.acsch(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic arccosecant of x
## Examples
```js
math.acsch(0.5); // returns 1.4436354751788103
```
## See also
[asech](asech.md),
[acoth](acoth.md)

View File

@@ -0,0 +1,53 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function add
Add two or more values, `x + y`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.add(x, y)
math.add(x, y, z, ...)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | First value to add
`y` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Second value to add
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Sum of `x` and `y`
## Examples
```js
math.add(2, 3); // returns number 5
math.add(2, 3, 4); // returns number 9
var a = math.complex(2, 3);
var b = math.complex(-4, 1);
math.add(a, b); // returns Complex -2 + 4i
math.add([1, 2, 3], 4); // returns Array [5, 6, 7]
var c = math.unit('5 cm');
var d = math.unit('2.1 mm');
math.add(c, d); // returns Unit 52.1 mm
math.add("2.3", "4"); // returns number 6.3
```
## See also
[subtract](subtract.md),
[sum](sum.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function and
Logical `and`. Test whether two values are both defined with a nonzero/nonempty value.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.and(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | First value to check
`y` | number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Second value to check
### Returns
Type | Description
---- | -----------
boolean &#124; Array &#124; Matrix | Returns true when both inputs are defined with a nonzero/nonempty value.
## Examples
```js
math.and(2, 4); // returns true
a = [2, 0, 0];
b = [3, 7, 0];
c = 0;
math.and(a, b); // returns [true, false, false]
math.and(a, c); // returns [false, false, false]
```
## See also
[not](not.md),
[or](or.md),
[xor](xor.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function arg
Compute the argument of a complex value.
For a complex number `a + bi`, the argument is computed as `atan2(b, a)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.arg(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | A complex number or array with complex numbers
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | The argument of x
## Examples
```js
var a = math.complex(2, 2);
math.arg(a) / math.pi; // returns number 0.25
var b = math.complex('2 + 3i');
math.arg(b); // returns number 0.982793723247329
math.atan2(3, 2); // returns number 0.982793723247329
```
## See also
[re](re.md),
[im](im.md),
[conj](conj.md),
[abs](abs.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function asec
Calculate the inverse secant of a value. Defined as `asec(x) = acos(1/x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.asec(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | The arc secant of x
## Examples
```js
math.asec(0.5); // returns 1.0471975511965979
math.asec(math.sec(1.5)); // returns 1.5
math.asec(2); // returns 0 + 1.3169578969248166 i
```
## See also
[acos](acos.md),
[acot](acot.md),
[acsc](acsc.md)

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function asech
Calculate the hyperbolic arcsecant of a value,
defined as `asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.asech(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic arcsecant of x
## Examples
```js
math.asech(0.5); // returns 1.3169578969248166
```
## See also
[acsch](acsch.md),
[acoth](acoth.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function asin
Calculate the inverse sine of a value.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.asin(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | The arc sine of x
## Examples
```js
math.asin(0.5); // returns number 0.5235987755982989
math.asin(math.sin(1.5)); // returns number ~1.5
math.asin(2); // returns Complex 1.5707963267948966 -1.3169578969248166 i
```
## See also
[sin](sin.md),
[atan](atan.md),
[acos](acos.md)

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function asinh
Calculate the hyperbolic arcsine of a value,
defined as `asinh(x) = ln(x + sqrt(x^2 + 1))`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.asinh(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic arcsine of x
## Examples
```js
math.asinh(0.5); // returns 0.48121182505960347
```
## See also
[acosh](acosh.md),
[atanh](atanh.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function atan
Calculate the inverse tangent of a value.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.atan(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | The arc tangent of x
## Examples
```js
math.atan(0.5); // returns number 0.4636476090008061
math.atan(math.tan(1.5)); // returns number 1.5
math.atan(2); // returns Complex 1.5707963267948966 -1.3169578969248166 i
```
## See also
[tan](tan.md),
[asin](asin.md),
[acos](acos.md)

View File

@@ -0,0 +1,50 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function atan2
Calculate the inverse tangent function with two arguments, y/x.
By providing two arguments, the right quadrant of the computed angle can be
determined.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.atan2(y, x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`y` | number &#124; Array &#124; Matrix | Second dimension
`x` | number &#124; Array &#124; Matrix | First dimension
### Returns
Type | Description
---- | -----------
number &#124; Array &#124; Matrix | Four-quadrant inverse tangent
## Examples
```js
math.atan2(2, 2) / math.pi; // returns number 0.25
var angle = math.unit(60, 'deg'); // returns Unit 60 deg
var x = math.cos(angle);
var y = math.sin(angle);
math.atan(2); // returns Complex 1.5707963267948966 -1.3169578969248166 i
```
## See also
[tan](tan.md),
[atan](atan.md),
[sin](sin.md),
[cos](cos.md)

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function atanh
Calculate the hyperbolic arctangent of a value,
defined as `atanh(x) = ln((1 + x)/(1 - x)) / 2`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.atanh(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic arctangent of x
## Examples
```js
math.atanh(0.5); // returns 0.5493061443340549
```
## See also
[acosh](acosh.md),
[asinh](asinh.md)

View File

@@ -0,0 +1,39 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function bellNumbers
The Bell Numbers count the number of partitions of a set. A partition is a pairwise disjoint subset of S whose union is S.
bellNumbers only takes integer arguments.
The following condition must be enforced: n >= 0
## Syntax
```js
math.bellNumbers(n)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`n` | Number &#124; BigNumber | Total number of objects in the set
### Returns
Type | Description
---- | -----------
Number &#124; BigNumber | B(n)
## Examples
```js
math.bellNumbers(3); // returns 5;
math.bellNumbers(8); // returns 4140;
```
## See also
[stirlingS2](stirlingS2.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function bignumber
Create a BigNumber, which can store numbers with arbitrary precision.
When a matrix is provided, all elements will be converted to BigNumber.
## Syntax
```js
math.bignumber(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`value` | number &#124; string &#124; Fraction &#124; BigNumber &#124; Array &#124; Matrix &#124; boolean &#124; null | Value for the big number, 0 by default.
### Returns
Type | Description
---- | -----------
BigNumber | The created bignumber
## Examples
```js
0.1 + 0.2; // returns number 0.30000000000000004
math.bignumber(0.1) + math.bignumber(0.2); // returns BigNumber 0.3
7.2e500; // returns number Infinity
math.bignumber('7.2e500'); // returns BigNumber 7.2e500
```
## See also
[boolean](boolean.md),
[complex](complex.md),
[index](index.md),
[matrix](matrix.md),
[string](string.md),
[unit](unit.md)

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function bitAnd
Bitwise AND two values, `x & y`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.bitAnd(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Array &#124; Matrix | First value to and
`y` | number &#124; BigNumber &#124; Array &#124; Matrix | Second value to and
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | AND of `x` and `y`
## Examples
```js
math.bitAnd(53, 131); // returns number 1
math.bitAnd([1, 12, 31], 42); // returns Array [0, 8, 10]
```
## See also
[bitNot](bitNot.md),
[bitOr](bitOr.md),
[bitXor](bitXor.md),
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function bitNot
Bitwise NOT value, `~x`.
For matrices, the function is evaluated element wise.
For units, the function is evaluated on the best prefix base.
## Syntax
```js
math.bitNot(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Array &#124; Matrix | Value to not
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | NOT of `x`
## Examples
```js
math.bitNot(1); // returns number -2
math.bitNot([2, -3, 4]); // returns Array [-3, 2, 5]
```
## See also
[bitAnd](bitAnd.md),
[bitOr](bitOr.md),
[bitXor](bitXor.md),
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)

View File

@@ -0,0 +1,46 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function bitOr
Bitwise OR two values, `x | y`.
For matrices, the function is evaluated element wise.
For units, the function is evaluated on the lowest print base.
## Syntax
```js
math.bitOr(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Array &#124; Matrix | First value to or
`y` | number &#124; BigNumber &#124; Array &#124; Matrix | Second value to or
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | OR of `x` and `y`
## Examples
```js
math.bitOr(1, 2); // returns number 3
math.bitOr([1, 2, 3], 4); // returns Array [5, 6, 7]
```
## See also
[bitAnd](bitAnd.md),
[bitNot](bitNot.md),
[bitXor](bitXor.md),
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function bitXor
Bitwise XOR two values, `x ^ y`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.bitXor(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Array &#124; Matrix | First value to xor
`y` | number &#124; BigNumber &#124; Array &#124; Matrix | Second value to xor
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | XOR of `x` and `y`
## Examples
```js
math.bitXor(1, 2); // returns number 3
math.bitXor([2, 3, 4], 4); // returns Array [6, 7, 0]
```
## See also
[bitAnd](bitAnd.md),
[bitNot](bitNot.md),
[bitOr](bitOr.md),
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)

View File

@@ -0,0 +1,50 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function boolean
Create a boolean or convert a string or number to a boolean.
In case of a number, `true` is returned for non-zero numbers, and `false` in
case of zero.
Strings can be `'true'` or `'false'`, or can contain a number.
When value is a matrix, all elements will be converted to boolean.
## Syntax
```js
math.boolean(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`value` | string &#124; number &#124; boolean &#124; Array &#124; Matrix &#124; null | A value of any type
### Returns
Type | Description
---- | -----------
boolean &#124; Array &#124; Matrix | The boolean value
## Examples
```js
math.boolean(0); // returns false
math.boolean(1); // returns true
math.boolean(-3); // returns true
math.boolean('true'); // returns true
math.boolean('false'); // returns false
math.boolean([1, 0, 1, 1]); // returns [true, false, true, true]
```
## See also
[bignumber](bignumber.md),
[complex](complex.md),
[index](index.md),
[matrix](matrix.md),
[string](string.md),
[unit](unit.md)

View File

@@ -0,0 +1,39 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function catalan
The Catalan Numbers enumerate combinatorial structures of many different types.
catalan only takes integer arguments.
The following condition must be enforced: n >= 0
## Syntax
```js
math.catalan(n)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`n` | Number &#124; BigNumber | nth Catalan number
### Returns
Type | Description
---- | -----------
Number &#124; BigNumber | Cn(n)
## Examples
```js
math.catalan(3); // returns 5;
math.catalan(8); // returns 1430;
```
## See also
[bellNumbers](bellNumbers.md)

View File

@@ -0,0 +1,54 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function cbrt
Calculate the cubic root of a value.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.cbrt(x)
math.cbrt(x, allRoots)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Value for which to calculate the cubic root.
`allRoots` | boolean | Optional, false by default. Only applicable when `x` is a number or complex number. If true, all complex roots are returned, if false (default) the principal root is returned.
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Returns the cubic root of `x`
## Examples
```js
math.cbrt(27); // returns 3
math.cube(3); // returns 27
math.cbrt(-64); // returns -4
math.cbrt(math.unit('27 m^3')); // returns Unit 3 m
math.cbrt([27, 64, 125]); // returns [3, 4, 5]
var x = math.complex('8i');
math.cbrt(x); // returns Complex 1.7320508075689 + i
math.cbrt(x, true); // returns Matrix [
// 1.7320508075689 + i
// -1.7320508075689 + i
// -2i
// ]
```
## See also
[square](square.md),
[sqrt](sqrt.md),
[cube](cube.md)

View File

@@ -0,0 +1,48 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function ceil
Round a value towards plus infinity
If `x` is complex, both real and imaginary part are rounded towards plus infinity.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.ceil(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Number to be rounded
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Rounded value
## Examples
```js
math.ceil(3.2); // returns number 4
math.ceil(3.8); // returns number 4
math.ceil(-4.2); // returns number -4
math.ceil(-4.7); // returns number -4
var c = math.complex(3.2, -2.7);
math.ceil(c); // returns Complex 4 - 2i
math.ceil([3.2, 3.8, -4.7]); // returns Array [4, 4, -4]
```
## See also
[floor](floor.md),
[fix](fix.md),
[round](round.md)

View File

@@ -0,0 +1,54 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function chain
Wrap any value in a chain, allowing to perform chained operations on
the value.
All methods available in the math.js library can be called upon the chain,
and then will be evaluated with the value itself as first argument.
The chain can be closed by executing `chain.done()`, which returns
the final value.
The chain has a number of special functions:
- `done()` Finalize the chain and return the chain's value.
- `valueOf()` The same as `done()`
- `toString()` Executes `math.format()` onto the chain's value, returning
a string representation of the value.
## Syntax
```js
math.chain(value)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`value` | * | A value of any type on which to start a chained operation.
### Returns
Type | Description
---- | -----------
math.type.Chain | The created chain
## Examples
```js
math.chain(3)
.add(4)
.subtract(2)
.done(); // 5
math.chain( [[1, 2], [3, 4]] )
.subset(math.index(0, 0), 8)
.multiply(3)
.done(); // [[24, 6], [9, 12]]
```

View File

@@ -0,0 +1,37 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function clone
Clone an object.
## Syntax
```js
math.clone(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | * | Object to be cloned
### Returns
Type | Description
---- | -----------
* | A clone of object x
## Examples
```js
math.clone(3.5); // returns number 3.5
math.clone(math.complex('2-4i'); // returns Complex 2 - 4i
math.clone(math.unit(45, 'deg')); // returns Unit 45 deg
math.clone([[1, 2], [3, 4]]); // returns Array [[1, 2], [3, 4]]
math.clone("hello world"); // returns string "hello world"
```

View File

@@ -0,0 +1,42 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function combinations
Compute the number of ways of picking `k` unordered outcomes from `n`
possibilities.
Combinations only takes integer arguments.
The following condition must be enforced: k <= n.
## Syntax
```js
math.combinations(n, k)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`n` | number &#124; BigNumber | Total number of objects in the set
`k` | number &#124; BigNumber | Number of objects in the subset
### Returns
Type | Description
---- | -----------
number &#124; BigNumber | Number of possible combinations.
## Examples
```js
math.combinations(7, 5); // returns 21
```
## See also
[permutations](permutations.md),
[factorial](factorial.md)

View File

@@ -0,0 +1,56 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function compare
Compare two values. Returns 1 when x > y, -1 when x < y, and 0 when x == y.
x and y are considered equal when the relative difference between x and y
is smaller than the configured epsilon. The function cannot be used to
compare values smaller than approximately 2.22e-16.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.compare(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Unit &#124; string &#124; Array &#124; Matrix | First value to compare
`y` | number &#124; BigNumber &#124; Fraction &#124; Unit &#124; string &#124; Array &#124; Matrix | Second value to compare
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Returns the result of the comparison: 1, 0 or -1.
## Examples
```js
math.compare(6, 1); // returns 1
math.compare(2, 3); // returns -1
math.compare(7, 7); // returns 0
var a = math.unit('5 cm');
var b = math.unit('40 mm');
math.compare(a, b); // returns 1
math.compare(2, [1, 2, 3]); // returns [1, 0, -1]
```
## See also
[equal](equal.md),
[unequal](unequal.md),
[smaller](smaller.md),
[smallerEq](smallerEq.md),
[larger](larger.md),
[largerEq](largerEq.md)

View File

@@ -0,0 +1,50 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function compile
Parse and compile an expression.
Returns a an object with a function `eval([scope])` to evaluate the
compiled expression.
## Syntax
```js
math.compile(expr) // returns one node
math.compile([expr1, expr2, expr3, ...]) // returns an array with nodes
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`expr` | string &#124; string[] &#124; Array &#124; Matrix | The expression to be compiled
### Returns
Type | Description
---- | -----------
{eval: Function} &#124; Array.&lt;{eval: Function}&gt; | code An object with the compiled expression
## Examples
```js
var code = math.compile('sqrt(3^2 + 4^2)');
code.eval(); // 5
var scope = {a: 3, b: 4}
var code = math.compile('a * b'); // 12
code.eval(scope); // 12
scope.a = 5;
code.eval(scope); // 20
var nodes = math.compile(['a = 3', 'b = 4', 'a * b']);
nodes[2].eval(); // 12
```
## See also
[parse](parse.md),
[eval](eval.md)

View File

@@ -0,0 +1,61 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function complex
Create a complex value or convert a value to a complex value.
## Syntax
```js
math.complex() // creates a complex value with zero
// as real and imaginary part.
math.complex(re : number, im : string) // creates a complex value with provided
// values for real and imaginary part.
math.complex(re : number) // creates a complex value with provided
// real value and zero imaginary part.
math.complex(complex : Complex) // clones the provided complex value.
math.complex(arg : string) // parses a string into a complex value.
math.complex(array : Array) // converts the elements of the array
// or matrix element wise into a
// complex value.
math.complex({re: number, im: number}) // creates a complex value with provided
// values for real an imaginary part.
math.complex({r: number, phi: number}) // creates a complex value with provided
// polar coordinates
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`args` | * &#124; Array &#124; Matrix | Arguments specifying the real and imaginary part of the complex number
### Returns
Type | Description
---- | -----------
Complex &#124; Array &#124; Matrix | Returns a complex value
## Examples
```js
var a = math.complex(3, -4); // a = Complex 3 - 4i
a.re = 5; // a = Complex 5 - 4i
var i = a.im; // Number -4;
var b = math.complex('2 + 6i'); // Complex 2 + 6i
var c = math.complex(); // Complex 0 + 0i
var d = math.add(a, b); // Complex 5 + 2i
```
## See also
[bignumber](bignumber.md),
[boolean](boolean.md),
[index](index.md),
[matrix](matrix.md),
[number](number.md),
[string](string.md),
[unit](unit.md)

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function composition
The composition counts of n into k parts.
composition only takes integer arguments.
The following condition must be enforced: k <= n.
## Syntax
```js
math.composition(n, k)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`n` | Number &#124; BigNumber | Total number of objects in the set
`k` | Number &#124; BigNumber | Number of objects in the subset
### Returns
Type | Description
---- | -----------
Number &#124; BigNumber | Returns the composition counts of n into k parts.
## Examples
```js
math.composition(5, 3); // returns 6
```
## See also
[combinations](combinations.md)

View File

@@ -0,0 +1,50 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function concat
Concatenate two or more matrices.
## Syntax
```js
math.concat(A, B, C, ...)
math.concat(A, B, C, ..., dim)
```
### Where
- `dim: number` is a zero-based dimension over which to concatenate the matrices.
By default the last dimension of the matrices.
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`args` | ... Array &#124; Matrix | Two or more matrices
### Returns
Type | Description
---- | -----------
Array &#124; Matrix | Concatenated matrix
## Examples
```js
var A = [[1, 2], [5, 6]];
var B = [[3, 4], [7, 8]];
math.concat(A, B); // returns [[1, 2, 3, 4], [5, 6, 7, 8]]
math.concat(A, B, 0); // returns [[1, 2], [5, 6], [3, 4], [7, 8]]
math.concat('hello', ' ', 'world'); // returns 'hello world'
```
## See also
[size](size.md),
[squeeze](squeeze.md),
[subset](subset.md),
[transpose](transpose.md)

View File

@@ -0,0 +1,37 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function config
Set configuration options for math.js, and get current options.
Will emit a 'config' event, with arguments (curr, prev).
## Syntax
```js
math.config(config: Object): Object
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`options` | Object | Available options: {number} epsilon Minimum relative difference between two compared values, used by all comparison functions. {string} matrix A string 'Matrix' (default) or 'Array'. {string} number A string 'number' (default), 'BigNumber', or 'Fraction' {number} precision The number of significant digits for BigNumbers. Not applicable for Numbers. {string} parenthesis How to display parentheses in LaTeX and string output.
### Returns
Type | Description
---- | -----------
Object | Returns the current configuration
## Examples
```js
math.config().number; // outputs 'number'
math.eval('0.4'); // outputs number 0.4
math.config({number: 'Fraction'});
math.eval('0.4'); // outputs Fraction 2/5
```

View File

@@ -0,0 +1,44 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function conj
Compute the complex conjugate of a complex value.
If `x = a+bi`, the complex conjugate of `x` is `a - bi`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.conj(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | A complex number or array with complex numbers
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | The complex conjugate of x
## Examples
```js
math.conj(math.complex('2 + 3i')); // returns Complex 2 - 3i
math.conj(math.complex('2 - 3i')); // returns Complex 2 + 3i
math.conj(math.complex('-5.2i')); // returns Complex 5.2i
```
## See also
[re](re.md),
[im](im.md),
[arg](arg.md),
[abs](abs.md)

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function cos
Calculate the cosine of a value.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.cos(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Cosine of x
## Examples
```js
math.cos(2); // returns number -0.4161468365471422
math.cos(math.pi / 4); // returns number 0.7071067811865475
math.cos(math.unit(180, 'deg')); // returns number -1
math.cos(math.unit(60, 'deg')); // returns number 0.5
var angle = 0.2;
math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2); // returns number ~1
```
## See also
[cos](cos.md),
[tan](tan.md)

View File

@@ -0,0 +1,40 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function cosh
Calculate the hyperbolic cosine of a value,
defined as `cosh(x) = 1/2 * (exp(x) + exp(-x))`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.cosh(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Hyperbolic cosine of x
## Examples
```js
math.cosh(0.5); // returns number 1.1276259652063807
```
## See also
[sinh](sinh.md),
[tanh](tanh.md)

View File

@@ -0,0 +1,41 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function cot
Calculate the cotangent of a value. Defined as `cot(x) = 1 / tan(x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.cot(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Cotangent of x
## Examples
```js
math.cot(2); // returns number -0.45765755436028577
1 / math.tan(2); // returns number -0.45765755436028577
```
## See also
[tan](tan.md),
[sec](sec.md),
[csc](csc.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function coth
Calculate the hyperbolic cotangent of a value,
defined as `coth(x) = 1 / tanh(x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.coth(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic cotangent of x
## Examples
```js
// coth(x) = 1 / tanh(x)
math.coth(2); // returns 1.0373147207275482
1 / math.tanh(2); // returns 1.0373147207275482
```
## See also
[sinh](sinh.md),
[tanh](tanh.md),
[cosh](cosh.md)

View File

@@ -0,0 +1,52 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function createUnit
Create a user-defined unit and register it with the Unit type.
## Syntax
```js
math.createUnit({
baseUnit1: {
aliases: [string, ...]
prefixes: object
},
unit2: {
definition: string,
aliases: [string, ...]
prefixes: object,
offset: number
},
unit3: string // Shortcut
})
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`name` | string | The name of the new unit. Must be unique. Example: 'knot'
`definition` | string, Unit | Definition of the unit in terms of existing units. For example, '0.514444444 m / s'.
`options` | Object | (optional) An object containing any of the following properties:
### Returns
Type | Description
---- | -----------
Unit | The new unit
## Examples
```js
math.createUnit('foo');
math.createUnit('knot', {definition: '0.514444444 m/s', aliases: ['knots', 'kt', 'kts']});
math.createUnit('mph', '1 mile/hour');
```
## See also
[unit](unit.md)

View File

@@ -0,0 +1,52 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function cross
Calculate the cross product for two vectors in three dimensional space.
The cross product of `A = [a1, a2, a3]` and `B = [b1, b2, b3]` is defined
as:
cross(A, B) = [
a2 * b3 - a3 * b2,
a3 * b1 - a1 * b3,
a1 * b2 - a2 * b1
]
If one of the input vectors has a dimension greater than 1, the output
vector will be a 1x3 (2-dimensional) matrix.
## Syntax
```js
math.cross(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Array &#124; Matrix | First vector
`y` | Array &#124; Matrix | Second vector
### Returns
Type | Description
---- | -----------
Array &#124; Matrix | Returns the cross product of `x` and `y`
## Examples
```js
math.cross([1, 1, 0], [0, 1, 1]); // Returns [1, -1, 1]
math.cross([3, -3, 1], [4, 9, 2]); // Returns [-15, -2, 39]
math.cross([2, 3, 4], [5, 6, 7]); // Returns [-3, 6, -3]
math.cross([[1, 2, 3]], [[4], [5], [6]]); // Returns [[-3, 6, -3]]
```
## See also
[dot](dot.md),
[multiply](multiply.md)

View File

@@ -0,0 +1,41 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function csc
Calculate the cosecant of a value, defined as `csc(x) = 1/sin(x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.csc(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Cosecant of x
## Examples
```js
math.csc(2); // returns number 1.099750170294617
1 / math.sin(2); // returns number 1.099750170294617
```
## See also
[sin](sin.md),
[sec](sec.md),
[cot](cot.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function csch
Calculate the hyperbolic cosecant of a value,
defined as `csch(x) = 1 / sinh(x)`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.csch(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Function input
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic cosecant of x
## Examples
```js
// csch(x) = 1/ sinh(x)
math.csch(0.5); // returns 1.9190347513349437
1 / math.sinh(0.5); // returns 1.9190347513349437
```
## See also
[sinh](sinh.md),
[sech](sech.md),
[coth](coth.md)

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function cube
Compute the cube of a value, `x * x * x`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.cube(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix &#124; Unit | Number for which to calculate the cube
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix &#124; Unit | Cube of x
## Examples
```js
math.cube(2); // returns number 8
math.pow(2, 3); // returns number 8
math.cube(4); // returns number 64
4 * 4 * 4; // returns number 64
math.cube([1, 2, 3, 4]); // returns Array [1, 8, 27, 64]
```
## See also
[multiply](multiply.md),
[square](square.md),
[pow](pow.md),
[cbrt](cbrt.md)

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function deepEqual
Test element wise whether two matrices are equal.
The function accepts both matrices and scalar values.
## Syntax
```js
math.deepEqual(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | First matrix to compare
`y` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Second matrix to compare
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Returns true when the input matrices have the same size and each of their elements is equal.
## Examples
```js
math.deepEqual(2, 4); // returns false
a = [2, 5, 1];
b = [2, 7, 1];
math.deepEqual(a, b); // returns false
math.equal(a, b); // returns [true, false, true]
```
## See also
[equal](equal.md),
[unequal](unequal.md)

View File

@@ -0,0 +1,55 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function derivative
Takes the derivative of an expression expressed in parser Nodes.
The derivative will be taken over the supplied variable in the
second parameter. If there are multiple variables in the expression,
it will return a partial derivative.
This uses rules of differentiation which can be found here:
- [Differentiation rules (Wikipedia)](http://en.wikipedia.org/wiki/Differentiation_rules)
## Syntax
```js
derivative(expr, variable)
derivative(expr, variable, options)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`expr` | Node &#124; string | The expression to differentiate
`variable` | SymbolNode &#124; string | The variable over which to differentiate
`options` | {simplify: boolean} | There is one option available, `simplify`, which is true by default. When false, output will not be simplified.
### Returns
Type | Description
---- | -----------
ConstantNode &#124; SymbolNode &#124; ParenthesisNode &#124; FunctionNode &#124; OperatorNode | The derivative of `expr`
## Examples
```js
math.derivative('x^2', 'x'); // Node {2 * x}
math.derivative('x^2', 'x', {simplify: false}); // Node {2 * 1 * x ^ (2 - 1)
math.derivative('sin(2x)', 'x')); // Node {2 * cos(2 * x)}
math.derivative('2*x', 'x').eval(); // number 2
math.derivative('x^2', 'x').eval({x: 4}); // number 8
var f = math.parse('x^2');
var x = math.parse('x');
math.derivative(f, x); // Node {2 * x}
```
## See also
[simplify](simplify.md),
[parse](parse.md),
[eval](eval.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function det
Calculate the determinant of a matrix.
## Syntax
```js
math.det(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Array &#124; Matrix | A matrix
### Returns
Type | Description
---- | -----------
number | The determinant of `x`
## Examples
```js
math.det([[1, 2], [3, 4]]); // returns -2
var A = [
[-2, 2, 3],
[-1, 1, 3],
[2, 0, -1]
]
math.det(A); // returns 6
```
## See also
[inv](inv.md)

View File

@@ -0,0 +1,55 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function diag
Create a diagonal matrix or retrieve the diagonal of a matrix
When `x` is a vector, a matrix with vector `x` on the diagonal will be returned.
When `x` is a two dimensional matrix, the matrixes `k`th diagonal will be returned as vector.
When k is positive, the values are placed on the super diagonal.
When k is negative, the values are placed on the sub diagonal.
## Syntax
```js
math.diag(X)
math.diag(X, format)
math.diag(X, k)
math.diag(X, k, format)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Matrix &#124; Array | A two dimensional matrix or a vector
`k` | number &#124; BigNumber | The diagonal where the vector will be filled in or retrieved. Default value: 0.
`format` | string | The matrix storage format. Default value: 'dense'.
### Returns
Type | Description
---- | -----------
Matrix &#124; Array | Diagonal matrix from input vector, or diagonal from input matrix.
## Examples
```js
// create a diagonal matrix
math.diag([1, 2, 3]); // returns [[1, 0, 0], [0, 2, 0], [0, 0, 3]]
math.diag([1, 2, 3], 1); // returns [[0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3]]
math.diag([1, 2, 3], -1); // returns [[0, 0, 0], [1, 0, 0], [0, 2, 0], [0, 0, 3]]
// retrieve the diagonal from a matrix
var a = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];
math.diag(a); // returns [1, 5, 9]
```
## See also
[ones](ones.md),
[zeros](zeros.md),
[eye](eye.md)

View File

@@ -0,0 +1,72 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function distance
Calculates:
The eucledian distance between two points in 2 and 3 dimensional spaces.
Distance between point and a line in 2 and 3 dimensional spaces.
Pairwise distance between a set of 2D or 3D points
NOTE:
When substituting coefficients of a line(a, b and c), use ax + by + c = 0 instead of ax + by = c
For parametric equation of a 3D line, x0, y0, z0, a, b, c are from: (xx0, yy0, zz0) = t(a, b, c)
## Syntax
```js
math.distance([x1, y1], [x2, y2])
math.distance({pointOneX: 4, pointOneY: 5}, {pointTwoX: 2, pointTwoY: 7})
math.distance([x1, y1, z1], [x2, y2, z2])
math.distance({pointOneX: 4, pointOneY: 5, pointOneZ: 8}, {pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9})
math.distance([[A], [B], [C]...])
math.distance([x1, y1], [LinePtX1, LinePtY1], [LinePtX2, LinePtY2])
math.distance({pointX: 1, pointY: 4}, {lineOnePtX: 6, lineOnePtY: 3}, {lineTwoPtX: 2, lineTwoPtY: 8})
math.distance([x1, y1, z1], [LinePtX1, LinePtY1, LinePtZ1], [LinePtX2, LinePtY2, LinePtZ2])
math.distance({pointX: 1, pointY: 4, pointZ: 7}, {lineOnePtX: 6, lineOnePtY: 3, lineOnePtZ: 4}, {lineTwoPtX: 2, lineTwoPtY: 8, lineTwoPtZ: 5})
math.distance([x1, y1], [xCoeffLine, yCoeffLine, constant])
math.distance({pointX: 10, pointY: 10}, {xCoeffLine: 8, yCoeffLine: 1, constant: 3})
math.distance([x1, y1, z1], [x0, y0, z0, a-tCoeff, b-tCoeff, c-tCoeff]) point and parametric equation of 3D line
math.distance([x, y, z], [x0, y0, z0, a, b, c])
math.distance({pointX: 2, pointY: 5, pointZ: 9}, {x0: 4, y0: 6, z0: 3, a: 4, b: 2, c: 0})
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Array &#124; Matrix &#124; Object | Co-ordinates of first point
`y` | Array &#124; Matrix &#124; Object | Co-ordinates of second point
### Returns
Type | Description
---- | -----------
Number &#124; BigNumber | Returns the distance from two/three points
## Examples
```js
math.distance([0,0], [4,4]) // Returns 5.6569
math.distance(
{pointOneX: 0, pointOneY: 0},
{pointTwoX: 10, pointTwoY: 10}) // Returns 14.142135623730951
math.distance([1, 0, 1], [4, -2, 2]) // Returns 3.74166
math.distance(
{pointOneX: 4, pointOneY: 5, pointOneZ: 8},
{pointTwoX: 2, pointTwoY: 7, pointTwoZ: 9}) // Returns 3
math.distance([[1, 2], [1, 2], [1, 3]]) // Returns [0, 1, 1]
math.distance([[1,2,4], [1,2,6], [8,1,3]]) // Returns [2, 7.14142842854285, 7.681145747868608]
math.distance([10, 10], [8, 1, 3]) // Returns 11.535230316796387
math.distance([10, 10], [2, 3], [-8, 0]) // Returns 8.759953130362847
math.distance(
{pointX: 1, pointY: 4},
{lineOnePtX: 6, lineOnePtY: 3},
{lineTwoPtX: 2, lineTwoPtY: 8}) // Returns 2.720549372624744
math.distance([2, 3, 1], [1, 1, 2, 5, 0, 1]) // Returns 2.3204774044612857
math.distance(
{pointX: 2, pointY: 3, pointZ: 1},
{x0: 1, y0: 1, z0: 2, a: 5, b: 0, c: 1} // Returns 2.3204774044612857
```

View File

@@ -0,0 +1,49 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function divide
Divide two values, `x / y`.
To divide matrices, `x` is multiplied with the inverse of `y`: `x * inv(y)`.
## Syntax
```js
math.divide(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Numerator
`y` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Denominator
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Quotient, `x / y`
## Examples
```js
math.divide(2, 3); // returns number 0.6666666666666666
var a = math.complex(5, 14);
var b = math.complex(4, 1);
math.divide(a, b); // returns Complex 2 + 3i
var c = [[7, -6], [13, -4]];
var d = [[1, 2], [4, 3]];
math.divide(c, d); // returns Array [[-9, 4], [-11, 6]]
var e = math.unit('18 km');
math.divide(e, 4.5); // returns Unit 4 km
```
## See also
[multiply](multiply.md)

View File

@@ -0,0 +1,42 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function dot
Calculate the dot product of two vectors. The dot product of
`A = [a1, a2, a3, ..., an]` and `B = [b1, b2, b3, ..., bn]` is defined as:
dot(A, B) = a1 * b1 + a2 * b2 + a3 * b3 + ... + an * bn
## Syntax
```js
math.dot(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Array &#124; Matrix | First vector
`y` | Array &#124; Matrix | Second vector
### Returns
Type | Description
---- | -----------
number | Returns the dot product of `x` and `y`
## Examples
```js
math.dot([2, 4, 1], [2, 2, 3]); // returns number 15
math.multiply([2, 4, 1], [2, 2, 3]); // returns number 15
```
## See also
[multiply](multiply.md),
[cross](cross.md)

View File

@@ -0,0 +1,46 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function dotDivide
Divide two matrices element wise. The function accepts both matrices and
scalar values.
## Syntax
```js
math.dotDivide(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Numerator
`y` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Denominator
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Quotient, `x ./ y`
## Examples
```js
math.dotDivide(2, 4); // returns 0.5
a = [[9, 5], [6, 1]];
b = [[3, 2], [5, 2]];
math.dotDivide(a, b); // returns [[3, 2.5], [1.2, 0.5]]
math.divide(a, b); // returns [[1.75, 0.75], [-1.75, 2.25]]
```
## See also
[divide](divide.md),
[multiply](multiply.md),
[dotMultiply](dotMultiply.md)

View File

@@ -0,0 +1,46 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function dotMultiply
Multiply two matrices element wise. The function accepts both matrices and
scalar values.
## Syntax
```js
math.dotMultiply(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Left hand value
`y` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Right hand value
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Unit &#124; Array &#124; Matrix | Multiplication of `x` and `y`
## Examples
```js
math.dotMultiply(2, 4); // returns 8
a = [[9, 5], [6, 1]];
b = [[3, 2], [5, 2]];
math.dotMultiply(a, b); // returns [[27, 10], [30, 2]]
math.multiply(a, b); // returns [[52, 28], [23, 14]]
```
## See also
[multiply](multiply.md),
[divide](divide.md),
[dotDivide](dotDivide.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function dotPow
Calculates the power of x to y element wise.
## Syntax
```js
math.dotPow(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | The base
`y` | number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | The exponent
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Unit &#124; Array &#124; Matrix | The value of `x` to the power `y`
## Examples
```js
math.dotPow(2, 3); // returns number 8
var a = [[1, 2], [4, 3]];
math.dotPow(a, 2); // returns Array [[1, 4], [16, 9]]
math.pow(a, 2); // returns Array [[9, 8], [16, 17]]
```
## See also
[pow](pow.md),
[sqrt](sqrt.md),
[multiply](multiply.md)

View File

@@ -0,0 +1,67 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function equal
Test whether two values are equal.
The function tests whether the relative difference between x and y is
smaller than the configured epsilon. The function cannot be used to
compare values smaller than approximately 2.22e-16.
For matrices, the function is evaluated element wise.
In case of complex numbers, x.re must equal y.re, and x.im must equal y.im.
Values `null` and `undefined` are compared strictly, thus `null` is only
equal to `null` and nothing else, and `undefined` is only equal to
`undefined` and nothing else.
## Syntax
```js
math.equal(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; boolean &#124; Complex &#124; Unit &#124; string &#124; Array &#124; Matrix | First value to compare
`y` | number &#124; BigNumber &#124; boolean &#124; Complex &#124; Unit &#124; string &#124; Array &#124; Matrix | Second value to compare
### Returns
Type | Description
---- | -----------
boolean &#124; Array &#124; Matrix | Returns true when the compared values are equal, else returns false
## Examples
```js
math.equal(2 + 2, 3); // returns false
math.equal(2 + 2, 4); // returns true
var a = math.unit('50 cm');
var b = math.unit('5 m');
math.equal(a, b); // returns true
var c = [2, 5, 1];
var d = [2, 7, 1];
math.equal(c, d); // returns [true, false, true]
math.deepEqual(c, d); // returns false
math.equal(0, null); // returns false
```
## See also
[unequal](unequal.md),
[smaller](smaller.md),
[smallerEq](smallerEq.md),
[larger](larger.md),
[largerEq](largerEq.md),
[compare](compare.md),
[deepEqual](deepEqual.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function erf
Compute the erf function of a value using a rational Chebyshev
approximations for different intervals of x.
This is a translation of W. J. Cody's Fortran implementation from 1987
( http://www.netlib.org/specfun/erf ). See the AMS publication
"Rational Chebyshev Approximations for the Error Function" by W. J. Cody
for an explanation of this process.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.erf(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Array &#124; Matrix | A real number
### Returns
Type | Description
---- | -----------
number &#124; Array &#124; Matrix | The erf of `x`
## Examples
```js
math.erf(0.2); // returns 0.22270258921047847
math.erf(-0.5); // returns -0.5204998778130465
math.erf(4); // returns 0.9999999845827421
```

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function eval
Evaluate an expression.
## Syntax
```js
math.eval(expr)
math.eval(expr, scope)
math.eval([expr1, expr2, expr3, ...])
math.eval([expr1, expr2, expr3, ...], scope)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`expr` | string &#124; string[] &#124; Matrix | The expression to be evaluated
`scope` | Object | Scope to read/write variables
### Returns
Type | Description
---- | -----------
* | The result of the expression
## Examples
```js
math.eval('(2+3)/4'); // 1.25
math.eval('sqrt(3^2 + 4^2)'); // 5
math.eval('sqrt(-4)'); // 2i
math.eval(['a=3', 'b=4', 'a*b']);, // [3, 4, 12]
var scope = {a:3, b:4};
math.eval('a * b', scope); // 12
```
## See also
[parse](parse.md),
[compile](compile.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function exp
Calculate the exponent of a value.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.exp(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | A number or matrix to exponentiate
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Exponent of `x`
## Examples
```js
math.exp(2); // returns number 7.3890560989306495
math.pow(math.e, 2); // returns number 7.3890560989306495
math.log(math.exp(2)); // returns number 2
math.exp([1, 2, 3]);
// returns Array [
// 2.718281828459045,
// 7.3890560989306495,
// 20.085536923187668
// ]
```
## See also
[log](log.md),
[pow](pow.md)

View File

@@ -0,0 +1,51 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# 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
```js
math.eye(n)
math.eye(n, format)
math.eye(m, n)
math.eye(m, n, format)
math.eye([m, n])
math.eye([m, n], format)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`size` | ...number &#124; Matrix &#124; Array | The size for the matrix
`format` | string | The Matrix storage format
### Returns
Type | Description
---- | -----------
Matrix &#124; Array &#124; number | A matrix with ones on the diagonal.
## Examples
```js
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(A)); // returns [[1, 0, 0], [0, 1, 0]]
```
## See also
[diag](diag.md),
[ones](ones.md),
[zeros](zeros.md),
[size](size.md),
[range](range.md)

View File

@@ -0,0 +1,42 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function factorial
Compute the factorial of a value
Factorial only supports an integer value as argument.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.factorial(n)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`n` | number &#124; BigNumber &#124; Array &#124; Matrix | An integer number
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | The factorial of `n`
## Examples
```js
math.factorial(5); // returns 120
math.factorial(3); // returns 6
```
## See also
[combinations](combinations.md),
[gamma](gamma.md),
[permutations](permutations.md)

View File

@@ -0,0 +1,44 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function filter
Filter the items in an array or one dimensional matrix.
## Syntax
```js
math.filter(x, test)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Matrix &#124; Array | A one dimensional matrix or array to filter
`test` | Function &#124; RegExp | A function or regular expression to test items. All entries for which `test` returns true are returned. When `test` is a function, it is invoked with three parameters: the value of the element, the index of the element, and the matrix/array being traversed. The function must return a boolean.
### Returns
Type | Description
---- | -----------
Matrix &#124; Array | Returns the filtered matrix.
## Examples
```js
function isPositive (x) {
return x > 0;
}
math.filter([6, -2, -1, 4, 3], isPositive); // returns [6, 4, 3]
math.filter(["23", "foo", "100", "55", "bar"], /[0-9]+/); // returns ["23", "100", "55"]
```
## See also
[forEach](forEach.md),
[map](map.md),
[sort](sort.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function fix
Round a value towards zero.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.fix(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Number to be rounded
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Rounded value
## Examples
```js
math.fix(3.2); // returns number 3
math.fix(3.8); // returns number 3
math.fix(-4.2); // returns number -4
math.fix(-4.7); // returns number -4
var c = math.complex(3.2, -2.7);
math.fix(c); // returns Complex 3 - 2i
math.fix([3.2, 3.8, -4.7]); // returns Array [3, 3, -4]
```
## See also
[ceil](ceil.md),
[floor](floor.md),
[round](round.md)

View File

@@ -0,0 +1,39 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function flatten
Flatten a multi dimensional matrix into a single dimensional matrix.
## Syntax
```js
math.flatten(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Matrix &#124; Array | Matrix to be flattened
### Returns
Type | Description
---- | -----------
Matrix &#124; Array | Returns the flattened matrix
## Examples
```js
math.flatten([[1,2], [3,4]]); // returns [1, 2, 3, 4]
```
## See also
[concat](concat.md),
[resize](resize.md),
[size](size.md),
[squeeze](squeeze.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function floor
Round a value towards minus infinity.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.floor(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Number to be rounded
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Complex &#124; Array &#124; Matrix | Rounded value
## Examples
```js
math.floor(3.2); // returns number 3
math.floor(3.8); // returns number 3
math.floor(-4.2); // returns number -5
math.floor(-4.7); // returns number -5
var c = math.complex(3.2, -2.7);
math.floor(c); // returns Complex 3 - 3i
math.floor([3.2, 3.8, -4.7]); // returns Array [3, 3, -5]
```
## See also
[ceil](ceil.md),
[fix](fix.md),
[round](round.md)

View File

@@ -0,0 +1,35 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function forEach
Iterate over all elements of a matrix/array, and executes the given callback function.
## Syntax
```js
math.forEach(x, callback)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Matrix &#124; Array | The matrix to iterate on.
`callback` | Function | The callback function is invoked with three parameters: the value of the element, the index of the element, and the Matrix/array being traversed.
## Examples
```js
math.forEach([1, 2, 3], function(value) {
console.log(value);
});
// outputs 1, 2, 3
```
## See also
[filter](filter.md),
[map](map.md),
[sort](sort.md)

View File

@@ -0,0 +1,100 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function format
Format a value of any type into a string.
## Syntax
```js
math.format(value)
math.format(value, options)
math.format(value, precision)
math.format(value, callback)
```
### Where
- `value: *`
The value to be formatted
- `options: Object`
An object with formatting options. Available options:
- `notation: string`
Number notation. Choose from:
- 'fixed'
Always use regular number notation.
For example '123.40' and '14000000'
- 'exponential'
Always use exponential notation.
For example '1.234e+2' and '1.4e+7'
- 'engineering'
Always use engineering notation.
For example '123.4e+0' and '14.0e+6'
- 'auto' (default)
Regular number notation for numbers having an absolute value between
`lower` and `upper` bounds, and uses exponential notation elsewhere.
Lower bound is included, upper bound is excluded.
For example '123.4' and '1.4e7'.
- `precision: number`
A number between 0 and 16 to round the digits of the number. In case
of notations 'exponential' and 'auto', `precision` defines the total
number of significant digits returned and is undefined by default.
In case of notation 'fixed', `precision` defines the number of
significant digits after the decimal point, and is 0 by default.
- `exponential: Object`
An object containing two parameters, {number} lower and {number} upper,
used by notation 'auto' to determine when to return exponential
notation. Default values are `lower=1e-3` and `upper=1e5`. Only
applicable for notation `auto`.
- `fraction: string`. Available values: 'ratio' (default) or 'decimal'.
For example `format(fraction(1, 3))` will output '1/3' when 'ratio' is
configured, and will output `0.(3)` when 'decimal' is configured.
- `callback: function`
A custom formatting function, invoked for all numeric elements in `value`,
for example all elements of a matrix, or the real and imaginary
parts of a complex number. This callback can be used to override the
built-in numeric notation with any type of formatting. Function `callback`
is called with `value` as parameter and must return a string.
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`value` | * | Value to be stringified
`options` | Object &#124; Function &#124; number | Formatting options
### Returns
Type | Description
---- | -----------
string | The formatted value
## Examples
```js
math.format(6.4); // returns '6.4'
math.format(1240000); // returns '1.24e6'
math.format(1/3); // returns '0.3333333333333333'
math.format(1/3, 3); // returns '0.333'
math.format(21385, 2); // returns '21000'
math.format(12.071, {notation: 'fixed'}); // returns '12'
math.format(2.3, {notation: 'fixed', precision: 2}); // returns '2.30'
math.format(52.8, {notation: 'exponential'}); // returns '5.28e+1'
math.format(12400, {notation: 'engineering'}); // returns '12.400e+3'
function formatCurrency(value) {
// return currency notation with two digits:
return '$' + value.toFixed(2);
// you could also use math.format inside the callback:
// return '$' + math.format(value, {notation: 'fixed', precision: 2});
}
math.format([2.1, 3, 0.016], formatCurrency}; // returns '[$2.10, $3.00, $0.02]'
```
## See also
[print](print.md)

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function fraction
Create a fraction convert a value to a fraction.
## Syntax
```js
math.fraction(numerator, denominator)
math.fraction({n: numerator, d: denominator})
math.fraction(matrix: Array | Matrix) Turn all matrix entries
into fractions
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`args` | number &#124; string &#124; Fraction &#124; BigNumber &#124; Array &#124; Matrix | Arguments specifying the numerator and denominator of the fraction
### Returns
Type | Description
---- | -----------
Fraction &#124; Array &#124; Matrix | Returns a fraction
## Examples
```js
math.fraction(1, 3);
math.fraction('2/3');
math.fraction({n: 2, d: 3});
math.fraction([0.2, 0.25, 1.25]);
```
## See also
[bignumber](bignumber.md),
[number](number.md),
[string](string.md),
[unit](unit.md)

View File

@@ -0,0 +1,43 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function gamma
Compute the gamma function of a value using Lanczos approximation for
small values, and an extended Stirling approximation for large values.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.gamma(n)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`n` | number &#124; Array &#124; Matrix | A real or complex number
### Returns
Type | Description
---- | -----------
number &#124; Array &#124; Matrix | The gamma of `n`
## Examples
```js
math.gamma(5); // returns 24
math.gamma(-0.5); // returns -3.5449077018110335
math.gamma(math.i); // returns -0.15494982830180973 - 0.49801566811835596i
```
## See also
[combinations](combinations.md),
[factorial](factorial.md),
[permutations](permutations.md)

View File

@@ -0,0 +1,44 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function gcd
Calculate the greatest common divisor for two or more values or arrays.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.gcd(a, b)
math.gcd(a, b, c, ...)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`args` | ... number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Two or more integer numbers
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | The greatest common divisor
## Examples
```js
math.gcd(8, 12); // returns 4
math.gcd(-4, 6); // returns 2
math.gcd(25, 15, -10); // returns 5
math.gcd([8, -4], [12, 6]); // returns [4, 2]
```
## See also
[lcm](lcm.md),
[xgcd](xgcd.md)

View File

@@ -0,0 +1,36 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function help
Retrieve help on a function or data type.
Help files are retrieved from the documentation in math.expression.docs.
## Syntax
```js
math.help(search)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`search` | Function &#124; string &#124; Object | A function or function name for which to get help
### Returns
Type | Description
---- | -----------
Help | A help object
## Examples
```js
console.log(math.help('sin').toString());
console.log(math.help(math.add).toString());
console.log(math.help(math.add).toJSON());
```

View File

@@ -0,0 +1,45 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function hypot
Calculate the hypotenusa of a list with values. The hypotenusa is defined as:
hypot(a, b, c, ...) = sqrt(a^2 + b^2 + c^2 + ...)
For matrix input, the hypotenusa is calculated for all values in the matrix.
## Syntax
```js
math.hypot(a, b, ...)
math.hypot([a, b, c, ...])
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`args` | ... number &#124; BigNumber |
### Returns
Type | Description
---- | -----------
number &#124; BigNumber | Returns the hypothenusa of the input values.
## Examples
```js
math.hypot(3, 4); // 5
math.hypot(3, 4, 5); // 7.0710678118654755
math.hypot([3, 4, 5]); // 7.0710678118654755
math.hypot(-2); // 2
```
## See also
[abs](abs.md),
[norm](norm.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function im
Get the imaginary part of a complex number.
For a complex number `a + bi`, the function returns `b`.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.im(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | A complex number or array with complex numbers
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | The imaginary part of x
## Examples
```js
var a = math.complex(2, 3);
math.re(a); // returns number 2
math.im(a); // returns number 3
math.re(math.complex('-5.2i')); // returns number -5.2
math.re(math.complex(2.4)); // returns number 0
```
## See also
[re](re.md),
[conj](conj.md),
[abs](abs.md),
[arg](arg.md)

View File

@@ -0,0 +1,60 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function import
Import functions from an object or a module
## Syntax
```js
math.import(object)
math.import(object, options)
```
### Where
- `object: Object`
An object with functions to be imported.
- `options: Object` An object with import options. Available options:
- `override: boolean`
If true, existing functions will be overwritten. False by default.
- `silent: boolean`
If true, the function will not throw errors on duplicates or invalid
types. False by default.
- `wrap: boolean`
If true, the functions will be wrapped in a wrapper function
which converts data types like Matrix to primitive data types like Array.
The wrapper is needed when extending math.js with libraries which do not
support these data type. False by default.
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`object` | Object &#124; Array | Object with functions to be imported.
`options` | Object | Import options.
## Examples
```js
// define new functions and variables
math.import({
myvalue: 42,
hello: function (name) {
return 'hello, ' + name + '!';
}
});
// use the imported function and variable
math.myvalue * 2; // 84
math.hello('user'); // 'hello, user!'
// import the npm module 'numbers'
// (must be installed first with `npm install numbers`)
math.import(require('numbers'), {wrap: true});
math.fibonacci(7); // returns 13
```

View File

@@ -0,0 +1,57 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function index
Create an index. An Index can store ranges having start, step, and end
for multiple dimensions.
Matrix.get, Matrix.set, and math.subset accept an Index as input.
## Syntax
```js
math.index(range1, range2, ...)
```
### Where
- A number
- A string for getting/setting an object property
- An instance of `Range`
- A one-dimensional Array or a Matrix with numbers
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`ranges` | ...* | Zero or more ranges or numbers.
### Returns
Type | Description
---- | -----------
Index | Returns the created index
## Examples
```js
var math = math.js
var b = [1, 2, 3, 4, 5];
math.subset(b, math.index([1, 2, 3])); // returns [2, 3, 4]
var a = math.matrix([[1, 2], [3, 4]]);
a.subset(math.index(0, 1)); // returns 2
```
## See also
[bignumber](bignumber.md),
[boolean](boolean.md),
[complex](complex.md),
[matrix](matrix.md),
[number](number.md),
[string](string.md),
[unit](unit.md)

View File

@@ -0,0 +1,44 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function intersect
Calculates the point of intersection of two lines in two or three dimensions
and of a line and a plane in three dimensions. The inputs are in the form of
arrays or 1 dimensional matrices. The line intersection functions return null
if the lines do not meet.
Note: Fill the plane coefficients as `x + y + z = c` and not as `x + y + z + c = 0`.
## Syntax
```js
math.intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)
math.intersect(endPoint1, endPoint2, planeCoefficients)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`w` | Array &#124; Matrix | Co-ordinates of first end-point of first line
`x` | Array &#124; Matrix | Co-ordinates of second end-point of first line
`y` | Array &#124; Matrix | Co-ordinates of first end-point of second line OR Co-efficients of the plane's equation
`z` | Array &#124; Matrix | Co-ordinates of second end-point of second line OR null if the calculation is for line and plane
### Returns
Type | Description
---- | -----------
Array | Returns the point of intersection of lines/lines-planes
## Examples
```js
math.intersect([0, 0], [10, 10], [10, 0], [0, 10]); // Returns [5, 5]
math.intersect([0, 0, 0], [10, 10, 0], [10, 0, 0], [0, 10, 0]); // Returns [5, 5, 0]
math.intersect([1, 0, 1], [4, -2, 2], [1, 1, 1, 6]); // Returns [7, -4, 3]
```

View File

@@ -0,0 +1,39 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function inv
Calculate the inverse of a square matrix.
## Syntax
```js
math.inv(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; Complex &#124; Array &#124; Matrix | Matrix to be inversed
### Returns
Type | Description
---- | -----------
number &#124; Complex &#124; Array &#124; Matrix | The inverse of `x`.
## Examples
```js
math.inv([[1, 2], [3, 4]]); // returns [[-2, 1], [1.5, -0.5]]
math.inv(4); // returns 0.25
1 / 4; // returns 0.25
```
## See also
[det](det.md),
[transpose](transpose.md)

View File

@@ -0,0 +1,49 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function isInteger
Test whether a value is an integer number.
The function supports `number`, `BigNumber`, and `Fraction`.
The function is evaluated element-wise in case of Array or Matrix input.
## Syntax
```js
math.isInteger(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Array &#124; Matrix | Value to be tested
### Returns
Type | Description
---- | -----------
boolean | Returns true when `x` contains a numeric, integer value. Throws an error in case of an unknown data type.
## Examples
```js
math.isInteger(2); // returns true
math.isInteger(0); // returns true
math.isInteger(0.5); // returns false
math.isInteger(math.bignumber(500)); // returns true
math.isInteger(math.fraction(4)); // returns true
math.isInteger('3'); // returns true
math.isInteger([3, 0.5, -2]); // returns [true, false, true]
math.isInteger(math.complex('2-4i'); // throws an error
```
## See also
[isNumeric](isNumeric.md),
[isPositive](isPositive.md),
[isNegative](isNegative.md),
[isZero](isZero.md)

View File

@@ -0,0 +1,50 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function isNaN
Test whether a value is NaN (not a number).
The function supports types `number`, `BigNumber`, `Fraction`, `Unit` and `Complex`.
The function is evaluated element-wise in case of Array or Matrix input.
## Syntax
```js
math.isNaN(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Unit &#124; Array &#124; Matrix | Value to be tested
### Returns
Type | Description
---- | -----------
boolean | Returns true when `x` is NaN. Throws an error in case of an unknown data type.
## Examples
```js
math.isNaN(3); // returns false
math.isNaN(NaN); // returns true
math.isNaN(0); // returns false
math.isNaN(math.bignumber(NaN)); // returns true
math.isNaN(math.bignumber(0)); // returns false
math.isNaN(math.fraction(-2, 5)); // returns false
math.isNaN('-2'); // returns false
math.isNaN([2, 0, -3, NaN]'); // returns [false, false, false, true]
```
## See also
[isNumeric](isNumeric.md),
[isNegative](isNegative.md),
[isPositive](isPositive.md),
[isZero](isZero.md),
[isInteger](isInteger.md)

View File

@@ -0,0 +1,49 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function isNegative
Test whether a value is negative: smaller than zero.
The function supports types `number`, `BigNumber`, `Fraction`, and `Unit`.
The function is evaluated element-wise in case of Array or Matrix input.
## Syntax
```js
math.isNegative(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Unit &#124; Array &#124; Matrix | Value to be tested
### Returns
Type | Description
---- | -----------
boolean | Returns true when `x` is larger than zero. Throws an error in case of an unknown data type.
## Examples
```js
math.isNegative(3); // returns false
math.isNegative(-2); // returns true
math.isNegative(0); // returns false
math.isNegative(-0); // returns false
math.isNegative(math.bignumber(2)); // returns false
math.isNegative(math.fraction(-2, 5)); // returns true
math.isNegative('-2'); // returns true
math.isNegative([2, 0, -3]'); // returns [false, false, true]
```
## See also
[isNumeric](isNumeric.md),
[isPositive](isPositive.md),
[isZero](isZero.md),
[isInteger](isInteger.md)

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function isNumeric
Test whether a value is an numeric value.
The function is evaluated element-wise in case of Array or Matrix input.
## Syntax
```js
math.isNumeric(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | * | Value to be tested
### Returns
Type | Description
---- | -----------
boolean | Returns true when `x` is a `number`, `BigNumber`, `Fraction`, or `boolean`. Returns false for other types. Throws an error in case of unknown types.
## Examples
```js
math.isNumeric(2); // returns true
math.isNumeric(0); // returns true
math.isNumeric(math.bignumber(500)); // returns true
math.isNumeric(math.fraction(4)); // returns true
math.isNumeric(math.complex('2-4i'); // returns false
math.isNumeric('3'); // returns false
math.isNumeric([2.3, 'foo', false]); // returns [true, false, true]
```
## See also
[isZero](isZero.md),
[isPositive](isPositive.md),
[isNegative](isNegative.md),
[isInteger](isInteger.md)

View File

@@ -0,0 +1,51 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function isPositive
Test whether a value is positive: larger than zero.
The function supports types `number`, `BigNumber`, `Fraction`, and `Unit`.
The function is evaluated element-wise in case of Array or Matrix input.
## Syntax
```js
math.isPositive(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; Unit &#124; Array &#124; Matrix | Value to be tested
### Returns
Type | Description
---- | -----------
boolean | Returns true when `x` is larger than zero. Throws an error in case of an unknown data type.
## Examples
```js
math.isPositive(3); // returns true
math.isPositive(-2); // returns false
math.isPositive(0); // returns false
math.isPositive(-0); // returns false
math.isPositive(0.5); // returns true
math.isPositive(math.bignumber(2)); // returns true
math.isPositive(math.fraction(-2, 5)); // returns false
math.isPositive(math.fraction(1,3)); // returns false
math.isPositive('2'); // returns true
math.isPositive([2, 0, -3]'); // returns [true, false, false]
```
## See also
[isNumeric](isNumeric.md),
[isZero](isZero.md),
[isNegative](isNegative.md),
[isInteger](isInteger.md)

View File

@@ -0,0 +1,48 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function isPrime
Test whether a value is prime: has no divisors other than itself and one.
The function supports type `number`, `bignumber`.
The function is evaluated element-wise in case of Array or Matrix input.
## Syntax
```js
math.isPrime(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Array &#124; Matrix | Value to be tested
### Returns
Type | Description
---- | -----------
boolean | Returns true when `x` is larger than zero. Throws an error in case of an unknown data type.
## Examples
```js
math.isPrime(3); // returns true
math.isPrime(-2); // returns false
math.isPrime(0); // returns false
math.isPrime(-0); // returns false
math.isPrime(0.5); // returns false
math.isPrime('2'); // returns true
math.isPrime([2, 17, 100]'); // returns [true, true, false]
```
## See also
[isNumeric](isNumeric.md),
[isZero](isZero.md),
[isNegative](isNegative.md),
[isInteger](isInteger.md)

View File

@@ -0,0 +1,53 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function isZero
Test whether a value is zero.
The function can check for zero for types `number`, `BigNumber`, `Fraction`,
`Complex`, and `Unit`.
The function is evaluated element-wise in case of Array or Matrix input.
## Syntax
```js
math.isZero(x)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Complex &#124; Fraction &#124; Unit &#124; Array &#124; Matrix | Value to be tested
### Returns
Type | Description
---- | -----------
boolean | Returns true when `x` is zero. Throws an error in case of an unknown data type.
## Examples
```js
math.isZero(0); // returns true
math.isZero(2); // returns false
math.isZero(0.5); // returns false
math.isZero(math.bignumber(0)); // returns true
math.isZero(math.fraction(0)); // returns true
math.isZero(math.fraction(1,3)); // returns false
math.isZero(math.complex('2 - 4i'); // returns false
math.isZero(math.complex('0i'); // returns true
math.isZero('0'); // returns true
math.isZero('2'); // returns false
math.isZero([2, 0, -3]'); // returns [false, true, false]
```
## See also
[isNumeric](isNumeric.md),
[isPositive](isPositive.md),
[isNegative](isNegative.md),
[isInteger](isInteger.md)

View File

@@ -0,0 +1,35 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function kldivergence
Calculate the Kullback-Leibler (KL) divergence between two distributions
## Syntax
```js
math.kldivergence(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`q` | Array &#124; Matrix | First vector
`p` | Array &#124; Matrix | Second vector
### Returns
Type | Description
---- | -----------
number | Returns distance between q and p
## Examples
```js
math.kldivergence([0.7,0.5,0.4], [0.2,0.9,0.5]); //returns 0.24376698773121153
```

View File

@@ -0,0 +1,47 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function kron
Calculates the kronecker product of 2 matrices or vectors.
NOTE: If a one dimensional vector / matrix is given, it will be
wrapped so its two dimensions.
See the examples.
## Syntax
```js
math.kron(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | Array &#124; Matrix | First vector
`y` | Array &#124; Matrix | Second vector
### Returns
Type | Description
---- | -----------
Array &#124; Matrix | Returns the kronecker product of `x` and `y`
## Examples
```js
math.kron([[1, 0], [0, 1]], [[1, 2], [3, 4]]);
// returns [ [ 1, 2, 0, 0 ], [ 3, 4, 0, 0 ], [ 0, 0, 1, 2 ], [ 0, 0, 3, 4 ] ]
math.kron([1,1], [2,3,4]);
// returns [ [ 2, 3, 4, 2, 3, 4 ] ]
```
## See also
[multiply](multiply.md),
[dot](dot.md),
[cross](cross.md)

View File

@@ -0,0 +1,53 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function larger
Test whether value x is larger than y.
The function returns true when x is larger than y and the relative
difference between x and y is larger than the configured epsilon. The
function cannot be used to compare values smaller than approximately 2.22e-16.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.larger(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; boolean &#124; Unit &#124; string &#124; Array &#124; Matrix | First value to compare
`y` | number &#124; BigNumber &#124; Fraction &#124; boolean &#124; Unit &#124; string &#124; Array &#124; Matrix | Second value to compare
### Returns
Type | Description
---- | -----------
boolean &#124; Array &#124; Matrix | Returns true when the x is larger than y, else returns false
## Examples
```js
math.larger(2, 3); // returns false
math.larger(5, 2 + 2); // returns true
var a = math.unit('5 cm');
var b = math.unit('2 inch');
math.larger(a, b); // returns false
```
## See also
[equal](equal.md),
[unequal](unequal.md),
[smaller](smaller.md),
[smallerEq](smallerEq.md),
[largerEq](largerEq.md),
[compare](compare.md)

View File

@@ -0,0 +1,49 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function largerEq
Test whether value x is larger or equal to y.
The function returns true when x is larger than y or the relative
difference between x and y is smaller than the configured epsilon. The
function cannot be used to compare values smaller than approximately 2.22e-16.
For matrices, the function is evaluated element wise.
## Syntax
```js
math.largerEq(x, y)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`x` | number &#124; BigNumber &#124; Fraction &#124; boolean &#124; Unit &#124; string &#124; Array &#124; Matrix | First value to compare
`y` | number &#124; BigNumber &#124; Fraction &#124; boolean &#124; Unit &#124; string &#124; Array &#124; Matrix | Second value to compare
### Returns
Type | Description
---- | -----------
boolean &#124; Array &#124; Matrix | Returns true when the x is larger or equal to y, else returns false
## Examples
```js
math.larger(2, 1 + 1); // returns false
math.largerEq(2, 1 + 1); // returns true
```
## See also
[equal](equal.md),
[unequal](unequal.md),
[smaller](smaller.md),
[smallerEq](smallerEq.md),
[larger](larger.md),
[compare](compare.md)

View File

@@ -0,0 +1,48 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function lcm
Calculate the least common multiple for two or more values or arrays.
lcm is defined as:
lcm(a, b) = abs(a * b) / gcd(a, b)
For matrices, the function is evaluated element wise.
## Syntax
```js
math.lcm(a, b)
math.lcm(a, b, c, ...)
```
### Parameters
Parameter | Type | Description
--------- | ---- | -----------
`args` | ... number &#124; BigNumber &#124; Array &#124; Matrix | Two or more integer numbers
### Returns
Type | Description
---- | -----------
number &#124; BigNumber &#124; Array &#124; Matrix | The least common multiple
## Examples
```js
math.lcm(4, 6); // returns 12
math.lcm(6, 21); // returns 42
math.lcm(6, 21, 5); // returns 210
math.lcm([4, 6], [6, 21]); // returns [12, 42]
```
## See also
[gcd](gcd.md),
[xgcd](xgcd.md)

Some files were not shown because too many files have changed in this diff Show More