Updated to v2.4.1 (examples not yet updated

This commit is contained in:
jos 2015-10-30 08:38:41 +01:00
parent ea4ee55f03
commit ccc827d3da
9 changed files with 174 additions and 119 deletions

View File

@ -75,6 +75,7 @@ layout: default
- [help(search)](help.html)
- [hypot(a, b, ...)](hypot.html)
- [im(x)](im.html)
- [index(range1, range2, ...)](index.html)
- [intersect(endPoint1Line1, endPoint2Line1, endPoint1Line2, endPoint2Line2)](intersect.html)
- [inv(x)](inv.html)
- [isInteger(x)](isInteger.html)
@ -135,6 +136,7 @@ layout: default
- [smaller(x, y)](smaller.html)
- [smallerEq(x, y)](smallerEq.html)
- [sort(x)](sort.html)
- [sparse(x)](sparse.html)
- [sqrt(x)](sqrt.html)
- [square(x)](square.html)
- [squeeze(x)](squeeze.html)

View File

@ -76,8 +76,10 @@ layout: default
- [chain(value)](chain.html)
- [complex(re, im)](complex.html)
- [fraction(numerator, denominator)](fraction.html)
- [index(range1, range2, ...)](index.html)
- [matrix(x)](matrix.html)
- [number(value)](number.html)
- [sparse(x)](sparse.html)
- [string(value)](string.html)
- [unit(x)](unit.html)

View File

@ -17,7 +17,9 @@ math.index(range1, range2, ...)
<h3 id="where">Where <a href="#where" title="Permalink">#</a></h3>
Each range can be any of:
- A number
- An instance of `Range`
- A one-dimensional Array or a Matrix with numbers
<h3 id="parameters">Parameters <a href="#parameters" title="Permalink">#</a></h3>
@ -38,11 +40,10 @@ Index | Returns the created index
var math = math.js
var b = [1, 2, 3, 4, 5];
math.subset(b, math.index([1, 3])); // returns [2, 3]
math.subset(b, math.index([1, 2, 3])); // returns [2, 3, 4]
var a = math.matrix([[1, 2], [3, 4]]);
a.subset(math.index(0, 1)); // returns 2
a.subset(math.index(1, null)); // returns [3, 4]
```

View File

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

View File

@ -23,18 +23,18 @@ Math.js can be downloaded or linked from [cdnjs](http://cdnjs.com/):
<table class="download">
<tr>
<td>
<a href="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.js">
Development (version 2.4.0)
<a href="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.js">
Development (version 2.4.1)
</a>
</td>
<td>
<span id="development-size">1384 kB</span>, uncompressed with comments
<span id="development-size">1383 kB</span>, uncompressed with comments
</td>
</tr>
<tr>
<td>
<a href="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.0/math.min.js">
Production (version 2.4.0)
<a href="http://cdnjs.cloudflare.com/ajax/libs/mathjs/2.4.1/math.min.js">
Production (version 2.4.1)
</a>
</td>
<td>

View File

@ -4,6 +4,24 @@ layout: default
<h1 id="history">History <a href="#history" title="Permalink">#</a></h1>
<h2 id="20151029-version-241">2015-10-29, version 2.4.1 <a href="#20151029-version-241" title="Permalink">#</a></h2>
- Fixed #480: `nthRoot` not working on Internet Explorer (up to IE 11).
- Fixed #490: `nthRoot` returning an error for negative values like
`nthRoot(-2, 3)`.
- Fixed #489: an issue with initializing a sparse matrix without data.
Thanks @Retsam.
- Fixed: #493: function `combinations` did not throw an exception for
non-integer values of `k`.
- Fixed: function `import` did not override typed functions when the option
override was set true.
- Fixed: added functions `math.sparse` and `math.index` to the reference docs,
they where missing.
- Fixed: removed memoization from `gamma` and `factorial` functions, this
could blow up memory.
<h2 id="20151009-version-240">2015-10-09, version 2.4.0 <a href="#20151009-version-240" title="Permalink">#</a></h2>
- Added support in the expression parser for mathematical alphanumeric symbols

View File

@ -6,8 +6,8 @@
* It features real and complex numbers, units, matrices, a large set of
* mathematical functions, and a flexible expression parser.
*
* @version 2.4.0
* @date 2015-10-09
* @version 2.4.1
* @date 2015-10-29
*
* @license
* Copyright (C) 2013-2015 Jos de Jong <wjosdejong@gmail.com>
@ -2626,6 +2626,7 @@ return /******/ (function(modules) { // webpackBootstrap
if (isFactory(object)) {
_importFactory(object, options);
}
// TODO: allow a typed-function with name too
else if (Array.isArray(object)) {
object.forEach(function (entry) {
math_import(entry, options);
@ -2669,11 +2670,12 @@ return /******/ (function(modules) { // webpackBootstrap
}
if (isTypedFunction(math[name]) && isTypedFunction(value)) {
// merge two typed functions
if (options.override) {
value = typed(extend({}, math[name].signatures, value.signatures));
// give the typed function the right name
value = typed(name, value.signatures);
}
else {
// merge the existing and typed function
value = typed(math[name], value);
}
@ -2745,11 +2747,11 @@ return /******/ (function(modules) { // webpackBootstrap
var instance = load(factory);
if (isTypedFunction(existing) && isTypedFunction(instance)) {
// merge two typed functions
if (options.override) {
instance = typed(extend({}, existing.signatures, instance.signatures));
// replace the existing typed function (nothing to do)
}
else {
// merge the existing and new typed function
instance = typed(existing, instance);
}
@ -13686,7 +13688,7 @@ return /******/ (function(modules) { // webpackBootstrap
this._values = [];
this._index = [];
this._ptr = [0];
this._size = [0];
this._size = [0, 0];
this._datatype = datatype;
}
}
@ -18682,7 +18684,7 @@ return /******/ (function(modules) { // webpackBootstrap
/* 79 */
/***/ function(module, exports) {
module.exports = '2.4.0';
module.exports = '2.4.1';
// Note: This file is automatically generated when building math.js.
// Changes made in this file will be overwritten.
@ -20845,16 +20847,15 @@ return /******/ (function(modules) { // webpackBootstrap
'name': 'not',
'category': 'Logical',
'syntax': [
'!x',
'not x',
'not(x)'
],
'description': 'Logical not. Flips the boolean value of given argument.',
'examples': [
'!true',
'not true',
'not false',
'!2',
'!0'
'not 2',
'not 0'
],
'seealso': [
'and', 'or', 'xor'
@ -39258,37 +39259,36 @@ return /******/ (function(modules) { // webpackBootstrap
* @private
*/
function _bigNthRoot(a, root) {
var precision = type.BigNumber.precision;
var Big = type.BigNumber.constructor({precision: precision + 2});
var zero = new type.BigNumber(0);
var one = new type.BigNumber(1);
var inv = root.isNegative();
if (inv) root = root.negated();
if (root.isZero()) throw new Error('Root must be non-zero');
if (a.isNegative() && !root.abs().mod(2).equals(1)) throw new Error('Root must be odd when a is negative.');
var one = new Big(1);
var inv = root.isNegative();
if (inv) {
root = root.neg();
}
if (root.isZero()) {
throw new Error('Root must be non-zero');
}
if (a.isNegative() && !root.abs().mod(2).equals(1)) {
throw new Error('Root must be odd when a is negative.');
}
// edge cases zero and infinity
if (a.isZero()) return zero;
if (!a.isFinite())
{
if (a.isZero()) {
return zero;
}
if (!a.isFinite()) {
return inv ? zero : a;
}
var x = one; // Initial guess
var i = 0;
var iMax = 10000;
do {
var xPrev = x;
var delta = a.div(x.pow(root.minus(1))).minus(x).div(root);
x = x.plus(delta);
i++;
}
while (!x.equals(xPrev) && i < iMax);
if (!x.equals(xPrev)) {
throw new Error('Function nthRoot failed to converge');
}
return inv ? one.div(x) : x;
var x = a.abs().pow(one.div(root));
// If a < 0, we require that root is an odd integer,
// so (-1) ^ (1/root) = -1
x = a.isNeg() ? x.neg() : x;
return new type.BigNumber((inv ? one.div(x) : x).toPrecision(precision));
}
}
@ -39301,17 +39301,35 @@ return /******/ (function(modules) { // webpackBootstrap
*/
function _nthRoot(a, root) {
var inv = root < 0;
if (inv) root = -root;
if (inv) {
root = -root;
}
if (root === 0) throw new Error('Root must be non-zero');
if (a < 0 && (Math.abs(root) % 2 != 1)) throw new Error('Root must be odd when a is negative.');
if (root === 0) {
throw new Error('Root must be non-zero');
}
if (a < 0 && (Math.abs(root) % 2 != 1)) {
throw new Error('Root must be odd when a is negative.');
}
// edge cases zero and infinity
if (a == 0) return 0;
if (!Number.isFinite(a)) {
if (a == 0) {
return 0;
}
if (!isFinite(a)) {
return inv ? 0 : a;
}
var x = Math.pow(Math.abs(a), 1/root);
// If a < 0, we require that root is an odd integer,
// so (-1) ^ (1/root) = -1
x = a < 0 ? -x : x;
return inv ? 1 / x : x;
// Very nice algorithm, but fails with nthRoot(-2, 3).
// Newton's method has some well-known problems at times:
// https://en.wikipedia.org/wiki/Newton%27s_method#Failure_analysis
/*
var x = 1; // Initial guess
var xPrev = 1;
var i = 0;
@ -39329,6 +39347,7 @@ return /******/ (function(modules) { // webpackBootstrap
}
return inv ? 1 / x : x;
*/
}
/**
@ -42069,39 +42088,21 @@ return /******/ (function(modules) { // webpackBootstrap
* @returns {BigNumber} Returns the factorial of n
*/
function bigFactorial(n) {
var value, res, preciseFacs;
var num = n.toNumber(); // should definitely be below Number.MAX_VALUE
if (num < smallBigFacs.length) {
return new type.BigNumber(smallBigFacs[num]).toSD(config.precision);
if (n.isZero()) {
return new type.BigNumber(1); // 0! is per definition 1
}
// be wary of round-off errors
var precision = config.precision + (Math.log(num) | 0);
var precision = config.precision + (Math.log(n.toNumber()) | 0);
var Big = type.BigNumber.constructor({precision: precision});
// adjust n do align with the precision specific tables
num -= smallBigFacs.length;
if (preciseFacs = bigBigFacs[precision]) {
if (preciseFacs[num]) {
return new type.BigNumber(preciseFacs[num].toPrecision(config.precision));
}
res = preciseFacs[preciseFacs.length-1];
} else {
preciseFacs = bigBigFacs[precision] = [];
res = new Big(smallBigFacs[smallBigFacs.length-1])
.toSD(precision);
var res = new Big(n);
var value = n.toNumber() - 1; // number
while (value > 1) {
res = res.times(value);
value--;
}
var one = new Big(1);
value = new Big(preciseFacs.length + smallBigFacs.length);
for (var i = preciseFacs.length; i < num; ++i) {
preciseFacs[i] = res = res.times(value);
value = value.plus(one);
}
preciseFacs[num] = res.times(value);
return new type.BigNumber(preciseFacs[num].toPrecision(config.precision));
return new type.BigNumber(res.toPrecision(type.BigNumber.precision));
}
gamma.toTex = '\\Gamma\\left(${args[0]}\\right)';
@ -42131,34 +42132,6 @@ return /******/ (function(modules) { // webpackBootstrap
0.36899182659531622704e-5
];
// 21! >= values for each precision
var bigBigFacs = [];
// 0-20! values
var smallBigFacs = [
1,
1,
2,
6,
24,
120,
720,
5040,
40320,
362880,
3628800,
39916800,
479001600,
6227020800,
87178291200,
1307674368000,
20922789888000,
355687428096000,
6402373705728000,
121645100408832000,
2432902008176640000
];
exports.name = 'gamma';
exports.factory = factory;
@ -42202,6 +42175,9 @@ return /******/ (function(modules) { // webpackBootstrap
if (!isInteger(n) || n < 0) {
throw new TypeError('Positive integer value expected in function combinations');
}
if (!isInteger(k) || k < 0) {
throw new TypeError('Positive integer value expected in function combinations');
}
if (k > n) {
throw new TypeError('k must be less than or equal to n');
}

File diff suppressed because one or more lines are too long

28
js/lib/math.min.js vendored

File diff suppressed because one or more lines are too long