Merge pull request #734 from tetslee/algebraic_differentiation

Improvements to simplify
This commit is contained in:
Jos de Jong 2016-11-07 20:50:14 +01:00 committed by GitHub
commit 6248d0e1d0
608 changed files with 34821 additions and 24639 deletions

View File

@ -2,5 +2,5 @@ language: node_js
node_js:
- 0.10
- 0.12
- 4.0
- 4.1
- 4
- 6

View File

@ -7,10 +7,11 @@ ideas and suggestions, and contribute to the code.
There are a few preferences regarding code contributions:
- Math.js follows the node.js code style as described
[here](http://nodeguide.com/style.html).
- Send pull requests to the `develop` branch, not the `master` branch.
[here](https://github.com/felixge/node-style-guide).
- Make sure you properly unit test your changes.
- Before creating a pull request, run the unit tests to make sure they all pass.
- Only commit changes done in the source files under `lib`, not to the builds
which are located in the folder `dist`.
- Send pull requests to the `develop` branch, not the `master` branch.
Thanks!

View File

@ -1,6 +1,218 @@
# History
## 2016-10-21, version 3.6.0
- Implemented function `erf()`. THanks @patgrasso.
- Extended function `cross()` to support n-d vectors. Thanks @patgrasso.
- Extended function `pickRandom` with the option to pick multiple values from
an array and give the values weights: `pickRandom(possibles, number, weights)`.
Thanks @woylie.
- Parser now exposes test functions like `isAlpha` which can be replaced in
order to adjust the allowed characters in variables names (See #715).
- Fixed #727: Parser not throwing an error for invalid implicit multiplications
like `-2 2` and `2^3 4` (right after the second value of an operator).
- Fixed #688: Describe allowed variable names in the docs.
## 2016-09-21, version 3.5.3
- Some more fixes regarding numbers ending with a decimal mark (like `2.`).
## 2016-09-20, version 3.5.2
- Fixed numbers ending with a decimal mark (like `2.`) not being supported by
the parser, solved the underlying ambiguity in the parser. See #707, #711.
## 2016-09-12, version 3.5.1
- Removed a left over console.log statement. Thanks @eknkc.
## 2016-09-07, version 3.5.0
- Comments of expressions are are now stored in the parsed nodes. See #690.
- Fixed function `print` not accepting an Object with formatting options as
third parameter Thanks @ThomasBrierley.
- Fixed #707: The expression parser no longer accepts numbers ending with a dot
like `2.`.
## 2016-08-08, version 3.4.1
- Fixed broken bundle files (`dist/math.js`, `dist/math.min.js`).
- Fixed some layout issues in the function reference docs.
## 2016-08-07, version 3.4.0
- Implemented support for custom units using `createUnit`. Thanks @ericman314.
- Implemented function `splitUnits`. Thanks @ericman314.
- Implemented function `isPrime`. Thanks @MathBunny.
## 2016-07-05, version 3.3.0
- Implemented function `isNaN`.
- Function `math.filter` now passes three arguments to the callback function:
value, index, and array.
- Removed the check on the number of arguments from functions defined in the
expression parser (see #665).
- Fixed #665: functions `map`, `forEach`, and `filter` now invoke callbacks
which are a typed-function with the correct number of arguments.
## 2016-04-26, version 3.2.1
- Fixed #651: unable to perform calculations on "Unit-less" units.
- Fixed matrix.subset mutating the replacement matrix when unsqueezing it.
## 2016-04-16, version 3.2.0
- Implemented #644: method `Parser.getAll()` to retrieve all defined variables.
- Upgraded dependencies (decimal.js@5.0.8, fraction.js@3.3.1,
typed-function@0.10.4).
- Fixed #601: Issue with unnamed typed-functions by upgrading to
typed-function v0.10.4.
- Fixed #636: More strict `toTex` templates, reckon with number of arguments.
- Fixed #641: Bug in expression parser parsing implicit multiplication with
wrong precedence in specific cases.
- Fixed #645: Added documentation about `engineering` notation of function
`math.format`.
## 2016-04-03, version 3.1.4
- Using ES6 Math functions like `Math.sinh`, `Math.cbrt`, `Math.sign`, etc when
available.
- Fixed #631: unit aliases `weeks`, `months`, and `years` where missing.
- Fixed #632: problem with escaped backslashes at the end of strings.
- Fixed #635: `Node.toString` options where not passed to function arguments.
- Fixed #629: expression parser throws an error when passing a number with
decimal exponent instead of parsing them as implicit multiplication.
- Fixed #484, #555: inaccuracy of `math.sinh` for values between -1 and 1.
- Fixed #625: Unit `in` (`inch`) not always working due to ambiguity with
the operator `a in b` (alias of `a to b`).
## 2016-03-24, version 3.1.3
- Fix broken bundle.
## 2016-03-24, version 3.1.2
- Fix broken npm release.
## 2016-03-24, version 3.1.1
- Fixed #621: a bug in parsing implicit multiplications like `(2)(3)+4`.
- Fixed #623: `nthRoot` of zero with a negative root returned `0` instead of
`Infinity`.
- Throw an error when functions `min`, `max`, `mean`, or `median` are invoked
with multiple matrices as arguments (see #598).
## 2016-03-19, version 3.1.0
- Hide multiplication operator by default when outputting `toTex` and `toString`
for implicit multiplications. Implemented and option to output the operator.
- Implemented unit `kip` and alias `kips`. Thanks @hgupta9.
- Added support for prefixes for units `mol` and `mole`. Thanks @stu-blair.
- Restored support for implicit multiplications like `2(3+4)` and `(2+3)(4+5)`.
- Some improvements in the docs.
- Added automatic conversions from `boolean` and `null` to `Fraction`,
and conversions from `Fraction` to `Complex`.
## 2016-03-04, version 3.0.0
### breaking changes
- More restricted support for implicit multiplication in the expression
parser: `(...)(...)` is now evaluated as a function invocation,
and `[...][...]` as a matrix subset.
- Matrix multiplication no longer squeezes scalar outputs to a scalar value,
but leaves them as they are: a vector or matrix containing a single value.
See #529.
- Assignments in the expression parser now return the assigned value rather
than the created or updated object (see #533). Example:
```
A = eye(3)
A[1,1] = 2 # this assignment now returns 2 instead of A
```
- Expression parser now supports objects. This involves a refactoring and
extension in expression nodes:
- Implemented new node `ObjectNode`.
- Refactored `AssignmentNode`, `UpdateNode`, and `IndexNode` are refactored
into `AccessorNode`, `AssignmentNode`, and `IndexNode` having a different API.
- Upgraded the used BigNumber library `decimal.js` to v5. Replaced the
trigonometric functions of math.js with those provided in decimal.js v5.
This can give slightly different behavior qua round-off errors.
- Replaced the internal `Complex.js` class with the `complex.js` library
created by @infusion.
- Entries in a matrix (typically numbers, BigNumbers, Units, etc) are now
considered immutable, they are no longer copied when performing operations on
the entries, improving performance.
- Implemented nearly equal comparison for relational functions (`equal`,
`larger`, `smaller`, etc.) when using BigNumbers.
- Changed the casing of the configuration options `matrix` (`Array` or `Matrix`)
and `number` (`number`, `BigNumber`, `Fraction`) such that they now match
the type returned by `math.typeof`. Wrong casing gives a console warning but
will still work.
- Changed the default config value for `epsilon` from `1e-14` to `1e-12`,
see #561.
### non-breaking changes
- Extended function `pow` to return the real root for cubic roots of negative
numbers. See #525, #482, #567.
- Implemented support for JSON objects in the expression parser and the
function `math.format`.
- Function `math.fraction` now supports `BigNumber`, and function
`math.bignumber` now supports `Fraction`.
- Expression parser now allows function and/or variable assignments inside
accessors and conditionals, like `A[x=2]` or `a > 2 ? b="ok" : b="fail"`.
- Command line interface:
- Outputs the variable name of assignments.
- Fixed not rounding BigNumbers to 14 digits like numbers.
- Fixed non-working autocompletion of user defined variables.
- Reorganized and extended docs, added docs on classes and more. Thanks @hgupta9.
- Added new units `acre`, `hectare`, `torr`, `bar`, `mmHg`, `mmH2O`, `cmH2O`,
and added new aliases `acres`, `hectares`, `sqfeet`, `sqyard`, `sqmile`,
`sqmiles`, `mmhg`, `mmh2o`, `cmh2o`. Thanks @hgupta9.
- Fixed a bug in the toString method of an IndexNode.
- Fixed angle units `deg`, `rad`, `grad`, `cycle`, `arcsec`, and `arcmin` not
being defined as BigNumbers when configuring to use BigNumbers.
## 2016-02-03, version 2.7.0
- Added more unit aliases for time: `secs`, `mins`, `hr`, `hrs`. See #551.
- Added support for doing operations with mixed `Fractions` and `BigNumbers`.
- Fixed #540: `math.intersect()` returning null in some cases. Thanks @void42.
- Fixed #546: Cannot import BigNumber, Fraction, Matrix, Array.
Thanks @brettjurgens.
## 2016-01-08, version 2.6.0
- Implemented (complex) units `VA` and `VAR`.
- Implemented time units for weeks, months, years, decades, centuries, and
millennia. Thanks @owenversteeg.
- Implemented new notation `engineering` in function `math.format`.
Thanks @johnmarinelli.
- Fixed #523: In some circumstances, matrix subset returned a scalar instead
of the correct subset.
- Fixed #536: A bug in an internal method used for sparse matrices.
## 2015-12-05, version 2.5.0
- Implemented support for numeric types `Fraction` and `BigNumber` in units.

2
NOTICE
View File

@ -1,7 +1,7 @@
math.js
https://github.com/josdejong/mathjs
Copyright (C) 2013-2015 Jos de Jong <wjosdejong@gmail.com>
Copyright (C) 2013-2016 Jos de Jong <wjosdejong@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -110,7 +110,7 @@ To see the coverage results, open the generated report in your browser:
## License
Copyright (C) 2013-2015 Jos de Jong <wjosdejong@gmail.com>
Copyright (C) 2013-2016 Jos de Jong <wjosdejong@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

View File

@ -29,7 +29,7 @@
* cat script.txt | mathjs > results.txt Run input stream, output to file
*
* @license
* Copyright (C) 2013-2015 Jos de Jong <wjosdejong@gmail.com>
* Copyright (C) 2013-2016 Jos de Jong <wjosdejong@gmail.com>
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
@ -45,11 +45,30 @@
*/
var math = require('../index');
var parser = math.parser();
var scope = {};
var fs = require('fs');
var PRECISION = 14; // decimals
/**
* Helper function to format a value. Regular numbers will be rounded
* to 14 digits to prevent round-off errors from showing up.
* @param {*} value
*/
function format(value) {
return math.format(value, {
fn: function (value) {
if (typeof value === 'number') {
// round numbers
return math.format(value, PRECISION);
}
else {
return math.format(value);
}
}
});
}
/**
* auto complete a text
* @param {String} text
@ -63,9 +82,8 @@ function completer (text) {
var keyword = m[0];
// scope variables
// TODO: not nice to read the (private) defs inside the scope
for (var def in parser.scope.defs) {
if (parser.scope.defs.hasOwnProperty(def)) {
for (var def in scope) {
if (scope.hasOwnProperty(def)) {
if (def.indexOf(keyword) == 0) {
matches.push(def);
}
@ -166,7 +184,7 @@ function runStream (input, output, mode, parenthesis) {
break;
case 'clear':
// clear memory
parser.clear();
scope = {};
console.log('memory cleared');
// get next input
@ -182,22 +200,37 @@ function runStream (input, output, mode, parenthesis) {
case 'eval':
// evaluate expression
try {
var res = parser.eval(expr);
if (res instanceof math.type.ResultSet) {
res.entries.forEach(function (entry) {
console.log(math.format(entry, PRECISION));
});
if (res.entries.length) {
// set last answer from the ResultSet as ans
parser.set('ans', res.entries[res.entries.length - 1]);
var node = math.parse(expr);
var res = node.eval(scope);
if (res && res.isResultSet) {
// we can have 0 or 1 results in the ResultSet, as the CLI
// does not allow multiple expressions separated by a return
res = res.entries[0];
node = node.blocks
.filter(function (entry) { return entry.visible; })
.map(function (entry) { return entry.node })[0];
}
if (node) {
if (node.isAssignmentNode) {
var name = findSymbolName(node);
if (name != null) {
scope.ans = scope[name];
console.log(name + ' = ' + format(scope[name]));
}
else {
scope.ans = res;
console.log(format(res));
}
}
else if (res instanceof math.type.Help) {
console.log(res.toString());
}
else {
scope.ans = res;
console.log(format(res));
}
}
else if (res instanceof math.type.Help) {
console.log(res.toString());
}
else {
parser.set('ans', res);
console.log(math.format(res, PRECISION));
}
}
catch (err) {
@ -239,6 +272,25 @@ function runStream (input, output, mode, parenthesis) {
});
}
/**
* Find the symbol name of an AssignmentNode. Recurses into the chain of
* objects to the root object.
* @param {AssignmentNode} node
* @return {string | null} Returns the name when found, else returns null.
*/
function findSymbolName (node) {
var n = node;
while (n) {
if (n.isSymbolNode) {
return n.name;
}
n = n.object;
}
return null;
}
/**
* Output application version number.
* Version number is read version from package.json.
@ -320,7 +372,6 @@ process.argv.forEach(function (arg, index) {
break;
case '--string':
mode = 'string';
break;
@ -336,6 +387,8 @@ process.argv.forEach(function (arg, index) {
parenthesis = 'all';
break;
// TODO: implement configuration via command line arguments
default:
scripts.push(arg);
}

View File

@ -1,6 +1,6 @@
{
"name": "mathjs",
"version": "2.5.0",
"version": "3.6.0",
"main": "./dist/math.min.js",
"license": "Apache-2.0",
"ignore": [

View File

@ -1,6 +1,6 @@
{
"name": "mathjs",
"version": "2.5.0",
"version": "3.6.0",
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser and offers an integrated solution to work with numbers, big numbers, complex numbers, units, and matrices.",
"repo": "josdejong/mathjs",
"main": "dist/math.min.js",

39836
dist/math.js vendored

File diff suppressed because it is too large Load Diff

2
dist/math.map vendored

File diff suppressed because one or more lines are too long

43
dist/math.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -1,3 +0,0 @@
# Chained operations
This page has been moved to [Chaining](chaining.md).

View File

@ -1,41 +1,3 @@
# Chaining
Math.js supports chaining operations by wrapping a value into a `Chain`.
A chain can be created with the function `math.chain(value)`
(formerly `math.select(value)`).
All functions available in the math namespace can be executed via the chain.
The functions will be executed with the chain's value as the first argument,
followed by extra arguments provided by the function call itself.
```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]]
```
### API
A `Chain` is constructed as:
```js
math.chain()
math.chain(value)
```
The `Chain` has all functions available in the `math` namespace, and has
a number of special functions:
- `done()`
Finalize the chain and return the chain's value.
- `valueOf()`
The same as `done()`, returns the chain's value.
- `toString()`
Executes `math.format(value)` onto the chain's value, returning
a string representation of the value.
This page has been moved [here](core/chaining.md).

View File

@ -1,125 +1,3 @@
# Configuration
Math.js contains a number of configuration options. There are two ways to
configure math.js:
- Configure an existing instance of math.js using `math.config(options)`,
for example `math.config({number: 'bignumber'})` to change to BigNumbers.
- Create and configure a new instance of math.js using `math.create([options])`,
for example `var bigmath = math.create({number: 'bignumber'})` to create a new
instance configured to use BigNumbers.
The following configuration options are available:
- `epsilon`. The minimum relative difference used to test equality between two
compared values. This value is used by all relational functions.
Default value is `1e-14`.
- `matrix`. The default type of matrix output for functions.
Available values are: `'matrix'` (default) or `'array'`.
Where possible, the type of matrix output from functions is determined from
the function input: An array as input will return an Array, a Matrix as input
will return a Matrix. In case of no matrix as input, the type of output is
determined by the option `matrix`. In case of mixed matrix
inputs, a matrix will be returned always.
- `number`. The default type of numbers. This setting is used by functions
like `eval` which cannot determine the correct type of output from the
functions input. For most functions though, the type of output is determined
from the the input: a number as input will return a number as output,
a BigNumber as input returns a BigNumber as output.
Available values are: `'number'` (default), `'bignumber'`, or `'fraction'`.
[BigNumbers](./datatypes/bignumbers.js) have higher precision than the default
numbers of JavaScript, and [`Fractions`](./datatypes/fractions.js) store
values in terms of a numerator and denominator.
- `precision`. The maximum number of significant digits for bigNumbers.
This setting only applies to BigNumbers, not to numbers.
Default value is `64`.
- `predictable`. Predictable output type of functions. When true, output type
depends only on the input types. When false (default), output type can vary
depending on input values. For example `math.sqrt(-2)` returns `NaN` when
predictable is false, and returns `complex('2i')` when true.
Predictable output can be needed when programmatically handling the result of
a calculation, but can be inconvenient for users when evaluating dynamic
equations.
## Examples
This section shows a number of configuration examples.
### node.js
```js
// load the default instance of math.js
var math = require('mathjs');
// range will output a Matrix
math.range(0, 4); // Matrix [0, 1, 2, 3]
// create a new instance configured to use Arrays
var math2 = math.create({
matrix: 'array' // Choose 'matrix' (default) or 'array'
});
// range will output an Array
math2.range(0, 4); // Array [0, 1, 2, 3]
// change the configuration of math2 from Arrays to Matrices
math2.config({
matrix: 'matrix' // Choose 'matrix' (default) or 'array'
});
// range will output a Matrix
math2.range(0, 4); // Matrix [0, 1, 2, 3]
// create an instance of math.js with bignumber configuration
var bigmath = math.create({
number: 'bignumber', // Choose 'number' (default), 'bignumber', or 'fraction'
precision: 32 // 64 by default, only applicable for BigNumbers
});
// parser will parse numbers as BigNumber now:
bigmath.eval('1 / 3'); // BigNumber, 0.33333333333333333333333333333333
```
### browser
```html
<!DOCTYPE HTML>
<html>
<head>
<script src="math.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
// the default instance of math.js is available as 'math'
// range will output a Matrix
math.range(0, 4); // Matrix [0, 1, 2, 3]
// change the configuration of math from Matrices to Arrays
math.config({
matrix: 'array' // Choose 'matrix' (default) or 'array'
});
// range will output an Array
math.range(0, 4); // Array [0, 1, 2, 3]
// create a new instance of math.js with bignumber configuration
var bigmath = math.create({
number: 'bignumber', // Choose 'number' (default), 'bignumber', or 'fraction'
precision: 32 // 64 by default, only applicable for BigNumbers
});
// parser will parse numbers as BigNumber now:
bigmath.eval('1 / 3'); // BigNumber, 0.33333333333333333333333333333333
</script>
</body>
</html>
```
This page has been moved [here](core/configuration.md).

3
docs/core.md Normal file
View File

@ -0,0 +1,3 @@
# Core
This page has been moved [here](core/index.md).

41
docs/core/chaining.md Normal file
View File

@ -0,0 +1,41 @@
# Chaining
Math.js supports chaining operations by wrapping a value into a `Chain`.
A chain can be created with the function `math.chain(value)`
(formerly `math.select(value)`).
All functions available in the math namespace can be executed via the chain.
The functions will be executed with the chain's value as the first argument,
followed by extra arguments provided by the function call itself.
```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]]
```
### API
A `Chain` is constructed as:
```js
math.chain()
math.chain(value)
```
The `Chain` has all functions available in the `math` namespace, and has
a number of special functions:
- `done()`
Finalize the chain and return the chain's value.
- `valueOf()`
The same as `done()`, returns the chain's value.
- `toString()`
Executes `math.format(value)` onto the chain's value, returning
a string representation of the value.

125
docs/core/configuration.md Normal file
View File

@ -0,0 +1,125 @@
# Configuration
Math.js contains a number of configuration options. There are two ways to
configure math.js:
- Configure an existing instance of math.js using `math.config(options)`,
for example `math.config({number: 'BigNumber'})` to change to BigNumbers.
- Create and configure a new instance of math.js using `math.create([options])`,
for example `var bigmath = math.create({number: 'BigNumber'})` to create a new
instance configured to use BigNumbers.
The following configuration options are available:
- `epsilon`. The minimum relative difference used to test equality between two
compared values. This value is used by all relational functions.
Default value is `1e-14`.
- `matrix`. The default type of matrix output for functions.
Available values are: `'Matrix'` (default) or `'Array'`.
Where possible, the type of matrix output from functions is determined from
the function input: An array as input will return an Array, a Matrix as input
will return a Matrix. In case of no matrix as input, the type of output is
determined by the option `matrix`. In case of mixed matrix
inputs, a matrix will be returned always.
- `number`. The default type of numbers. This setting is used by functions
like `eval` which cannot determine the correct type of output from the
functions input. For most functions though, the type of output is determined
from the the input: a number as input will return a number as output,
a BigNumber as input returns a BigNumber as output.
Available values are: `'number'` (default), `'BigNumber'`, or `'Fraction'`.
[BigNumbers](../datatypes/bignumbers.js) have higher precision than the default
numbers of JavaScript, and [`Fractions`](../datatypes/fractions.js) store
values in terms of a numerator and denominator.
- `precision`. The maximum number of significant digits for bigNumbers.
This setting only applies to BigNumbers, not to numbers.
Default value is `64`.
- `predictable`. Predictable output type of functions. When true, output type
depends only on the input types. When false (default), output type can vary
depending on input values. For example `math.sqrt(-2)` returns `NaN` when
predictable is false, and returns `complex('2i')` when true.
Predictable output can be needed when programmatically handling the result of
a calculation, but can be inconvenient for users when evaluating dynamic
equations.
## Examples
This section shows a number of configuration examples.
### node.js
```js
// load the default instance of math.js
var math = require('mathjs');
// range will output a Matrix
math.range(0, 4); // Matrix [0, 1, 2, 3]
// create a new instance configured to use Arrays
var math2 = math.create({
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
});
// range will output an Array
math2.range(0, 4); // Array [0, 1, 2, 3]
// change the configuration of math2 from Arrays to Matrices
math2.config({
matrix: 'Matrix' // Choose 'Matrix' (default) or 'Array'
});
// range will output a Matrix
math2.range(0, 4); // Matrix [0, 1, 2, 3]
// create an instance of math.js with BigNumber configuration
var bigmath = math.create({
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
precision: 32 // 64 by default, only applicable for BigNumbers
});
// parser will parse numbers as BigNumber now:
bigmath.eval('1 / 3'); // BigNumber, 0.33333333333333333333333333333333
```
### browser
```html
<!DOCTYPE HTML>
<html>
<head>
<script src="math.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
// the default instance of math.js is available as 'math'
// range will output a Matrix
math.range(0, 4); // Matrix [0, 1, 2, 3]
// change the configuration of math from Matrices to Arrays
math.config({
matrix: 'Array' // Choose 'Matrix' (default) or 'Array'
});
// range will output an Array
math.range(0, 4); // Array [0, 1, 2, 3]
// create a new instance of math.js with bignumber configuration
var bigmath = math.create({
number: 'BigNumber', // Choose 'number' (default), 'BigNumber', or 'Fraction'
precision: 32 // 64 by default, only applicable for BigNumbers
});
// parser will parse numbers as BigNumber now:
bigmath.eval('1 / 3'); // BigNumber, 0.33333333333333333333333333333333
</script>
</body>
</html>
```

236
docs/core/extension.md Normal file
View File

@ -0,0 +1,236 @@
# Extension
The library can easily be extended with functions and variables using the
[`import`](../reference/functions/import.md) function. The function `import`
accepts an object with functions and variables.
Function `import` has the following syntax:
```js
math.import(object: Object [, options: Object])
```
Where:
- `object` is an object or array containing the functions and/or values to be
imported. `import` support regular values and functions, typed functions
(see section [Typed functions](#typed-functions)), and factory functions
(see section [Factory functions](#factory-functions)).
An array is only applicable when it contains factory functions.
- `options` is an optional second argument with options.
The following options are available:
- `{boolean} override`
If `true`, existing functions will be overwritten. The default value is `false`.
- `{boolean} silent`
If `true`, the function will not throw errors on duplicates or invalid
types. Default value is `false`.
- `{boolean} wrap`
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 the math.js data types. The default value is `false`.
The following code example shows how to import a function and a value into math.js:
```js
// define new functions and variables
math.import({
myvalue: 42,
hello: function (name) {
return 'hello, ' + name + '!';
}
});
// defined functions can be used in both JavaScript as well as the parser
math.myvalue * 2; // 84
math.hello('user'); // 'hello, user!'
var parser = math.parser();
parser.eval('myvalue + 10'); // 52
parser.eval('hello("user")'); // 'hello, user!'
```
## Import external libraries
External libraries like
[numbers.js](https://github.com/sjkaliski/numbers.js) and
[numeric.js](http://numericjs.com/) can be imported as follows.
The libraries must be installed using npm:
$ npm install numbers
$ npm install numeric
The libraries can be easily imported into math.js using `import`.
In order to convert math.js specific data types like `Matrix` to primitive types
like `Array`, the imported functions can be wrapped by enabling `{wrap: true}`.
```js
// import the numbers.js and numeric.js libraries into math.js
math.import(require('numbers'), {wrap: true, silent: true});
math.import(require('numeric'), {wrap: true, silent: true});
// use functions from numbers.js
math.fibonacci(7); // 13
math.eval('fibonacci(7)'); // 13
// use functions from numeric.js
math.eval('eig([1, 2; 4, 3])').lambda.x; // [5, -1]
```
## Typed functions
Typed functions can be created using `math.typed`. A typed function is a function
which does type checking on the input arguments. It can have multiple signatures.
And can automatically convert input types where needed.
A typed function can be created like:
```js
var max = typed('max', {
'number, number': function (a, b) {
return Math.max(a, b);
},
'BigNumber, BigNumber': function (a, b) {
return a.greaterThan(b) ? a : b;
}
});
```
Typed functions can be merged as long as there are no conflicts in the signatures.
This allows for extending existing functions in math.js with support for new
data types.
```js
// create a new data type
function MyType (value) {
this.value = value;
}
MyType.prototype.isMyType = true;
MyType.prototype.toString = function () {
return 'MyType:' + this.value;
}
// define a new datatype
math.typed.addType({
name: 'MyType',
test: function (x) {
// test whether x is of type MyType
return x && x.isMyType;
}
})
// use the type in a new typed function
var add = typed('add', {
'MyType, MyType': function (a, b) {
return new MyType(a.value + b.value);
}
});
// import in math.js, extend the existing function `add` with support for MyType
math.import({add: add});
// use the new type
var ans = math.add(new MyType(2), new MyType(3)); // returns MyType(5)
console.log(ans); // outputs 'MyType:5'
```
Detailed information on typed functions is available here:
[https://github.com/josdejong/typed-function](https://github.com/josdejong/typed-function)
## Factory functions
Regular JavaScript functions can be imported in math.js using `math.import`:
```js
math.import({
myFunction: function (a, b) {
// ...
}
});
```
The function can be stored in a separate file:
```js
exports.myFunction = function (a, b) {
// ...
}
```
Which can be imported like:
```js
math.import(require('./myFunction.js'));
```
An issue arises when `myFunction` needs functionality from math.js:
it doesn't have access to the current instance of math.js when in a separate file.
Factory functions can be used to solve this issue. A file exporting a factory function
looks like:
```js
exports.name = 'myFunction';
exports.factory = function (type, config, load, typed) {
return myFunction (a, b) {
// ...
}
};
```
The file exports a name and a factory function. When running `math.import`, the factory
function is invoked by math.js with four arguments:
- `type: Object`: Object containing the data types of math.js,
like `type.BigNumber` and `type.Unit`.
- `config: Object`: object with the configuration of math.js.
- `load: function`: loader function to access functions from math.js. For example to
load the function `add`:
```js
exports.factory = function (type, config, load, typed) {
var add = load(require('mathjs/lib/function/arithmetic/add'));
return myFunction (a, b) {
// ...
}
};
```
- `typed: function`: function to create typed-functions.
The result returned by a factory function will be imported into the `math`
namespace under the given `name`, `math.myFunction` in the above example.
A factory can contain the following properties:
- `name: string`. The name of the exported function or value. Required.
- `factory: function (type, config, load, typed) `. The factory function,
must return the function or value to be imported in math.js. Required.
- `path: string`. An optional path to where the function or value will be
imported. By default, imported functions have no path and are imported in
the 'flat' namespace `math`. Data types have `type` as path, and will be
located under `math.type.*`. Optional.
- `lazy: boolean`. If true (default), the factory function will be lazy loaded:
it is executed as soon as the function is about to be used.
- `math: boolean`. False by default. If true, the `math` namespace is passed
to the factory function as fifth argument. Should not be used unless there
is a very good reason for it.
To import a set of factory functions, the function `math.import` accepts an
array containing factory functions:
```js
math.import([
require('./myFactoryFunction1.js'),
require('./myFactoryFunction2.js'),
require('./myFactoryFunction3.js'),
// ...
]);
```

21
docs/core/index.md Normal file
View File

@ -0,0 +1,21 @@
# Core
## Usage
The core of math.js is the `math` namespace containing all functions and constants. There are three ways to do calculations in math.js:
- Doing regular function calls like `math.add(math.sqrt(4), 2)`.
- Evaluating expressions like `math.eval('sqrt(4) + 2')`
- Chaining operations like `math.chain(4).sqrt().add(2)`.
## Configuration
math.js can be configured using the `math.config()`, see page [Configuration](configuration.md).
## Extension
math.js can be extended with new functions and constants using the function `math.import()`, see page [Extension](extension.md).
## Serialization
To persist or exchange data structures like matrices and units, the data types of math.js can be stringified as JSON. This is explained on the page [Serialization](serialization.md).

View File

@ -0,0 +1,38 @@
# Serialization
Math.js has a number of data types like `Matrix`, `Complex`, and `Unit`. These
types are instantiated JavaScript objects. To be able to store these data types
or send them between processes, they must be serialized. The data types of
math.js can be serialized to JSON. Use cases:
- Store data in a database or on disk.
- Interchange of data between a server and a client.
- Interchange of data between a web worker and the browser.
Math.js types can be serialized using JavaScript's built-in `JSON.stringify`
function:
```js
var x = math.complex('2 + 3i');
var str = JSON.stringify(x);
console.log(str);
// outputs a string '{"mathjs":"Complex","re":2,"im":3}'
```
In order to deserialize a string, containing math.js data types, `JSON.parse`
can be used. In order to recognize the data types of math.js, `JSON.parse` must
be called with the reviver function of math.js:
```js
var json = '{"mathjs":"Unit","value":5,"unit":"cm","fixPrefix":false}';
var x = JSON.parse(json, math.json.reviver); // Unit 5 cm
```
Note that if math.js is used in conjunction with other data types, it is
possible to use multiple reviver functions at the same time by cascading them:
```js
var reviver = function (key, value) {
return reviver1(key, reviver2(key, value));
}
```

View File

@ -47,7 +47,7 @@ math.import(require('mathjs/lib/function/arithmetic/add'));
math.import(require('mathjs/lib/function/arithmetic/subtract'));
math.import(require('mathjs/lib/function/arithmetic/multiply'));
math.import(require('mathjs/lib/function/arithmetic/divide'));
math.import(require('mathjs/lib/function/utils/format'));
math.import(require('mathjs/lib/function/string/format'));
```
To see which data types and categories are available, explore the `index.js`

View File

@ -21,8 +21,8 @@ BigNumbers instead of [numbers](numbers.md) by default, configure math.js like:
```js
math.config({
number: 'bignumber', // Default type of number:
// 'number' (default), 'bignumber', or 'fraction'
number: 'BigNumber', // Default type of number:
// 'number' (default), 'BigNumber', or 'Fraction'
precision: 64 // Number of significant digits for BigNumbers
});

View File

@ -1,6 +1,7 @@
# Complex Numbers
Math.js supports the creation, manipulation, and calculations with complex numbers.
Support of complex numbers is powered by the library [complex.js](https://github.com/infusion/Complex.js).
In mathematics, a complex number is an expression of the form `a + bi`,
where `a` and `b` are real numbers and `i` represents the imaginary number
@ -11,7 +12,7 @@ complex number, having real part `3` and imaginary part `2`.
Complex numbers are often used in applied mathematics, control theory,
signal analysis, fluid dynamics and other fields.
## API
## Usage
A complex number is created using the function `math.complex`. This function
accepts:
@ -47,38 +48,6 @@ b.re = 5; // Number 5
b; // Complex 5 - 2i
```
A `Complex` object has the following properties:
- `re`. A number containing the real part of the complex number.
- `im`. A number containing the imaginary part of the complex number.
The properties `re` and `im` of a complex number can be read and replaced.
A `Complex` object has the following functions:
- `clone()`. Create a clone of the complex number.
- `equals(other)`. Test whether a complex number equals another complex value.
Two complex numbers are equal when both their real and imaginary parts are
equal.
- `format([precision: number])`. Get a string representation of the complex number,
formatted as `a + bi` where `a` is the real part and `b` the imaginary part.
If precision is defined, the units value will be rounded to the provided
number of digits.
- `fromJSON(json)`. Revive a complex number from a JSON object. Accepts
An object `{mathjs: 'Complex', re: number, im: number}`, where the property
`mathjs` is optional.
Used when deserializing a complex number, see [Serialization](../serialization.md).
- `fromPolar(r: number, phi: number)`. Create a complex number from polar
coordinates.
- `toJSON()`. Returns a JSON representation of the complex number, with signature
`{mathjs: 'Complex', re: number, im: number}`.
Used when serializing a complex number, see [Serialization](../serialization.md).
- `toPolar()`. Get the polar coordinates of the complex number, returns
an object with properties `r` and `phi`.
- `toString()`. Returns a string representation of the complex number, formatted
as `a + bi` where `a` is the real part and `b` the imaginary part.
## Calculations
Most functions of math.js support complex numbers. Complex and real numbers
@ -96,3 +65,59 @@ math.add(a, b); // Complex 6 + i
math.multiply(a, 2); // Complex 4 + 6i
math.sqrt(-4); // Complex 2i
```
## API
A `Complex` object contains the following properties and functions:
### complex.re
A number containing the real part of the complex number. Can be read and replaced.
### complex.im
A number containing the imaginary part of the complex number. Can be read and replaced.
### complex.clone()
Create a clone of the complex number.
### complex.equals(other)
Test whether a complex number equals another complex value.
Two complex numbers are equal when both their real and imaginary parts are
equal.
### complex.format([precision: number])
Get a string representation of the complex number,
formatted as `a + bi` where `a` is the real part and `b` the imaginary part.
If precision is defined, the units value will be rounded to the provided
number of digits.
### complex.fromJSON(json)
Revive a complex number from a JSON object. Accepts
An object `{mathjs: 'Complex', re: number, im: number}`, where the property
`mathjs` is optional.
Used when deserializing a complex number, see [Serialization](../core/serialization.md).
### complex.fromPolar(r: number, phi: number)
Create a complex number from polar coordinates.
### complex.toJSON()
Returns a JSON representation of the complex number, with signature
`{mathjs: 'Complex', re: number, im: number}`.
Used when serializing a complex number, see [Serialization](../core/serialization.md).
### complex.toPolar()
Get the polar coordinates of the complex number, returns
an object with properties `r` and `phi`.
### complex.toString()
Returns a string representation of the complex number, formatted
as `a + bi` where `a` is the real part and `b` the imaginary part.

View File

@ -36,9 +36,9 @@ which can be configured when instantiating math.js. To configure the use of
fractions instead of [numbers](numbers.md) by default, configure math.js like:
```js
// Configure the default type of number: 'number' (default), 'bignumber', or 'fraction'
// Configure the default type of number: 'number' (default), 'BigNumber', or 'Fraction'
math.config({
number: 'fraction'
number: 'Fraction'
});
// use the expression parser

View File

@ -17,6 +17,9 @@ The supported data types are:
- [Unit](units.md)
- String
Function [`math.typeof(x)`](../reference/functions/typeof.md) can be used to get
the type of a variable.
Example usage:
```js
@ -56,4 +59,9 @@ math.sqrt(matrix); // Matrix, [1, 2, 3, 4, 5]
var a = math.unit(55, 'cm'); // 550 mm
var b = math.unit('0.1m'); // 100 mm
math.add(a, b); // 0.65 m
// check the type of a variable
math.typeof(2); // 'number'
math.typeof(math.unit('2 inch')); // 'Unit'
math.typeof(math.sqrt(-4)); // 'Complex'
```

View File

@ -22,7 +22,7 @@ function input: An `Array` as input will return an `Array`, a `Matrix` as input
will return a `Matrix`. In case of mixed input, a `Matrix` is returned.
For functions where the type of output cannot be determined from the
input, the output is determined by the configuration option `matrix`,
which can be a string `'matrix'` (default) or `'array'`.
which can be a string `'Matrix'` (default) or `'Array'`.
```js
// create an array and a matrix
@ -326,3 +326,18 @@ The type of matrix can be selected when creating a matrix using the construction
var m1 = math.matrix([[0, 1], [0, 0]], 'sparse');
var m2 = math.eye(1000, 1000, 'sparse');
```
## API
All relevant functions in math.js support Matrices and Arrays. Functions like `math.add` and `math.subtract`, `math.sqrt` handle matrices element wise. There is a set of functions specifically for creating or manipulating matrices, such as:
- Functions like `math.matrix` and `math.sparse`, `math.ones`, `math.zeros`, and `math.eye` to create a matrix.
- Functions like `math.subset` and `math.index` to get or replace a part of a matrix
- Functions like `math.transpose` and `math.diag` to manipulate matrices.
A full list of matrix functions is available on the [functions reference page](../reference/functions.md#matrix-functions).
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.
- [DenseMatrix](../reference/classes/densematrix.md)
- [SparseMatrix](../reference/classes/sparsematrix.md)

View File

@ -20,7 +20,7 @@ can be configured when instantiating math.js:
```js
math.config({
number: 'number' // Default type of number:
// 'number' (default), 'bignumber', or 'fraction'
// 'number' (default), 'BigNumber', or 'Fraction'
});
```
@ -50,6 +50,9 @@ var ans = math.add(0.1, 0.2); // 0.30000000000000004
math.format(ans, {precision: 14}); // '0.3'
```
Alternatives are to use [Fractions](fractions.md) which store a number as a numerator and denominator, or [BigNumbers](bignumbers.md), which store a number with a higher precision.
## Minimum and maximum
A Number can store values between `5e-324` and `1.7976931348623157e+308`.
@ -79,7 +82,7 @@ option `epsilon`. In pseudo code (without exceptions for 0, Infinity and NaN):
where:
- `EPSILON` is the relative difference between x and y. Epsilon is configurable
and is `1e-14` by default. See [Configuration](../configuration.md).
and is `1e-14` by default. See [Configuration](../core/configuration.md).
- `DBL_EPSILON` is the minimum positive floating point number such that
`1.0 + DBL_EPSILON != 1.0`. This is a constant with a value of approximately
`2.2204460492503130808472633361816e-16`;

View File

@ -3,8 +3,7 @@
Math.js supports units. Units can be used to do calculations and to perform
conversions.
## API
## Usage
Units can be created using the function `math.unit`. This function accepts
either a single string argument containing a value and unit, or two arguments,
@ -30,35 +29,6 @@ var d = math.unit('90 km/h'); // Unit 90 km/h
var e = math.unit('101325 kg/(m s^2)'); // Unit 101325 kg / (m s^2)
```
A `Unit` contains the following functions:
- `clone()`. Clone the unit, returns a new unit with the same parameters.
- `equalBase(unit)`. Test whether a unit has the same base as an other unit:
length, mass, etc.
- `equals(unit)`. Test whether a unit equals an other unit. Units are equal
when they have the same base and same value when normalized to SI units.
- `format([precision])`. Get a string representation of the unit. The function
will determine the best fitting prefix for the unit. If precision is defined,
the units value will be rounded to the provided number of digits.
- `fromJSON(json)`. Revive a unit from a JSON object. Accepts
An object `{mathjs: 'Unit', value: number, unit: string, fixPrefix: boolean}`,
where the property `mathjs` and `fixPrefix` are optional.
Used when deserializing a unit, see [Serialization](../serialization.md).
- `to(unitName)`. Convert the unit to a specific unit name. Returns a clone of
the unit with a fixed prefix and unit.
- `toJSON()`. Returns a JSON representation of the unit, with signature
`{mathjs: 'Unit', value: number, unit: string, fixPrefix: boolean}`.
Used when serializing a unit, see [Serialization](../serialization.md).
- `toNumber(unitName)`. Get the value of a unit when converted to the
specified unit (a unit with optional prefix but without value).
The type of the returned value is always `number`.
- `toNumeric(unitName)`. Get the value of a unit when converted to the
specified unit (a unit with optional prefix but without value).
The type of the returned value depends on how the unit was created and
can be `number`, `Fraction`, or `BigNumber`.
- `toString()`. Get a string representation of the unit. The function will
determine the best fitting prefix for the unit.
```js
var a = math.unit(55, 'cm'); // Unit 550 mm
var b = math.unit('0.1 kilogram'); // Unit 100 gram
@ -142,7 +112,313 @@ var Trate2 = math.eval('(5 degC)/hour'); // Unit 278.15 degC/hour
The expression parser supports units too. This is described in the section about
units on the page [Syntax](../expressions/syntax.md#units).
## User-Defined Units
You can add your own units to Math.js using the `math.createUnit` function. The following example defines a new unit `furlong`, then uses the user-defined unit in a calculation:
```js
math.createUnit('furlong', '220 yards');
math.eval('1 mile to furlong'); // 8 furlong
```
If you cannot express the new unit in terms of any existing unit, then the second argument can be omitted. In this case, a new base unit is created:
```js
// A 'foo' cannot be expressed in terms of any other unit.
math.createUnit('foo');
math.eval('8 foo * 4 feet'); // 32 foo feet
```
The second argument to `createUnit` can also be a configuration object consisting of the following properties:
* **definition** A `string` or `Unit` which defines the user-defined unit in terms of existing built-in or user-defined units. If omitted, a new base unit is created.
* **prefixes** A `string` indicating which prefixes math.js should use with the new unit. Possible values are `'none'`, `'short'`, `'long'`, `'binary_short'`, or `'binary_long'`. Default is `'none'`.
* **offset** A value applied when converting to the unit. This is very helpful for temperature scales that do not share a zero with the absolute temperature scale. For example, if we were defining fahrenheit for the first time, we would use: `math.createUnit('fahrenheit', {definition: '0.555556 kelvin', offset: 459.67})`
* **aliases** An array of strings to alias the new unit. Example: `math.createUnit('knot', {definition: '0.514444 m/s', aliases: ['knots', 'kt', 'kts']})`
An optional `options` object can also be supplied as the last argument to `createUnits`. Currently only the `override` option is supported:
```js
// Redefine the mile (would not be the first time in history)
math.createUnit('mile', '1609.347218694', {override: true}});
```
Base units created without specifying a definition cannot be overridden.
Multiple units can defined using a single call to `createUnit` by passing an object map as the first argument, where each key in the object is the name of a new unit and the value is either a string defining the unit, or an object with the configuration properties listed above. If the value is an empty string or an object lacking a definition property, a new base unit is created.
For example:
```js
math.createUnit( {
foo: {
prefixes: 'long'
},
bar: '40 foo',
baz: {
definition: '1 bar/hour',
prefixes: 'long'
}
},
{
override: true
});
math.eval('50000 kilofoo/s'); // 4.5 gigabaz
```
### Return Value
`createUnit` returns the created unit, or, when multiple units are created, the last unit created. Since `createUnit` is also compatible with the expression parser, this allows you to do things like this:
```js
math.eval('45 mile/hour to createUnit("knot", "0.514444m/s")')
// 39.103964668651976 knot
```
## API
A `Unit` object contains the following functions:
### unit.clone()
Clone the unit, returns a new unit with the same parameters.
### unit.equalBase(unit)
Test whether a unit has the same base as an other unit:
length, mass, etc.
### unit.equals(unit)
Test whether a unit equals an other unit. Units are equal
when they have the same base and same value when normalized to SI units.
### unit.format([precision])
Get a string representation of the unit. The function
will determine the best fitting prefix for the unit. If precision is defined,
the units value will be rounded to the provided number of digits.
### unit.fromJSON(json)
Revive a unit from a JSON object. Accepts
An object `{mathjs: 'Unit', value: number, unit: string, fixPrefix: boolean}`,
where the property `mathjs` and `fixPrefix` are optional.
Used when deserializing a unit, see [Serialization](../core/serialization.md).
### unit.splitUnit(parts)
Split a unit into the specified parts. For example:
```js
var u = math.unit(1, 'm');
u.splitUnit(['ft', 'in']); // 3 feet,3.3700787401574765 inch
```
### unit.to(unitName)
Convert the unit to a specific unit name. Returns a clone of
the unit with a fixed prefix and unit.
### unit.toJSON()
Returns a JSON representation of the unit, with signature
`{mathjs: 'Unit', value: number, unit: string, fixPrefix: boolean}`.
Used when serializing a unit, see [Serialization](../core/serialization.md).
### unit.toNumber(unitName)
Get the value of a unit when converted to the
specified unit (a unit with optional prefix but without value).
The type of the returned value is always `number`.
### unit.toNumeric(unitName)
Get the value of a unit when converted to the
specified unit (a unit with optional prefix but without value).
The type of the returned value depends on how the unit was created and
can be `number`, `Fraction`, or `BigNumber`.
### unit.toString()
Get a string representation of the unit. The function will
determine the best fitting prefix for the unit.
## Unit reference
This section lists all available units, prefixes, and physical constants. These can be used via the Unit object, or via `math.eval()`.
## Reference
All available units and prefixes are listed on the page [Unit reference](../reference/units.md).
Math.js comes with the following built-in units.
Base | Unit
------------------- | ---
Length | meter (m), inch (in), foot (ft), yard (yd), mile (mi), link (li), rod (rd), chain (ch), angstrom, mil
Surface area | m2, sqin, sqft, sqyd, sqmi, sqrd, sqch, sqmil, acre, hectare
Volume | m3, litre (l, L, lt, liter), cc, cuin, cuft, cuyd, teaspoon, tablespoon
Liquid volume | minim (min), fluiddram (fldr), fluidounce (floz), gill (gi), cup (cp), pint (pt), quart (qt), gallon (gal), beerbarrel (bbl), oilbarrel (obl), hogshead, drop (gtt)
Angles | rad (radian), deg (degree), grad (gradian), cycle, arcsec (arcsecond), arcmin (arcminute)
Time | second (s, secs, seconds), minute (mins, minutes), hour (h, hr, hrs, hours), day (days), week (weeks), month (months), year (years), decade (decades), century (centuries), millennium (millennia)
Frequency | hertz (Hz)
Mass | gram(g), tonne, ton, grain (gr), dram (dr), ounce (oz), poundmass (lbm, lb, lbs), hundredweight (cwt), stick, stone
Electric current | ampere (A)
Temperature | kelvin (K), celsius (degC), fahrenheit (degF), rankine (degR)
Amount of substance | mole (mol)
Luminous intensity | candela (cd)
Force | newton (N), dyne (dyn), poundforce (lbf), kip
Energy | joule (J), erg, Wh, BTU, electronvolt (eV)
Power | watt (W), hp
Pressure | Pa, psi, atm, torr, bar, mmHg, mmH2O, cmH2O
Electricity and magnetism | ampere (A), coulomb (C), watt (W), volt (V), ohm, farad (F), weber (Wb), tesla (T), henry (H), siemens (S), electronvolt (eV)
Binary | bit (b), byte (B)
Note: all time units are based on the Julian year, with one month being 1/12th of a Julian year, a year being one Julian year, a decade being 10 Julian years, a century being 100, and a millennium being 1000.
Note that all relevant units can also be written in plural form, for example `5 meters` instead of `5 meter` or `10 seconds` instead of `10 second`.
Surface and volume units can alternatively be expressed in terms of length units raised to a power, for example `100 in^2` instead of `100 sqin`.
### Prefixes
The following decimal prefixes are available.
Name | Abbreviation | Value
------- | ------------- | -----
deca | da | 1e1
hecto | h | 1e2
kilo | k | 1e3
mega | M | 1e6
giga | G | 1e9
tera | T | 1e12
peta | P | 1e15
exa | E | 1e18
zetta | Z | 1e21
yotta | Y | 1e24
Name | Abbreviation | Value
------ | ------------- | -----
deci | d | 1e-1
centi | c | 1e-2
milli | m | 1e-3
micro | u | 1e-6
nano | n | 1e-9
pico | p | 1e-12
femto | f | 1e-15
atto | a | 1e-18
zepto | z | 1e-21
yocto | y | 1e-24
The following binary prefixes are available.
They can be used with units `bit` (`b`) and `byte` (`B`).
Name | Abbreviation | Value
---- | ------------ | -----
kibi | Ki | 1024
mebi | Mi | 1024^2
gibi | Gi | 1024^3
tebi | Ti | 1024^4
pebi | Pi | 1024^5
exi | Ei | 1024^6
zebi | Zi | 1024^7
yobi | Yi | 1024^8
Name | Abbreviation | Value
----- | ------------ | -----
kilo | k | 1e3
mega | M | 1e6
giga | G | 1e9
tera | T | 1e12
peta | P | 1e15
exa | E | 1e18
zetta | Z | 1e21
yotta | Y | 1e24
### Physical Constants
Math.js includes the following physical constants. See [Wikipedia](http://en.wikipedia.org/wiki/Physical_constants) for more information.
#### Universal constants
Name | Symbol | Value | Unit
----------------------|--------------------------------------------------------|-------------------|-------------------------------------------------------
speedOfLight | <i>c</i> | 299792458 | m &#183; s<sup>-1</sup>
gravitationConstant | <i>G</i> | 6.6738480e-11 | m<sup>3</sup> &#183; kg<sup>-1</sup> &#183; s<sup>-2</sup>
planckConstant | <i>h</i> | 6.626069311e-34 | J &#183; s
reducedPlanckConstant | <i><span style="text-decoration:overline">h</span></i> | 1.05457172647e-34 | J &#183; s
#### Electromagnetic constants
Name | Symbol | Value | Unit
--------------------------|--------------------------------------------------|-----------------------|----------------------------------------
magneticConstant | <i>&mu;<sub>0</sub></i> | 1.2566370614e-6 | N &#183; A<sup>-2</sup>
electricConstant | <i>&epsilon;<sub>0</sub></i> | 8.854187817e-12 | F &#183; m<sup>-1</sup>
vacuumImpedance | <i>Z<sub>0</sub></i> | 376.730313461 | &ohm;
coulomb | <i>&kappa;</i> | 8.9875517873681764e9 | N &#183; m<sup>2</sup> &#183; C<sup>-2</sup>
elementaryCharge | <i>e</i> | 1.60217656535e-19 | C
bohrMagneton | <i>&mu;<sub>B</sub></i> | 9.2740096820e-24 | J &#183; T<sup>-1</sup>
conductanceQuantum | <i>G<sub>0</sub></i> | 7.748091734625e-5 | S
inverseConductanceQuantum | <i>G<sub>0</sub><sup>-1</sup></i> | 12906.403721742 | &ohm;
magneticFluxQuantum | <i><font face="Symbol">f</font><sub>0</sub></i> | 2.06783375846e-15 | Wb
nuclearMagneton | <i>&mu;<sub>N</sub></i> | 5.0507835311e-27 | J &#183; T<sup>-1</sup>
klitzing | <i>R<sub>K</sub></i> | 25812.807443484 | &ohm;
<!-- TODO: implement josephson
josephson | <i>K<sub>J</sub></i> | 4.8359787011e-14 | Hz &#183; V<sup>-1</sup>
-->
#### Atomic and nuclear constants
Name | Symbol | Value | Unit
------------------------|------------------------------|-----------------------|----------------------------------
bohrRadius | <i>a<sub>0</sub></i> | 5.291772109217e-11 | m
classicalElectronRadius | <i>r<sub>e</sub></i> | 2.817940326727e-15 | m
electronMass | <i>m<sub>e</sub></i> | 9.1093829140e-31 | kg
fermiCoupling | <i>G<sub>F</sub></i> | 1.1663645e-5 | GeV<sup>-2</sup>
fineStructure | <i>&alpha;</i> | 7.297352569824e-3 | -
hartreeEnergy | <i>E<abbr>h</abbr> </i> | 4.3597443419e-18 | J
protonMass | <i>m<sub>p</sub></i> | 1.67262177774e-27 | kg
deuteronMass | <i>m<sub>d</sub></i> | 3.3435830926e-27 | kg
neutronMass | <i>m<sub>n</sub></i> | 1.6749271613e-27 | kg
quantumOfCirculation | <i>h / (2m<sub>e</sub>)</i> | 3.636947552024e-4 | m<sup>2</sup> &#183; s<sup>-1</sup>
rydberg | <i>R<sub>&infin;</sub></i> | 10973731.56853955 | m<sup>-1</sup>
thomsonCrossSection | | 6.65245873413e-29 | m<sup>2</sup>
weakMixingAngle | | 0.222321 | -
efimovFactor | | 22.7 | -
#### Physico-chemical constants
Name | Symbol | Value | Unit
--------------------|------------------------------|---------------------|--------------------------------------------
atomicMass | <i>m<sub>u</sub></i> | 1.66053892173e-27 | kg
avogadro | <i>N<sub>A</sub></i> | 6.0221412927e23 | mol<sup>-1</sup>
boltzmann | <i>k</i> | 1.380648813e-23 | J &#183; K<sup>-1</sup>
faraday | <i>F</i> | 96485.336521 | C &#183; mol<sup>-1</sup>
firstRadiation | <i>c<sub>1</sub></i> | 3.7417715317e-16 | W &#183; m<sup>2</sup>
loschmidt | <i>n<sub>0</sub></i> | 2.686780524e25 | m<sup>-3</sup>
gasConstant | <i>R</i> | 8.314462175 | J &#183; K<sup>-1</sup> &#183; mol<sup>-1</sup>
molarPlanckConstant | <i>N<sub>A</sub> &#183; h</i>| 3.990312717628e-10| J &#183; s &#183; mol<sup>-1</sup>
molarVolume | <i>V<sub>m</sub></i> | 2.241396820e-10 | m<sup>3</sup> &#183; mol<sup>-1</sup>
sackurTetrode | | -1.164870823 | -
secondRadiation | <i>c<sub>2</sub></i> | 1.438777013e-2 | m &#183; K
stefanBoltzmann | <i>&sigma;</i> | 5.67037321e-8 | W &#183; m<sup>-2</sup> &#183; K<sup>-4</sup>
wienDisplacement | <i>b</i> | 2.897772126e-3 | m &#183; K
<!-- TODO: implement spectralRadiance
spectralRadiance | <i>c<sub>1L</sub></i> | 1.19104286953e-16 | W &#183; m<sup>2</sup> &#183; sr<sup>-1</sup>
-->
Note that the values of `loschmidt` and `molarVolume` are at `T = 273.15 K` and `p = 101.325 kPa`.
The value of `sackurTetrode` is at `T = 1 K` and `p = 101.325 kPa`.
#### Adopted values
Name | Symbol | Value | Unit
--------------|------------------------------|---------|-------------------------
molarMass | <i>M<sub>u</sub></i> | 1e-3 | kg &#183; mol<sup>-1</sup>
molarMassC12 | <i>M(<sub>12</sub>C)</i> | 1.2e-2 | kg &#183; mol<sup>-1</sup>
gravity | <i>g<sub>n</sub></i> | 9.80665 | m &#183; s<sup>-2</sup>
atm | <i>atm</i> | 101325 | Pa
#### Natural units
Name | Symbol | Value | Unit
------------------|-----------------------|--------------------|-----
planckLength | <i>l<sub>P</sub></i> | 1.61619997e-35 | m
planckMass | <i>m<sub>P</sub></i> | 2.1765113e-8 | kg
planckTime | <i>t<sub>P</sub></i> | 5.3910632e-44 | s
planckCharge | <i>q<sub>P</sub></i> | 1.87554595641e-18 | C
planckTemperature | <i>T<sub>P</sub></i> | 1.41683385e+32 | K

View File

@ -10,6 +10,7 @@ On this page:
- [Custom argument parsing](#custom-argument-parsing)
- [Custom LaTeX handlers](#custom-latex-handlers)
- [Custom LaTeX and string output](#custom-latex-and-string-output)
- [Customize supported characters](#customize-supported-characters)
## Function transforms
@ -156,10 +157,10 @@ or a template string similar to ES6 templates.
### Template syntax
* `${name}`: Gets replaced by the name of the function
* `${args}`: Gets replaced by a comma separated list of the arguments of the function.
* `${args[0]}`: Gets replaced by the first argument of a function
* `$$`: Gets replaced by `$`
- `${name}`: Gets replaced by the name of the function
- `${args}`: Gets replaced by a comma separated list of the arguments of the function.
- `${args[0]}`: Gets replaced by the first argument of a function
- `$$`: Gets replaced by `$`
#### Example
@ -197,16 +198,18 @@ The functions `toTex` and `toString` accept an `options` argument to customise o
```js
{
parenthesis: 'keep', // parenthesis option
handler: someHandler // handler to change the output
handler: someHandler, // handler to change the output
implicit: 'hide' // how to treat implicit multiplication
}
```
### Parenthesis
The `parenthesis` option changes the way parenteheses are used in the output. There are three options available:
* `keep`: Keep the parentheses from the input and display them as is. This is the default.
* `auto`: Only display parentheses that are necessary. Mathjs tries to get rid of as much parntheses as possible.
* `all`: Display all parentheses that are given by the structure of the node tree. This makes the output precedence unambiguous.
The `parenthesis` option changes the way parentheses are used in the output. There are three options available:
- `keep` Keep the parentheses from the input and display them as is. This is the default.
- `auto` Only display parentheses that are necessary. Mathjs tries to get rid of as much parentheses as possible.
- `all` Display all parentheses that are given by the structure of the node tree. This makes the output precedence unambiguous.
There's two ways of passing callbacks:
@ -324,3 +327,50 @@ var expression = math.parse('binomial(2,1)');
var latex = expression.toTex({handler: customLaTeX});
//latex now contains "\binom{2}{1}"
```
### Implicit multiplication
You can change the way that implicit multiplication is converted to a string or LaTeX. The two options are `hide`, to not show a multiplication operator for implicit multiplication and `show` to show it.
Example:
```js
var node = math.parse('2a');
node.toString(); //'2 a'
node.toString({implicit: 'hide'}); //'2 a'
node.toString({implicit: 'show'}); //'2 * a'
node.toTex(); //'2~ a'
node.toTex({implicit: 'hide'}); //'2~ a'
node.toTex({implicit: 'show'}); //'2\\cdot a'
```
## Customize supported characters
It is possible to customize the characters allowed in symbols and digits.
The `parse` function exposes the following test functions:
- `math.expression.parse.isAlpha(c, cPrev, cNext)`
- `math.expression.parse.isWhitespace(c, nestingLevel)`
- `math.expression.parse.isDecimalMark(c, cNext)`
- `math.expression.parse.isDigitDot(c)`
- `math.expression.parse.isDigit(c)`
The exact signature and implementation of these functions can be looked up in
the [source code of the parser](https://github.com/josdejong/mathjs/blob/master/lib/expression/parse.js). The allowed alpha characters are described here: [Constants and variables](syntax.md#constants-and-variables).
For example, the `$` character is not supported by default. It can be enabled
by replacing the `isAlpha` function:
```js
var isAlphaOriginal = math.expression.parse.isAlpha;
math.expression.parse.isAlpha = function (c, cPrev, cNext) {
return isAlphaOriginal(c, cPrev, cNext) || (c === '$');
};
// now we can use the $ character in expressions
var result = math.eval('$foo', {$foo: 42}); // returns 42
console.log(result);
```

View File

@ -64,13 +64,13 @@ All nodes have the following methods:
var eval = node.eval({x: 3}; // returns 5
```
- `filter(callback: function) : Array.<Node>`
- `filter(callback: function) : Node[]`
Filter nodes in an expression tree. The `callback` function is called as
`callback(node: Node, path: string, parent: Node) : boolean` for every node
in the tree, and must return a boolean. The function `filter` returns an
array with nodes for which the test returned true. Parameter `path` is a
string containing a relative JSON Path.
Recursively filter nodes in an expression tree. The `callback` function is
called as `callback(node: Node, path: string, parent: Node) : boolean` for
every node in the tree, and must return a boolean. The function `filter`
returns an array with nodes for which the test returned true.
Parameter `path` is a string containing a relative JSON Path.
Example:
@ -82,7 +82,7 @@ All nodes have the following methods:
// returns an array with two entries: two SymbolNodes 'x'
```
- `forEach(callback: function) : Array.<Node>`
- `forEach(callback: function) : Node[]`
Execute a callback for each of the child nodes of this node. The `callback`
function is called as `callback(child: Node, path: string, parent: Node)`.
@ -107,7 +107,7 @@ All nodes have the following methods:
// ConstantNode 2
```
- `map(callback: function) : Array.<Node>`
- `map(callback: function) : Node[]`
Transform a node. Creates a new Node having it's childs be the results of
calling the provided callback function for each of the childs of the original
@ -127,7 +127,7 @@ All nodes have the following methods:
node.toString(); // returns '3 + (4 * 2)'
```
Information about the options in [Customization](customization.md#custom-latex-and-string-conversion).
Information about the options in [Customization](customization.md#custom-latex-and-string-output).
- `toTex(options: object): string`
@ -139,7 +139,7 @@ All nodes have the following methods:
node.toTex(); // returns '\sqrt{\frac{2}{3}}'
```
Information about the options in [Customization](customization.md#custom-latex-and-string-conversion).
Information about the options in [Customization](customization.md#custom-latex-and-string-output).
- `transform(callback: function)`
@ -201,6 +201,12 @@ All nodes have the following methods:
Each `Node` has the following properties:
- `comment: string`
A string holding a comment if there was any in the expression, or else the
string will be empty string. A comment can be attached to the root node of
an expression or to each of the childs nodes of a `BlockNode`.
- `isNode: true`
Is defined with value `true` on Nodes. Additionally, each type of node
@ -217,17 +223,43 @@ Each `Node` has the following properties:
math.js has the following types of nodes. All nodes are available at the
namespace `math.expression.node`.
### AccessorNode
Construction:
```
new AccessorNode(object: Node, index: IndexNode)
```
Properties:
- `object: Node`
- `index: IndexNode`
- `name: string` (read-only) The function or method name. Returns an empty string when undefined.
Examples:
```js
var node1 = math.parse('a[3]');
var object = new math.expression.node.SymbolNode('a');
var index = new math.expression.node.IndexNode([3]);
var node2 = new math.expression.node.AccessorNode(object, index);
```
### ArrayNode
Construction:
```
new ArrayNode(nodes: Node[])
new ArrayNode(items: Node[])
```
Properties:
- `nodes: Node[]`
- `items: Node[]`
Examples:
@ -246,21 +278,25 @@ var node2 = new math.expression.node.ArrayNode([one, two, three]);
Construction:
```
new AssignmentNode(name: string, expr: Node)
new AssignmentNode(object: SymbolNode, value: Node)
new AssignmentNode(object: SymbolNode | AccessorNode, index: IndexNode, value: Node)
```
Properties:
- `name: string`
- `expr: Node`
- `object: SymbolNode | AccessorNode`
- `index: IndexNode | null`
- `value: Node`
- `name: string` (read-only) The function or method name. Returns an empty string when undefined.
Examples:
```js
var node1 = math.parse('a = 3');
var expr = new math.expression.node.ConstantNode(3);
var node2 = new math.expression.node.AssignmentNode('a', expr);
var object = new math.expression.node.SymbolNode('a');
var value = new math.expression.node.ConstantNode(3);
var node2 = new math.expression.node.AssignmentNode(object, value);
```
@ -287,19 +323,22 @@ Examples:
```js
var block1 = math.parse('a=1; b=2; c=3');
var a = new math.expression.node.SymbolNode('a');
var one = new math.expression.node.ConstantNode(1);
var a = new math.expression.node.AssignmentNode('a', one);
var ass1 = new math.expression.node.AssignmentNode(a, one);
var b = new math.expression.node.SymbolNode('b');
var two = new math.expression.node.ConstantNode(2);
var b = new math.expression.node.AssignmentNode('b', two);
var ass2 = new math.expression.node.AssignmentNode(b, two);
var c = new math.expression.node.SymbolNode('c');
var three = new math.expression.node.ConstantNode(3);
var c = new math.expression.node.AssignmentNode('c', three);
var ass3 = new math.expression.node.AssignmentNode(c, three);
var block2 = new BlockNode([
{node: a, visible: false},
{node: b, visible: false},
{node: c, visible: true}
{node: ass1, visible: false},
{node: ass2, visible: false},
{node: ass3, visible: true}
]);
```
@ -385,12 +424,13 @@ var node2 = new math.expression.node.FunctionAssignmentNode('f', ['x'], expr);
Construction:
```
new FunctionNode(name: string, args: Node[])
new FunctionNode(fn: Node, args: Node[])
```
Properties:
- `name: string`
- `object: Node`
- `name: string` (read-only) The function or method name. Returns an empty string when undefined.
- `args: Node[]`
Examples:
@ -399,7 +439,7 @@ Examples:
var node1 = math.parse('sqrt(4)');
var four = new math.expression.node.ConstantNode(4);
var node2 = new math.expression.node.FunctionNode('sqrt', [four]);
var node3 = new math.expression.node.FunctionNode(new SymbolNode('sqrt'), [four]);
```
@ -408,15 +448,22 @@ var node2 = new math.expression.node.FunctionNode('sqrt', [four]);
Construction:
```
new IndexNode(object: Node, ranges: Node[])
new IndexNode(dimensions: Node[])
new IndexNode(dimensions: Node[], dotNotation: boolean)
```
Note that ranges are one-based, including range end.
Each dimension can be a single value, a range, or a property. The values of
indices are one-based, including range end.
An optional property `dotNotation` can be provided describing whether this index
was written using dot notation like `a.b`, or using bracket notation
like `a["b"]`. Default value is `false`. This information is used when
stringifying the IndexNode.
Properties:
- `object: Node`
- `ranges: Node[]`
- `dimensions: Node[]`
- `dotNotation: boolean`
Examples:
@ -429,9 +476,34 @@ var two = new math.expression.node.ConstantNode(2);
var three = new math.expression.node.ConstantNode(3);
var range = new math.expression.node.RangeNode(one, three);
var node2 = new math.expression.node.IndexNode(A, [range, two]);
var index = new math.expression.node.IndexNode([range, two]);
var node2 = new math.expression.node.AccessNode(A, index);
```
### ObjectNode
Construction:
```
new ObjectNode(properties: Object.<string, Node>)
```
Properties:
- `properties: Object.<string, Node>`
Examples:
```js
var node1 = math.parse('{a: 1, b: 2, c: 3}');
var a = new math.expression.node.ConstantNode(1);
var b = new math.expression.node.ConstantNode(2);
var c = new math.expression.node.ConstantNode(3);
var node2 = new math.expression.node.ObjectNode({a: a, b: b, c: c});
```
### OperatorNode
Construction:
@ -526,31 +598,3 @@ var node = math.parse('x');
var x = new math.expression.node.SymbolNode('x');
```
### UpdateNode
Construction:
```
new UpdateNode(index: IndexNode, expr: Node)
```
Properties:
- `index: IndexNode`
- `expr: Node`
Examples:
```js
var node1 = math.parse('A[3, 1] = 4');
var A = new math.expression.node.SymbolNode('A');
var one = new math.expression.node.ConstantNode(1);
var three = new math.expression.node.ConstantNode(3);
var four = new math.expression.node.ConstantNode(4);
var index = new math.expression.node.IndexNode(A, [three, one]);
var node2 = new math.expression.node.UpdateNode(index, four);
```

View File

@ -166,6 +166,8 @@ The parser contains the following functions:
Evaluate an expression. Returns the result of the expression.
- `get(name)`
Retrieve a variable or function from the parser's scope.
- `getAll()`
Retrieve a map with all defined a variables from the parser's scope.
- `remove(name)`
Remove a variable or function from the parser's scope.
- `set(name, value)`

View File

@ -45,9 +45,11 @@ The following operators are available:
Operator | Name | Syntax | Associativity | Example | Result
----------- | ----------------------- | ---------- | ------------- | --------------------- | ---------------
`(`, `)` | Parentheses | `(x)` | None | `2 * (3 + 4)` | `14`
`(`, `)` | Grouping | `(x)` | None | `2 * (3 + 4)` | `14`
`[`, `]` | Matrix, Index | `[...]` | None | `[[1,2],[3,4]]` | `[[1,2],[3,4]]`
`{`, `}` | Object | `{...}` | None | `{a: 1, b: 2}` | `{a: 1, b: 2}`
`,` | Parameter separator | `x, y` | Left to right | `max(2, 1, 5)` | `5`
`.` | Property accessor | `obj.prop` | Left to right | `obj={a: 12}; obj.a` | `12`
`;` | Statement separator | `x; y` | Left to right | `a=2; b=3; a*b` | `[6]`
`;` | Row separator | `[x, y]` | Left to right | `[1,2;3,4]` | `[[1,2],[3,4]]`
`\n` | Statement separator | `x \n y` | Left to right | `a=2 \n b=3 \n a*b` | `[2,3,6]`
@ -93,7 +95,8 @@ The operators have the following precedence, from highest to lowest:
Operators | Description
--------------------------------- | --------------------
`x(...)` | Function call and matrix index
`(...)`<br>`[...]`<br>`{...}` | Grouping<br>Matrix<br>Object
`x(...)`<br>`x[...]`<br>`obj.prop`<br>`:`| Function call<br>Matrix index<br>Property accessor<br>Key/value separator
`'` | Matrix transpose
`!` | Factorial
`^`, `.^` | Exponentiation
@ -122,7 +125,7 @@ Operators | Description
Functions are called by entering their name, followed by zero or more
arguments enclosed by parentheses. All available functions are listed on the
page [Functions](../functions.md).
page [Functions](../reference/functions.md).
```js
math.eval('sqrt(25)'); // 5
@ -145,12 +148,23 @@ parser.eval('g(x, y) = x ^ y');
parser.eval('g(2, 3)'); // 8
```
Math.js itself heavily uses typed functions, which ensure correct inputs and
throws meaningful errors when the input arguments are invalid. One can create
a [typed-function](https://github.com/josdejong/typed-function) in the
expression parser like:
```js
var parser = math.parser();
parser.eval('f = typed({"number": f(x) = x ^ 2 - 5})');
```
## Constants and variables
Math.js has a number of built-in constants such as `pi` and `e`.
All available constants are listed on he page
[Constants](../constants.md).
[Constants](../reference/constants.md).
```js
// use constants
@ -174,11 +188,24 @@ parser.eval('b = 5 / 2'); // 2.5
parser.eval('a * b'); // 8.5
```
Variable names must:
- Begin with an "alpha character", which is:
- A latin letter (upper or lower case). Ascii: `a-z`, `A-Z`
- An underscore. Ascii: `_`
- A latin letter with accents. Unicode: `\u00C0` - `\u02AF`
- A greek letter. Unicode: `\u0370` - `\u03FF`
- A mathematical alphanumeric symbol. Unicode: `\u{1D400}` - `\u{1D7FF}` excluding invalid code points
- Contain only alpha characters (above) and digits `0-9`
- Not be any of the following: `mod`, `to`, `in`, `and`, `xor`, `or`, `not`, `end`. It is possible to assign to some of these, but that's not recommended.
It is possible to customize the allowed alpha characters, see [Customize supported characters](customization.md#customize-supported-characters) for more information.
## Data types
The expression parser supports booleans, numbers, complex numbers, units,
strings, and matrices.
strings, matrices, and objects.
### Booleans
@ -272,8 +299,8 @@ The default number type of the expression parser can be changed at instantiation
of math.js. The expression parser parses numbers as BigNumber by default:
```js
// Configure the type of number: 'number' (default), 'bignumber', or 'fraction'
math.config({number: 'bignumber'});
// Configure the type of number: 'number' (default), 'BigNumber', or 'Fraction'
math.config({number: 'BigNumber'});
// all numbers are parsed as BigNumber
math.eval('0.1 + 0.2'); // BigNumber, 0.3
@ -358,10 +385,11 @@ math.eval('9.81 m/s^2 * 5 s to mi/h') // Unit, 109.72172512527 mi / h
### Strings
Strings are enclosed by double quotes ". Strings can be concatenated by adding
them. Parts of a string can be retrieved or replaced by using indexes. Strings
can be converted to a number using function `number`, and numbers can be
converted to a string using function `string`.
Strings are enclosed by double quotes ". Strings can be concatenated using the
function `concat` (not by adding them using `+` like in JavaScript). Parts of
a string can be retrieved or replaced by using indexes. Strings can be converted
to a number using function `number`, and numbers can be converted to a string
using function `string`.
```js
var parser = math.parser();
@ -458,6 +486,45 @@ parser.eval('d[2, 1:end]'); // Matrix, [[43, 50]]
parser.eval('c[end - 1 : -1 : 2]'); // Matrix, [8, 7, 6]
```
## Objects
Objects in math.js work the same as in languages like JavaScript and Python.
An object is enclosed by square brackets `{`, `}`, and contains a set of
comma separated key/value pairs. Keys and values are separated by a colon `:`.
Keys can be a symbol like `prop` or a string like `"prop"`.
```js
math.eval('{a: 2 + 1, b: 4}'); // {a: 3, b: 4}
math.eval('{"a": 2 + 1, "b": 4}'); // {a: 3, b: 4}
```
Objects can contain objects:
```js
math.eval('{a: 2, b: {c: 3, d: 4}}'); // {a: 2, b: {c: 3, d: 4}}
```
Object properties can be retrieved or replaced using dot notation or bracket
notation. Unlike JavaScript, when setting a property value, the whole object
is returned, not the property value
```js
var scope = {
obj: {
prop: 42
}
};
// retrieve properties
math.eval('obj.prop', scope); // 42
math.eval('obj["prop"]', scope); // 42
// set properties (returns the whole object, not the property value!)
math.eval('obj.prop = 43', scope); // {prop: 43}
math.eval('obj["prop"] = 43', scope); // {prop: 43}
scope.obj; // {prop: 43}
```
## Multi-line expressions
@ -488,26 +555,25 @@ array with results.
The expression parser supports implicit multiplication. Implicit multiplication
has the same precedence as explicit multiplications and divisions, so `3/4 mm`
is evaluated as `(3 / 4) * mm`. Here some examples:
is evaluated as `(3 / 4) * mm`.
Expression | Evaluated as:
--------------- | ----------------------
(3 + 2) b | (3 + 2) * b
3 / 4 mm | (3 / 4) * mm
(1 + 2) (4 - 2) | (1 + 2) * (4 - 2)
sqrt(2)(4 + 1) | sqrt(2) * (4 + 1)
A[2, 3] | A[2, 3] # get subset
(A)[2, 3] | (A) * [2, 3]
[2, 3][1, 3] | [2, 3] * [1, 3]
Parentheses are parsed as a function call when there is a symbol or accessor on
the left hand side, like `sqrt(4)` or `obj.method(4)`. In other cases the
parentheses are interpreted as an implicit multiplication.
Implicit multiplication can be tricky as there is ambiguity on how an expression
is evaluated. Use it carefully.
```js
math.eval('(1 + 2)(4 - 2)'); // Number, 6
math.eval('3/4 mm'); // Unit, 0.75 mm
math.eval('2 + 3i'); // Complex, 2 + 3i
```
Here some examples:
Expression | Evaluated as | Result
--------------- | ----------------- | ------------------
(1 + 3) pi | (1 + 3) * pi | 12.566370614359172
(4 - 1) 2 | (4 - 1) * 2 | 6
3 / 4 mm | (3 / 4) * mm | 0.75 mm
2 + 3 i | 2 + (3 * i) | 2 + 3i
(1 + 2) (4 - 2) | (1 + 2) * (4 - 2) | 6
sqrt(4) (1 + 2) | sqrt(4) * (1 + 2) | 6
## Comments

View File

@ -1,236 +1,3 @@
# Extension
The library can easily be extended with functions and variables using the
[`import`](reference/functions/import.md) function. The function `import`
accepts an object with functions and variables.
Function `import` has the following syntax:
```js
math.import(object: Object [, options: Object])
```
Where:
- `object` is an object or array containing the functions and/or values to be
imported. `import` support regular values and functions, typed functions
(see section [Typed functions](#typed-functions)), and factory functions
(see section [Factory functions](#factory-functions)).
An array is only applicable when it contains factory functions.
- `options` is an optional second argument with options.
The following options are available:
- `{boolean} override`
If `true`, existing functions will be overwritten. The default value is `false`.
- `{boolean} silent`
If `true`, the function will not throw errors on duplicates or invalid
types. Default value is `false`.
- `{boolean} wrap`
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 the math.js data types. The default value is `false`.
The following code example shows how to import a function and a value into math.js:
```js
// define new functions and variables
math.import({
myvalue: 42,
hello: function (name) {
return 'hello, ' + name + '!';
}
});
// defined functions can be used in both JavaScript as well as the parser
math.myvalue * 2; // 84
math.hello('user'); // 'hello, user!'
var parser = math.parser();
parser.eval('myvalue + 10'); // 52
parser.eval('hello("user")'); // 'hello, user!'
```
## Import external libraries
External libraries like
[numbers.js](https://github.com/sjkaliski/numbers.js) and
[numeric.js](http://numericjs.com/) can be imported as follows.
The libraries must be installed using npm:
$ npm install numbers
$ npm install numeric
The libraries can be easily imported into math.js using `import`.
In order to convert math.js specific data types like `Matrix` to primitive types
like `Array`, the imported functions can be wrapped by enabling `{wrap: true}`.
```js
// import the numbers.js and numeric.js libraries into math.js
math.import(require('numbers'), {wrap: true, silent: true});
math.import(require('numeric'), {wrap: true, silent: true});
// use functions from numbers.js
math.fibonacci(7); // 13
math.eval('fibonacci(7)'); // 13
// use functions from numeric.js
math.eval('eig([1, 2; 4, 3])').lambda.x; // [5, -1]
```
## Typed functions
Typed functions can be created using `math.typed`. A typed function is a function
which does type checking on the input arguments. It can have multiple signatures.
And can automatically convert input types where needed.
A typed function can be created like:
```js
var max = typed('max', {
'number, number': function (a, b) {
return Math.max(a, b);
},
'BigNumber, BigNumber': function (a, b) {
return a.greaterThan(b) ? a : b;
}
});
```
Typed functions can be merged as long as there are no conflicts in the signatures.
This allows for extending existing functions in math.js with support for new
data types.
```js
// create a new data type
function MyType (value) {
this.value = value;
}
MyType.prototype.isMyType = true;
MyType.prototype.toString = function () {
return 'MyType:' + this.value;
}
// define a new datatype
math.typed.addType({
name: 'MyType',
test: function (x) {
// test whether x is of type MyType
return x && x.isMyType;
}
})
// use the type in a new typed function
var add = typed('add', {
'MyType, MyType': function (a, b) {
return new MyType(a.value + b.value);
}
});
// import in math.js, extend the existing function `add` with support for MyType
math.import({add: add});
// use the new type
var ans = math.add(new MyType(2), new MyType(3)); // returns MyType(5)
console.log(ans); // outputs 'MyType:5'
```
Detailed information on typed functions is available here:
[https://github.com/josdejong/typed-function](https://github.com/josdejong/typed-function)
## Factory functions
Regular JavaScript functions can be imported in math.js using `math.import`:
```js
math.import({
myFunction: function (a, b) {
// ...
}
});
```
The function can be stored in a separate file:
```js
exports.myFunction = function (a, b) {
// ...
}
```
Which can be imported like:
```js
math.import(require('./myFunction.js'));
```
An issue arises when `myFunction` needs functionality from math.js:
it doesn't have access to the current instance of math.js when in a separate file.
Factory functions can be used to solve this issue. A file exporting a factory function
looks like:
```js
exports.name = 'myFunction';
exports.factory = function (type, config, load, typed) {
return myFunction (a, b) {
// ...
}
};
```
The file exports a name and a factory function. When running `math.import`, the factory
function is invoked by math.js with four arguments:
- `type: Object`: Object containing the data types of math.js,
like `type.BigNumber` and `type.Unit`.
- `config: Object`: object with the configuration of math.js.
- `load: function`: loader function to access functions from math.js. For example to
load the function `add`:
```js
exports.factory = function (type, config, load, typed) {
var add = load(require('mathjs/lib/function/arithmetic/add'));
return myFunction (a, b) {
// ...
}
};
```
- `typed: function`: function to create typed-functions.
The result returned by a factory function will be imported into the `math`
namespace under the given `name`, `math.myFunction` in the above example.
A factory can contain the following properties:
- `name: string`. The name of the exported function or value. Required.
- `factory: function (type, config, load, typed) `. The factory function,
must return the function or value to be imported in math.js. Required.
- `path: string`. An optional path to where the function or value will be
imported. By default, imported functions have no path and are imported in
the 'flat' namespace `math`. Data types have `type` as path, and will be
located under `math.type.*`. Optional.
- `lazy: boolean`. If true (default), the factory function will be lazy loaded:
it is executed as soon as the function is about to be used.
- `math: boolean`. False by default. If true, the `math` namespace is passed
to the factory function as fifth argument. Should not be used unless there
is a very good reason for it.
To import a set of factory functions, the function `math.import` accepts an
array containing factory functions:
```js
math.import([
require('./myFactoryFunction1.js'),
require('./myFactoryFunction2.js'),
require('./myFactoryFunction3.js'),
// ...
]);
```
This page has been moved [here](core/extension.md).

View File

@ -5,7 +5,7 @@ This getting started describes how to install, load, and use math.js.
## Install
Math.js can be installed using various package managers like [npm](https://npmjs.org/) and [bower](http://twitter.github.io/bower/), or by just downloading the library from the website: [http://mathjs.org/download.html](http://mathjs.org/download.html).
Math.js can be installed using various package managers like [npm](https://npmjs.org/) and [bower](http://bower.io/), or by just downloading the library from the website: [http://mathjs.org/download.html](http://mathjs.org/download.html).
To install via npm, run:

View File

@ -1,51 +1,40 @@
# Documentation
[Math.js](http://mathjs.org) is an extensive math library for JavaScript and Node.js.
It features a flexible expression parser and offers an integrated solution
to work with numbers, big numbers, complex numbers, units, and matrices.
Powerful and easy to use.
This documentation of contains a getting started tutorial,
an extensive overview describing math.js on a high level, and a reference
describing all available functions, constants, and units in detail.
It features a flexible expression parser, a large set of built-in functions and constants,
and offers an integrated solution to work with different data types like numbers,
big numbers, complex numbers, units, and matrices.
Math.js can be used in the browser, in node.js and in any JavaScript engine. Installation and download instructions are available on the [Download page](http://mathjs.org/download.html) of the website.
## Getting Started
- [Getting Started](getting_started.md)
- [Examples](http://mathjs.org/examples/index.html)
## Documentation
## Overview
- [Introduction](introduction.md)
- [Expressions](expressions/index.md)
- **[Core](core/index.md)**
- [Configuration](core/configuration.md)
- [Chaining](core/chaining.md)
- [Extension](core/extension.md)
- [Serialization](core/serialization.md)
- **[Expressions](expressions/index.md)**
- [Parsing and evaluation](expressions/parsing.md)
- [Syntax](expressions/syntax.md)
- [Expression trees](expressions/expression_trees.md)
- [Customization](expressions/customization.md)
- [Chaining](chaining.md)
- [Data Types](datatypes/index.md)
- **[Data Types](datatypes/index.md)**
- [Numbers](datatypes/numbers.md)
- [BigNumbers](datatypes/bignumbers.md)
- [Fractions](datatypes/fractions.md)
- [Complex Numbers](datatypes/complex_numbers.md)
- [Matrices](datatypes/matrices.md)
- [Units](datatypes/units.md)
- [Configuration](configuration.md)
- [Serialization](serialization.md)
- [Extension](extension.md)
- **[Reference](reference/index.md)**
- [Classes](reference/classes.md)
- [Functions](reference/functions.md)
- [Constants](reference/constants.md)
- [Custom bundling](custom_bundling.md)
- [Command Line Interface](command_line_interface.md)
## Examples
- [Examples](http://mathjs.org/examples/index.html)
## Reference
- [Constants](reference/constants.md)
- [Functions (alphabetical)](reference/functions/alphabetical.md)
- [Functions (categorical)](reference/functions/categorical.md)
- [History](../HISTORY.md)
- [Units](reference/units.md)

View File

@ -1,62 +0,0 @@
# Introduction
[Math.js](http://mathjs.org) is an extensive math library.
It features a flexible expression parser and offers an integrated solution
to work with numbers, big numbers, complex numbers, units, and matrices.
Math.js can be used in node.js and in the browser. Installation and download instructions are available on the [Download page](http://mathjs.org/download.html) of the website. A [Getting Started](getting_started.md) tutorial describes how to start using math.js. Code examples are available [here](http://mathjs.org/examples/index.html).
## Usage
Math.js can be used in three different ways:
- Make **function calls** like `math.sqrt(4)` and constants like `math.pi`. This works similar to JavaScript's built-in `Math` object. Examples:
```js
math.sqrt(25); // Number 5
math.add(3, 4); // Number 7
math.add(3, math.multiply(2, 3)); // Number 9
math.log(10000, 10); // Number 4
math.sin(math.pi / 4); // Number 0.70711
math.multiply(math.i, math.i); // Number -1
```
- Evaluate **expressions** using [`math.eval`](reference/functions/eval.md). See section [Expressions](expressions/index.md). Some examples:
```js
math.eval('12 / (2.3 + 0.7)'); // 4
math.eval('sqrt(3^2 + 4^2)'); // Number 5
math.eval('sqrt(-4)'); // Complex 2i
math.eval('2 inch to cm'); // Unit 5.08 cm
math.eval('cos(45 deg)'); // Number 0.7071067811865476
math.eval('det([-1, 2; 3, 1])'); // Number -7
math.eval('a ^ b', {a: 2, b: 3}); // Number 8
```
- Write **chains** using [`math.chain`](reference/functions/chain.md), described in section [Chaining](chaining.md). Examples:
```js
math.chain(3)
.add(4)
.subtract(2)
.done(); // 5
```
A listing with all available functions, units, and constants can be found in the [reference section](reference/index.md).
## Data types
The functions available in math.js support multiple data types: Number, BigNumber, Complex, Unit, String, Matrix, and Array. Different data types can be mixed together in calculations.
```js
math.add([2, 1, 5], 3); // Array [5, 4, 8]
var a1 = math.complex(2, 3); // Complex 2 + 3i
var a2 = math.complex(-1, 4); // Complex -1 + 4i
math.multiply(a, b); // Complex -14 + 5i
math.sin(math.unit(45, 'deg')); // Number 0.70711
math.add('hello ', 'world!'); // String 'hello world!'
```
The available data types are described in detail in section [Data types](datatypes/index.md).

87
docs/reference/classes.md Normal file
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>
### FibonacciHeap._cascadingCut()
Performs a cascading cut operation. This cuts node from its parent and then does the same for its parent, and so on up the tree. Running time: O(log n); O(1) excluding the recursion.
**Kind**: static method of <code>[FibonacciHeap](#FibonacciHeap)</code>
<a name="FibonacciHeap._linkNodes"></a>
### FibonacciHeap._linkNodes()
Make the first node a child of the second one. Running time: O(1) actual.
**Kind**: static method of <code>[FibonacciHeap](#FibonacciHeap)</code>

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}` |

264
docs/reference/functions.md Normal file
View File

@ -0,0 +1,264 @@
# Function reference
## Core functions
Function | Description
---- | -----------
[math.config(config:&nbsp;Object):&nbsp;Object](functions/config.md) | Set configuration options for math.
[math.import(object,&nbsp;override)](functions/import.md) | Import functions from an object or a module.
[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) | Returns an array of units whose sum is equal to this 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
---- | -----------
[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.
[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 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 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.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.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

@ -1,3 +1,5 @@
<!-- 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
@ -36,6 +38,3 @@ math.abs([3, -5, -1, 0, 2]); // returns Array [3, 5, 1, 0, 2]
## See also
[sign](sign.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -39,6 +41,3 @@ math.acos(2); // returns Complex 0 + 1.3169578969248166 i
[cos](cos.md),
[atan](atan.md),
[asin](asin.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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,
@ -37,6 +39,3 @@ math.acosh(1.5); // returns 0.9624236501192069
[cosh](cosh.md),
[asinh](asinh.md),
[atanh](atanh.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,6 +1,8 @@
<!-- 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.
Calculate the inverse cotangent of a value, defined as `acot(x) = atan(1/x)`.
For matrices, the function is evaluated element wise.
@ -38,6 +40,3 @@ math.acot(2); // returns Complex 1.5707963267948966 -1.3169578969248
[cot](cot.md),
[atan](atan.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,7 +1,9 @@
<!-- 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) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
defined as `acoth(x) = atanh(1/x) = (ln((x+1)/x) + ln(x/(x-1))) / 2`.
For matrices, the function is evaluated element wise.
@ -36,6 +38,3 @@ math.acoth(0.5); // returns 0.8047189562170503
[acsch](acsch.md),
[asech](asech.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,6 +1,8 @@
<!-- 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.
Calculate the inverse cosecant of a value, defined as `acsc(x) = asin(1/x)`.
For matrices, the function is evaluated element wise.
@ -39,6 +41,3 @@ math.acsc(2); // returns Complex 1.5707963267948966 -1.3169578969248
[csc](csc.md),
[asin](asin.md),
[asec](asec.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,7 +1,9 @@
<!-- 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) = ln(1/x + sqrt(1/x^2 + 1))`.
defined as `acsch(x) = asinh(1/x) = ln(1/x + sqrt(1/x^2 + 1))`.
For matrices, the function is evaluated element wise.
@ -36,6 +38,3 @@ math.acsch(0.5); // returns 1.4436354751788103
[asech](asech.md),
[acoth](acoth.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function add
Add two values, `x + y`.
@ -46,6 +48,3 @@ math.add("2.3", "4"); // returns number 6.3
## See also
[subtract](subtract.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,158 +0,0 @@
# Function reference (alphabetical)
- [abs(x)](abs.md)
- [acos(x)](acos.md)
- [acosh(x)](acosh.md)
- [acot(x)](acot.md)
- [acoth(x)](acoth.md)
- [acsc(x)](acsc.md)
- [acsch(x)](acsch.md)
- [add(x, y)](add.md)
- [and(x, y)](and.md)
- [arg(x)](arg.md)
- [asec(x)](asec.md)
- [asech(x)](asech.md)
- [asin(x)](asin.md)
- [asinh(x)](asinh.md)
- [atan(x)](atan.md)
- [atan2(y, x)](atan2.md)
- [atanh(x)](atanh.md)
- [bellNumbers(n)](bellNumbers.md)
- [bignumber(x)](bignumber.md)
- [bitAnd(x, y)](bitAnd.md)
- [bitNot(x)](bitNot.md)
- [bitOr(x, y)](bitOr.md)
- [bitXor(x, y)](bitXor.md)
- [boolean(x)](boolean.md)
- [catalan(n)](catalan.md)
- [cbrt(x)](cbrt.md)
- [ceil(x)](ceil.md)
- [chain(value)](chain.md)
- [clone(x)](clone.md)
- [combinations(n, k)](combinations.md)
- [compare(x, y)](compare.md)
- [compile(expr)](compile.md)
- [complex(re, im)](complex.md)
- [composition(n, k)](composition.md)
- [concat(a, b, c, ... [, dim])](concat.md)
- [conj(x)](conj.md)
- [cos(x)](cos.md)
- [cosh(x)](cosh.md)
- [cot(x)](cot.md)
- [coth(x)](coth.md)
- [cross(x, y)](cross.md)
- [csc(x)](csc.md)
- [csch(x)](csch.md)
- [cube(x)](cube.md)
- [deepEqual(x, y)](deepEqual.md)
- [det(x)](det.md)
- [diag(X)](diag.md)
- [distance([x1, y1], [x2, y2])](distance.md)
- [divide(x, y)](divide.md)
- [dot(x, y)](dot.md)
- [dotDivide(x, y)](dotDivide.md)
- [dotMultiply(x, y)](dotMultiply.md)
- [dotPow(x, y)](dotPow.md)
- [equal(x, y)](equal.md)
- [eval(expr [, scope])](eval.md)
- [exp(x)](exp.md)
- [eye(n)](eye.md)
- [factorial(n)](factorial.md)
- [filter(x, test)](filter.md)
- [fix(x)](fix.md)
- [flatten(x)](flatten.md)
- [floor(x)](floor.md)
- [forEach(x, callback)](forEach.md)
- [format(value [, precision])](format.md)
- [fraction(numerator, denominator)](fraction.md)
- [gamma(n)](gamma.md)
- [gcd(a, b)](gcd.md)
- [help(search)](help.md)
- [hypot(a, b, ...)](hypot.md)
- [im(x)](im.md)
- [index(range1, range2, ...)](index.md)
- [intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)](intersect.md)
- [inv(x)](inv.md)
- [isInteger(x)](isInteger.md)
- [isNegative(x)](isNegative.md)
- [isNumeric(x)](isNumeric.md)
- [isPositive(x)](isPositive.md)
- [isZero(x)](isZero.md)
- [kldivergence(x, y)](kldivergence.md)
- [larger(x, y)](larger.md)
- [largerEq(x, y)](largerEq.md)
- [lcm(a, b)](lcm.md)
- [leftShift(x, y)](leftShift.md)
- [log(x [, base])](log.md)
- [log10(x)](log10.md)
- [lsolve(L, b)](lsolve.md)
- [lup(A)](lup.md)
- [lusolve(A, b)](lusolve.md)
- [map(x, callback)](map.md)
- [matrix(x)](matrix.md)
- [max(a, b, c, ...)](max.md)
- [mean(a, b, c, ...)](mean.md)
- [median(a, b, c, ...)](median.md)
- [min(a, b, c, ...)](min.md)
- [mod(x, y)](mod.md)
- [mode(a, b, c, ...)](mode.md)
- [multinomial(a)](multinomial.md)
- [multiply(x, y)](multiply.md)
- [norm(x [, p])](norm.md)
- [not(x)](not.md)
- [nthRoot(a)](nthRoot.md)
- [number(value)](number.md)
- [ones(m, n, p, ...)](ones.md)
- [or(x, y)](or.md)
- [parse(expr [, scope])](parse.md)
- [parser()](parser.md)
- [partitionSelect(x, k)](partitionSelect.md)
- [permutations(n [, k])](permutations.md)
- [pickRandom(array)](pickRandom.md)
- [pow(x, y)](pow.md)
- [print(template, values [, precision])](print.md)
- [prod(a, b, c, ...)](prod.md)
- [quantileSeq(A, prob[, sorted])](quantileSeq.md)
- [random([min, max])](random.md)
- [randomInt([min, max])](randomInt.md)
- [range(start, end [, step])](range.md)
- [re(x)](re.md)
- [resize(x, size [, defaultValue])](resize.md)
- [rightArithShift(x, y)](rightArithShift.md)
- [rightLogShift(x, y)](rightLogShift.md)
- [round(x [, n])](round.md)
- [sec(x)](sec.md)
- [sech(x)](sech.md)
- [sign(x)](sign.md)
- [sin(x)](sin.md)
- [sinh(x)](sinh.md)
- [size(x)](size.md)
- [slu(A, order, threshold)](slu.md)
- [smaller(x, y)](smaller.md)
- [smallerEq(x, y)](smallerEq.md)
- [sort(x)](sort.md)
- [sparse(x)](sparse.md)
- [sqrt(x)](sqrt.md)
- [square(x)](square.md)
- [squeeze(x)](squeeze.md)
- [std(a, b, c, ...)](std.md)
- [stirlingS2(n, k)](stirlingS2.md)
- [string(value)](string.md)
- [subset(x, index [, replacement])](subset.md)
- [subtract(x, y)](subtract.md)
- [sum(a, b, c, ...)](sum.md)
- [tan(x)](tan.md)
- [tanh(x)](tanh.md)
- [to(x, unit)](to.md)
- [trace(x)](trace.md)
- [transpose(x)](transpose.md)
- [typeof(x)](typeof.md)
- [unaryMinus(x)](unaryMinus.md)
- [unaryPlus(x)](unaryPlus.md)
- [unequal(x, y)](unequal.md)
- [unit(x)](unit.md)
- [usolve(U, b)](usolve.md)
- [var(a, b, c, ...)](var.md)
- [xgcd(a, b)](xgcd.md)
- [xor(x, y)](xor.md)
- [zeros(m, n, p, ...)](zeros.md)

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -43,6 +45,3 @@ math.and(a, c); // returns [false, false, false]
[not](not.md),
[or](or.md),
[xor](xor.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -43,6 +45,3 @@ math.atan2(3, 2); // returns number 0.982793723247329
[im](im.md),
[conj](conj.md),
[abs](abs.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,6 +1,8 @@
<!-- 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.
Calculate the inverse secant of a value. Defined as `asec(x) = acos(1/x)`.
For matrices, the function is evaluated element wise.
@ -39,6 +41,3 @@ math.asec(2); // returns 0 + 1.3169578969248166 i
[acos](acos.md),
[acot](acot.md),
[acsc](acsc.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,7 +1,9 @@
<!-- 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) = ln(sqrt(1/x^2 - 1) + 1/x)`.
defined as `asech(x) = acosh(1/x) = ln(sqrt(1/x^2 - 1) + 1/x)`.
For matrices, the function is evaluated element wise.
@ -36,6 +38,3 @@ math.asech(0.5); // returns 1.3169578969248166
[acsch](acsch.md),
[acoth](acoth.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -39,6 +41,3 @@ math.asin(2); // returns Complex 1.5707963267948966 -1.3169578969248
[sin](sin.md),
[atan](atan.md),
[acos](acos.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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,
@ -36,6 +38,3 @@ math.asinh(0.5); // returns 0.48121182505960347
[acosh](acosh.md),
[atanh](atanh.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -39,6 +41,3 @@ math.atan(2); // returns Complex 1.5707963267948966 -1.3169578969248
[tan](tan.md),
[asin](asin.md),
[acos](acos.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -46,6 +48,3 @@ math.atan(2); // returns Complex 1.5707963267948966 -1.3169578969248
[atan](atan.md),
[sin](sin.md),
[cos](cos.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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,
@ -36,6 +38,3 @@ math.atanh(0.5); // returns 0.5493061443340549
[acosh](acosh.md),
[asinh](asinh.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -35,6 +37,3 @@ math.bellNumbers(8); // returns 4140;
## See also
[stirlingS2](stirlingS2.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -14,7 +16,7 @@ math.bignumber(x)
Parameter | Type | Description
--------- | ---- | -----------
`value` | number &#124; string &#124; Array &#124; Matrix &#124; boolean &#124; null | Value for the big number, 0 by default.
`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
@ -43,6 +45,3 @@ math.bignumber('7.2e500'); // returns BigNumber 7.2e500
[matrix](matrix.md),
[string](string.md),
[unit](unit.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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`.
@ -41,6 +43,3 @@ math.bitAnd([1, 12, 31], 42); // returns Array [0, 8, 10]
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function bitNot
Bitwise NOT value, `~x`.
@ -41,6 +43,3 @@ math.bitNot([2, -3, 4]); // returns Array [-3, 2, 5]
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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`.
@ -42,6 +44,3 @@ math.bitOr([1, 2, 3], 4); // returns Array [5, 6, 7]
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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`.
@ -41,6 +43,3 @@ math.bitXor([2, 3, 4], 4); // returns Array [6, 7, 0]
[leftShift](leftShift.md),
[rightArithShift](rightArithShift.md),
[rightLogShift](rightLogShift.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -46,6 +48,3 @@ math.boolean([1, 0, 1, 1]); // returns [true, false, true, true]
[matrix](matrix.md),
[string](string.md),
[unit](unit.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -35,6 +37,3 @@ math.catalan(8); // returns 1430;
## See also
[bellNumbers](bellNumbers.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,205 +0,0 @@
# Function reference (categorical)
## algebra
- [lsolve(L, b)](lsolve.md)
- [lup(A)](lup.md)
- [lusolve(A, b)](lusolve.md)
- [slu(A, order, threshold)](slu.md)
- [usolve(U, b)](usolve.md)
## arithmetic
- [abs(x)](abs.md)
- [add(x, y)](add.md)
- [cbrt(x)](cbrt.md)
- [ceil(x)](ceil.md)
- [cube(x)](cube.md)
- [divide(x, y)](divide.md)
- [dotDivide(x, y)](dotDivide.md)
- [dotMultiply(x, y)](dotMultiply.md)
- [dotPow(x, y)](dotPow.md)
- [exp(x)](exp.md)
- [fix(x)](fix.md)
- [floor(x)](floor.md)
- [gcd(a, b)](gcd.md)
- [hypot(a, b, ...)](hypot.md)
- [lcm(a, b)](lcm.md)
- [log(x [, base])](log.md)
- [log10(x)](log10.md)
- [mod(x, y)](mod.md)
- [multiply(x, y)](multiply.md)
- [norm(x [, p])](norm.md)
- [nthRoot(a)](nthRoot.md)
- [pow(x, y)](pow.md)
- [round(x [, n])](round.md)
- [sign(x)](sign.md)
- [sqrt(x)](sqrt.md)
- [square(x)](square.md)
- [subtract(x, y)](subtract.md)
- [unaryMinus(x)](unaryMinus.md)
- [unaryPlus(x)](unaryPlus.md)
- [xgcd(a, b)](xgcd.md)
## bitwise
- [bitAnd(x, y)](bitAnd.md)
- [bitNot(x)](bitNot.md)
- [bitOr(x, y)](bitOr.md)
- [bitXor(x, y)](bitXor.md)
- [leftShift(x, y)](leftShift.md)
- [rightArithShift(x, y)](rightArithShift.md)
- [rightLogShift(x, y)](rightLogShift.md)
## combinatorics
- [bellNumbers(n)](bellNumbers.md)
- [catalan(n)](catalan.md)
- [composition(n, k)](composition.md)
- [stirlingS2(n, k)](stirlingS2.md)
## complex
- [arg(x)](arg.md)
- [conj(x)](conj.md)
- [im(x)](im.md)
- [re(x)](re.md)
## construction
- [bignumber(x)](bignumber.md)
- [boolean(x)](boolean.md)
- [chain(value)](chain.md)
- [complex(re, im)](complex.md)
- [fraction(numerator, denominator)](fraction.md)
- [index(range1, range2, ...)](index.md)
- [matrix(x)](matrix.md)
- [number(value)](number.md)
- [sparse(x)](sparse.md)
- [string(value)](string.md)
- [unit(x)](unit.md)
## expression
- [compile(expr)](compile.md)
- [eval(expr [, scope])](eval.md)
- [help(search)](help.md)
- [parse(expr [, scope])](parse.md)
- [parser()](parser.md)
## geometry
- [distance([x1, y1], [x2, y2])](distance.md)
- [intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)](intersect.md)
## logical
- [and(x, y)](and.md)
- [not(x)](not.md)
- [or(x, y)](or.md)
- [xor(x, y)](xor.md)
## matrix
- [concat(a, b, c, ... [, dim])](concat.md)
- [cross(x, y)](cross.md)
- [det(x)](det.md)
- [diag(X)](diag.md)
- [dot(x, y)](dot.md)
- [eye(n)](eye.md)
- [flatten(x)](flatten.md)
- [inv(x)](inv.md)
- [ones(m, n, p, ...)](ones.md)
- [range(start, end [, step])](range.md)
- [resize(x, size [, defaultValue])](resize.md)
- [size(x)](size.md)
- [squeeze(x)](squeeze.md)
- [subset(x, index [, replacement])](subset.md)
- [trace(x)](trace.md)
- [transpose(x)](transpose.md)
- [zeros(m, n, p, ...)](zeros.md)
## probability
- [combinations(n, k)](combinations.md)
- [factorial(n)](factorial.md)
- [gamma(n)](gamma.md)
- [kldivergence(x, y)](kldivergence.md)
- [multinomial(a)](multinomial.md)
- [permutations(n [, k])](permutations.md)
- [pickRandom(array)](pickRandom.md)
- [random([min, max])](random.md)
- [randomInt([min, max])](randomInt.md)
## relational
- [compare(x, y)](compare.md)
- [deepEqual(x, y)](deepEqual.md)
- [equal(x, y)](equal.md)
- [larger(x, y)](larger.md)
- [largerEq(x, y)](largerEq.md)
- [smaller(x, y)](smaller.md)
- [smallerEq(x, y)](smallerEq.md)
- [unequal(x, y)](unequal.md)
## statistics
- [max(a, b, c, ...)](max.md)
- [mean(a, b, c, ...)](mean.md)
- [median(a, b, c, ...)](median.md)
- [min(a, b, c, ...)](min.md)
- [mode(a, b, c, ...)](mode.md)
- [prod(a, b, c, ...)](prod.md)
- [quantileSeq(A, prob[, sorted])](quantileSeq.md)
- [std(a, b, c, ...)](std.md)
- [sum(a, b, c, ...)](sum.md)
- [var(a, b, c, ...)](var.md)
## trigonometry
- [acos(x)](acos.md)
- [acosh(x)](acosh.md)
- [acot(x)](acot.md)
- [acoth(x)](acoth.md)
- [acsc(x)](acsc.md)
- [acsch(x)](acsch.md)
- [asec(x)](asec.md)
- [asech(x)](asech.md)
- [asin(x)](asin.md)
- [asinh(x)](asinh.md)
- [atan(x)](atan.md)
- [atan2(y, x)](atan2.md)
- [atanh(x)](atanh.md)
- [cos(x)](cos.md)
- [cosh(x)](cosh.md)
- [cot(x)](cot.md)
- [coth(x)](coth.md)
- [csc(x)](csc.md)
- [csch(x)](csch.md)
- [sec(x)](sec.md)
- [sech(x)](sech.md)
- [sin(x)](sin.md)
- [sinh(x)](sinh.md)
- [tan(x)](tan.md)
- [tanh(x)](tanh.md)
## units
- [to(x, unit)](to.md)
## utils
- [clone(x)](clone.md)
- [filter(x, test)](filter.md)
- [forEach(x, callback)](forEach.md)
- [format(value [, precision])](format.md)
- [isInteger(x)](isInteger.md)
- [isNegative(x)](isNegative.md)
- [isNumeric(x)](isNumeric.md)
- [isPositive(x)](isPositive.md)
- [isZero(x)](isZero.md)
- [map(x, callback)](map.md)
- [partitionSelect(x, k)](partitionSelect.md)
- [print(template, values [, precision])](print.md)
- [sort(x)](sort.md)
- [typeof(x)](typeof.md)

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -9,6 +11,7 @@ For matrices, the function is evaluated element wise.
```js
math.cbrt(x)
math.cbrt(x, allRoots)
```
### Parameters
@ -49,6 +52,3 @@ math.cbrt(x, true); // returns Matrix [
[square](square.md),
[sqrt](sqrt.md),
[cube](cube.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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
@ -44,6 +46,3 @@ math.ceil([3.2, 3.8, -4.7]); // returns Array [4, 4, -4]
[floor](floor.md),
[fix](fix.md),
[round](round.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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
@ -50,6 +52,3 @@ math.chain( [[1, 2], [3, 4]] )
```
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function clone
Clone an object.
@ -26,13 +28,10 @@ Type | Description
```js
math.clone(3.5); // returns number 3.5
math.clone(math.complex('2 - 4i'); // returns Complex 2 - 4i
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"
```
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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`
@ -38,6 +40,3 @@ math.combinations(7, 5); // returns 21
[permutations](permutations.md),
[factorial](factorial.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -52,6 +54,3 @@ math.compare(2, [1, 2, 3]); // returns [1, 0, -1]
[smallerEq](smallerEq.md),
[larger](larger.md),
[largerEq](largerEq.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -22,7 +24,7 @@ Parameter | Type | Description
Type | Description
---- | -----------
{eval: Function} &#124; Array.<{eval: Function}> | code An object with the compiled expression
{eval: Function} &#124; Array.&lt;{eval: Function}&gt; | code An object with the compiled expression
## Examples
@ -46,6 +48,3 @@ nodes[2].eval(); // 12
[parse](parse.md),
[eval](eval.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -57,6 +59,3 @@ var d = math.add(a, b); // Complex 5 + 2i
[number](number.md),
[string](string.md),
[unit](unit.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -36,6 +38,3 @@ math.composition(5, 3); // returns 6
## See also
[combinations](combinations.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -46,6 +48,3 @@ math.concat('hello', ' ', 'world'); // returns 'hello world'
[squeeze](squeeze.md),
[subset](subset.md),
[transpose](transpose.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

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

@ -1,3 +1,5 @@
<!-- 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.
@ -40,6 +42,3 @@ math.conj(math.complex('-5.2i')); // returns Complex 5.2i
[im](im.md),
[arg](arg.md),
[abs](abs.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -41,6 +43,3 @@ math.pow(math.sin(angle), 2) + math.pow(math.cos(angle), 2); // returns number ~
[cos](cos.md),
[tan](tan.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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,
@ -36,6 +38,3 @@ math.cosh(0.5); // returns number 1.1276259652063807
[sinh](sinh.md),
[tanh](tanh.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,6 +1,8 @@
<!-- 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. `cot(x)` is defined as `1 / tan(x)`.
Calculate the cotangent of a value. Defined as `cot(x) = 1 / tan(x)`.
For matrices, the function is evaluated element wise.
@ -37,6 +39,3 @@ math.cot(2); // returns number -0.45765755436028577
[tan](tan.md),
[sec](sec.md),
[csc](csc.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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,
@ -39,6 +41,3 @@ math.coth(2); // returns 1.0373147207275482
[sinh](sinh.md),
[tanh](tanh.md),
[cosh](cosh.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

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

@ -1,7 +1,9 @@
<!-- 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
The cross product of `A = [a1, a2, a3]` and `B = [b1, b2, b3]` is defined
as:
cross(A, B) = [
@ -10,6 +12,9 @@ as:
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
@ -34,9 +39,10 @@ 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, 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]]
```
@ -44,6 +50,3 @@ math.cross([2, 3, 4], [5, 6, 7]); // Returns [-3, 6, -3]
[dot](dot.md),
[multiply](multiply.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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)`.
@ -37,6 +39,3 @@ math.csc(2); // returns number 1.099750170294617
[sin](sin.md),
[sec](sec.md),
[cot](cot.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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,
@ -39,6 +41,3 @@ math.csch(0.5); // returns 1.9190347513349437
[sinh](sinh.md),
[sech](sech.md),
[coth](coth.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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`.
@ -41,6 +43,3 @@ math.cube([1, 2, 3, 4]); // returns Array [1, 8, 27, 64]
[square](square.md),
[pow](pow.md),
[cbrt](cbrt.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -41,6 +43,3 @@ math.equal(a, b); // returns [true, false, true]
[equal](equal.md),
[unequal](unequal.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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.
@ -39,6 +41,3 @@ math.det(A); // returns 6
## See also
[inv](inv.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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
@ -51,6 +53,3 @@ math.diag(a); // returns [1, 5, 9]
[ones](ones.md),
[zeros](zeros.md),
[eye](eye.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->
# Function distance
Calculates:
@ -68,6 +70,3 @@ math.distance(
```
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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`.
@ -45,6 +47,3 @@ math.divide(e, 4.5); // returns Unit 4 km
## See also
[multiply](multiply.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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
@ -38,6 +40,3 @@ math.multiply([2, 4, 1], [2, 2, 3]); // returns number 15
[multiply](multiply.md),
[cross](cross.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

View File

@ -1,3 +1,5 @@
<!-- 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
@ -42,6 +44,3 @@ math.divide(a, b); // returns [[1.75, 0.75], [-1.75, 2.25]]
[divide](divide.md),
[multiply](multiply.md),
[dotMultiply](dotMultiply.md)
<!-- Note: This file is automatically generated from source code comments. Changes made in this file will be overridden. -->

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