Released version 1.3.0

This commit is contained in:
jos 2015-02-09 21:43:00 +01:00
parent 618ec2c84b
commit beb4e2e536
47 changed files with 2961 additions and 2185 deletions

View File

@ -1,8 +1,10 @@
# History
## not yet released, version 1.2.1-SNAPSHOT
## 2015-02-09, version 1.3.0
- Implemented BigNumber implementations of most trigonometric functions: `sin`,
`cos`, `tan`, `asin`, `acos`, `atan`, `cosh`, `sinh`, `tanh`. Thanks @BigFav.
- Implemented function `trace`. Thanks @pcorey.
- Faster loading of BigNumber configuration with a high precision by lazy
loading constants like `pi` and `e`.

2
NOTICE
View File

@ -1,7 +1,7 @@
math.js
https://github.com/josdejong/mathjs
Copyright (C) 2013 Jos de Jong <wjosdejong@gmail.com>
Copyright (C) 2013-2015 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

@ -24,7 +24,7 @@
* cat script.txt | mathjs > results.txt Run input stream, output to file
*
* @license
* Copyright (C) 2013-2014 Jos de Jong <wjosdejong@gmail.com>
* Copyright (C) 2013-2015 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

View File

@ -1,6 +1,6 @@
{
"name": "mathjs",
"version": "1.2.1-SNAPSHOT",
"version": "1.3.0",
"main": "./dist/math.min.js",
"ignore": [
"coverage",

View File

@ -2,7 +2,7 @@
"name": "mathjs",
"repo": "josdejong/mathjs",
"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.",
"version": "1.2.1-SNAPSHOT",
"version": "1.3.0",
"main": "dist/math.min.js",
"keywords": [
"math",

4951
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

22
dist/math.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,8 @@ For calculations with an arbitrary precision, math.js supports a `BigNumber`
data type. BigNumber support is powered by
[decimal.js](https://github.com/MikeMcl/decimal.js/).
## Usage
A BigNumber can be created using the function `bignumber`:
```js
@ -35,10 +37,13 @@ BigNumber is not supported by the following functions:
gcd, lcm, xgcd,
arg,
random,
acos, asin, atan, atan2, cos, cot, csc, sec, sin, tan,
cosh, coth, csch, sech, sinh, tanh.
atan2, cot, csc, sec,
coth, csch, sech.
These functions will downgrade BigNumber to Number, and return a Number.*
## Round-off errors
Calculations with BigNumber are much slower than calculations with Number,
but they can be executed with an arbitrary precision. By using a higher
precision, it is less likely that round-off errors occur:
@ -53,6 +58,31 @@ math.add(math.bignumber(0.1), math.bignumber(0.2)); // BigNumber, 0.3
math.divide(math.bignumber(0.3), math.bignumber(0.2)); // BigNumber, 1.5
```
## Limitations
It's important to realize that BigNumbers do not solve *all* problems related
to precision and round-off errors. Numbers with an infinite number of digits
cannot be represented with a regular number nor a BigNumber. Though a BigNumber
can store a much larger number of digits, the amount of digits remains limited,
if only to keep calculations fast enough to remain practical.
```js
var one = math.bignumber(1);
var three = math.bignumber(3);
var third = math.divide(one, three);
console.log(third.toString());
// outputs 0.3333333333333333333333333333333333333333333333333333333333333333
var ans = math.multiply(third, three);
console.log(ans.toString());
// outputs 0.9999999999999999999999999999999999999999999999999999999999999999
// this should be 1 again, but `third` is rounded to a limited number of digits 3
```
## Conversion
BigNumbers can be converted to numbers and vice versa using the functions
`number` and `bignumber`. When converting a BigNumber to a Number, the high
precision of the BigNumber will be lost. When a BigNumber is too large to be represented

View File

@ -15,13 +15,13 @@ math.acos(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber Boolean &#124; Complex &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | The arc cosine of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | The arc cosine of x
## Examples

View File

@ -113,6 +113,7 @@
- [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)

View File

@ -15,13 +15,13 @@ math.asin(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | The arc sine of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | The arc sine of x
## Examples

View File

@ -15,13 +15,13 @@ math.atan(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | The arc tangent of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | The arc tangent of x
## Examples

View File

@ -91,6 +91,7 @@
- [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)

View File

@ -15,13 +15,13 @@ math.cos(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | Cosine of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Cosine of x
## Examples

View File

@ -16,13 +16,13 @@ math.cosh(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic cosine of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Hyperbolic cosine of x
## Examples

View File

@ -30,7 +30,7 @@ Number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic secant of x
```js
// sech(x) = 1/ cosh(x)
math.sech(0.5); // returns 0.886818883970074
1 / math.cosh(0.5); // returns 1.9190347513349437
1 / math.cosh(0.5); // returns 0.886818883970074
```

View File

@ -15,13 +15,13 @@ math.sin(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | Sine of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Sine of x
## Examples

View File

@ -16,13 +16,13 @@ math.sinh(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic sine of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Hyperbolic sine of x
## Examples

View File

@ -15,13 +15,13 @@ math.tan(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | Tangent of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Tangent of x
## Examples

View File

@ -16,13 +16,13 @@ math.tanh(x)
Parameter | Type | Description
--------- | ---- | -----------
`x` | Number &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
`x` | Number &#124; BigNumber &#124; Boolean &#124; Complex &#124; Unit &#124; Array &#124; Matrix &#124; null | Function input
### Returns
Type | Description
---- | -----------
Number &#124; Complex &#124; Array &#124; Matrix | Hyperbolic tangent of x
Number &#124; BigNumber &#124; Complex &#124; Array &#124; Matrix | Hyperbolic tangent of x
## Examples

View File

@ -14,6 +14,6 @@ module.exports = {
'concat(A, B, 2)'
],
'seealso': [
'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -10,6 +10,6 @@ module.exports = {
'det([-2, 2, 3; -1, 1, 3; 2, 0, -1])'
],
'seealso': [
'concat', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
'concat', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -13,6 +13,6 @@ module.exports = {
'diag(a)'
],
'seealso': [
'concat', 'det', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
'concat', 'det', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -15,6 +15,6 @@ module.exports = {
'eye(size(a))'
],
'seealso': [
'concat', 'det', 'diag', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
'concat', 'det', 'diag', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -11,6 +11,6 @@ module.exports = {
'1 / 4'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
'concat', 'det', 'diag', 'eye', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -19,6 +19,6 @@ module.exports = {
'ones(size(a))'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
'concat', 'det', 'diag', 'eye', 'inv', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -20,6 +20,6 @@ module.exports = {
'a[1:2, 1:2]'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'size', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -13,6 +13,6 @@ module.exports = {
'size(1:6)'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'squeeze', 'subset', 'transpose', 'zeros'
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'squeeze', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -12,6 +12,6 @@ module.exports = {
'size(squeeze(b))'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'subset', 'transpose', 'zeros'
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'subset', 'trace', 'transpose', 'zeros'
]
};

View File

@ -20,6 +20,6 @@ module.exports = {
'f[:, 1]'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'transpose', 'zeros'
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'trace', 'transpose', 'zeros'
]
};

View File

@ -0,0 +1,15 @@
module.exports = {
'name': 'trace',
'category': 'Matrix',
'syntax': [
'trace(A)'
],
'description': 'Calculate the trace of a matrix: the sum of the elements on the main diagonal of a square matrix.',
'examples': [
'A = [1, 2, 3; -1, 2, 3; 2, 0, 3]',
'trace(A)'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose', 'zeros'
]
};

View File

@ -12,6 +12,6 @@ module.exports = {
'transpose(a)'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'zeros'
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'zeros'
]
};

View File

@ -18,6 +18,6 @@ module.exports = {
'zeros(size(a))'
],
'seealso': [
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'transpose'
'concat', 'det', 'diag', 'eye', 'inv', 'ones', 'range', 'size', 'squeeze', 'subset', 'trace', 'transpose'
]
};

View File

@ -99,6 +99,7 @@ exports.resize = require('./function/matrix/resize');
exports.size = require('./function/matrix/size');
exports.squeeze = require('./function/matrix/squeeze');
exports.subset = require('./function/matrix/subset');
exports.trace = require('./function/matrix/trace');
exports.transpose = require('./function/matrix/transpose');
exports.zeros = require('./function/matrix/zeros');

View File

@ -9,7 +9,8 @@ module.exports = function (math) {
string = util.string;
/**
* Calculate the trace of a matrix.
* Calculate the trace of a matrix: the sum of the elements on the main
* diagonal of a square matrix.
*
* Syntax:
*
@ -26,6 +27,10 @@ module.exports = function (math) {
* ]
* math.trace(A); // returns 6
*
* See also:
*
* diag
*
* @param {Array | Matrix} x A matrix
* @return {Number} The trace of `x`
*/

View File

@ -34,8 +34,8 @@ module.exports = function (math) {
*
* cos, atan, asin
*
* @param {Number | Boolean | Complex | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} The arc cosine of x
* @param {Number | BigNumber Boolean | Complex | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} The arc cosine of x
*/
math.acos = function acos(x) {
if (arguments.length != 1) {

View File

@ -34,8 +34,8 @@ module.exports = function (math) {
*
* sin, atan, acos
*
* @param {Number | Boolean | Complex | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} The arc sine of x
* @param {Number | BigNumber | Boolean | Complex | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} The arc sine of x
*/
math.asin = function asin(x) {
if (arguments.length != 1) {

View File

@ -34,8 +34,8 @@ module.exports = function (math) {
*
* tan, asin, acos
*
* @param {Number | Boolean | Complex | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} The arc tangent of x
* @param {Number | BigNumber | Boolean | Complex | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} The arc tangent of x
*/
math.atan = function atan(x) {
if (arguments.length != 1) {

View File

@ -39,8 +39,8 @@ module.exports = function (math, config) {
*
* cos, tan
*
* @param {Number | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} Cosine of x
* @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} Cosine of x
*/
math.cos = function cos(x) {
if (arguments.length != 1) {

View File

@ -34,8 +34,8 @@ module.exports = function (math) {
*
* sinh, tanh
*
* @param {Number | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} Hyperbolic cosine of x
* @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} Hyperbolic cosine of x
*/
math.cosh = function cosh(x) {
if (arguments.length != 1) {

View File

@ -34,8 +34,8 @@ module.exports = function (math) {
*
* cosh, tanh
*
* @param {Number | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} Hyperbolic sine of x
* @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} Hyperbolic sine of x
*/
math.sinh = function sinh(x) {
if (arguments.length != 1) {

View File

@ -36,8 +36,8 @@ module.exports = function (math, config) {
*
* atan, sin, cos
*
* @param {Number | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} Tangent of x
* @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} Tangent of x
*/
math.tan = function tan(x) {
if (arguments.length != 1) {

View File

@ -37,8 +37,8 @@ module.exports = function (math) {
*
* sinh, cosh, coth
*
* @param {Number | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | Complex | Array | Matrix} Hyperbolic tangent of x
* @param {Number | BigNumber | Boolean | Complex | Unit | Array | Matrix | null} x Function input
* @return {Number | BigNumber | Complex | Array | Matrix} Hyperbolic tangent of x
*/
math.tanh = function tanh(x) {
if (arguments.length != 1) {

View File

@ -10,7 +10,7 @@
* @date @@date
*
* @license
* Copyright (C) 2013-2014 Jos de Jong <wjosdejong@gmail.com>
* Copyright (C) 2013-2015 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

View File

@ -1,3 +1,3 @@
module.exports = '1.2.1-SNAPSHOT';
module.exports = '1.3.0';
// Note: This file is automatically generated when building math.js.
// Changes made in this file will be overwritten.

View File

@ -1,6 +1,6 @@
{
"name": "mathjs",
"version": "1.2.1-SNAPSHOT",
"version": "1.3.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.",
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
"contributors": [