mathjs 11.12.0 → 12.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +54 -2
- package/README.md +1 -1
- package/lib/browser/math.js +1 -1
- package/lib/browser/math.js.LICENSE.txt +2 -2
- package/lib/browser/math.js.map +1 -1
- package/lib/cjs/entry/dependenciesAny/dependenciesEigs.generated.js +4 -0
- package/lib/cjs/entry/pureFunctionsAny.generated.js +2 -0
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/round.js +2 -2
- package/lib/cjs/expression/embeddedDocs/function/matrix/eigs.js +2 -2
- package/lib/cjs/expression/node/AssignmentNode.js +1 -1
- package/lib/cjs/expression/node/FunctionAssignmentNode.js +1 -1
- package/lib/cjs/function/algebra/derivative.js +8 -31
- package/lib/cjs/function/arithmetic/gcd.js +4 -5
- package/lib/cjs/function/arithmetic/mod.js +2 -9
- package/lib/cjs/function/arithmetic/round.js +59 -16
- package/lib/cjs/function/matrix/eigs/complexEigs.js +73 -68
- package/lib/cjs/function/matrix/eigs/{realSymetric.js → realSymmetric.js} +57 -51
- package/lib/cjs/function/matrix/eigs.js +118 -45
- package/lib/cjs/function/probability/pickRandom.js +2 -2
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/number.js +2 -2
- package/lib/cjs/utils/number.js +1 -1
- package/lib/cjs/utils/snapshot.js +6 -6
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesEigs.generated.js +4 -0
- package/lib/esm/entry/pureFunctionsAny.generated.js +2 -0
- package/lib/esm/expression/embeddedDocs/function/arithmetic/round.js +2 -2
- package/lib/esm/expression/embeddedDocs/function/matrix/eigs.js +2 -2
- package/lib/esm/expression/node/AssignmentNode.js +1 -1
- package/lib/esm/expression/node/FunctionAssignmentNode.js +1 -1
- package/lib/esm/function/algebra/derivative.js +8 -31
- package/lib/esm/function/arithmetic/mod.js +2 -9
- package/lib/esm/function/arithmetic/round.js +40 -17
- package/lib/esm/function/matrix/eigs/complexEigs.js +73 -68
- package/lib/esm/function/matrix/eigs/{realSymetric.js → realSymmetric.js} +55 -51
- package/lib/esm/function/matrix/eigs.js +119 -47
- package/lib/esm/function/probability/pickRandom.js +2 -2
- package/lib/esm/type/number.js +2 -2
- package/lib/esm/utils/number.js +1 -1
- package/lib/esm/version.js +1 -1
- package/package.json +14 -14
- package/types/EXPLANATION.md +54 -0
- package/types/index.d.ts +6825 -6483
@@ -1,18 +1,20 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
4
5
|
value: true
|
5
6
|
});
|
6
7
|
exports.createEigs = void 0;
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
7
9
|
var _factory = require("../../utils/factory.js");
|
8
10
|
var _string = require("../../utils/string.js");
|
9
11
|
var _complexEigs = require("./eigs/complexEigs.js");
|
10
|
-
var
|
12
|
+
var _realSymmetric = require("./eigs/realSymmetric.js");
|
11
13
|
var _is = require("../../utils/is.js");
|
12
14
|
var name = 'eigs';
|
13
15
|
|
14
16
|
// The absolute state of math.js's dependency system:
|
15
|
-
var dependencies = ['config', 'typed', 'matrix', 'addScalar', 'equal', 'subtract', 'abs', 'atan', 'cos', 'sin', 'multiplyScalar', 'divideScalar', 'inv', 'bignumber', 'multiply', 'add', 'larger', 'column', 'flatten', 'number', 'complex', 'sqrt', 'diag', 'qr', 'usolve', 'usolveAll', 'im', 're', 'smaller', 'matrixFromColumns', 'dot'];
|
17
|
+
var dependencies = ['config', 'typed', 'matrix', 'addScalar', 'equal', 'subtract', 'abs', 'atan', 'cos', 'sin', 'multiplyScalar', 'divideScalar', 'inv', 'bignumber', 'multiply', 'add', 'larger', 'column', 'flatten', 'number', 'complex', 'sqrt', 'diag', 'size', 'reshape', 'qr', 'usolve', 'usolveAll', 'im', 're', 'smaller', 'matrixFromColumns', 'dot'];
|
16
18
|
var createEigs = exports.createEigs = /* #__PURE__ */(0, _factory.factory)(name, dependencies, function (_ref) {
|
17
19
|
var config = _ref.config,
|
18
20
|
typed = _ref.typed,
|
@@ -37,6 +39,8 @@ var createEigs = exports.createEigs = /* #__PURE__ */(0, _factory.factory)(name,
|
|
37
39
|
complex = _ref.complex,
|
38
40
|
sqrt = _ref.sqrt,
|
39
41
|
diag = _ref.diag,
|
42
|
+
size = _ref.size,
|
43
|
+
reshape = _ref.reshape,
|
40
44
|
qr = _ref.qr,
|
41
45
|
usolve = _ref.usolve,
|
42
46
|
usolveAll = _ref.usolveAll,
|
@@ -45,7 +49,7 @@ var createEigs = exports.createEigs = /* #__PURE__ */(0, _factory.factory)(name,
|
|
45
49
|
smaller = _ref.smaller,
|
46
50
|
matrixFromColumns = _ref.matrixFromColumns,
|
47
51
|
dot = _ref.dot;
|
48
|
-
var
|
52
|
+
var doRealSymmetric = (0, _realSymmetric.createRealSymmetric)({
|
49
53
|
config: config,
|
50
54
|
addScalar: addScalar,
|
51
55
|
subtract: subtract,
|
@@ -75,6 +79,8 @@ var createEigs = exports.createEigs = /* #__PURE__ */(0, _factory.factory)(name,
|
|
75
79
|
abs: abs,
|
76
80
|
bignumber: bignumber,
|
77
81
|
diag: diag,
|
82
|
+
size: size,
|
83
|
+
reshape: reshape,
|
78
84
|
qr: qr,
|
79
85
|
inv: inv,
|
80
86
|
usolve: usolve,
|
@@ -88,26 +94,54 @@ var createEigs = exports.createEigs = /* #__PURE__ */(0, _factory.factory)(name,
|
|
88
94
|
});
|
89
95
|
|
90
96
|
/**
|
91
|
-
* Compute eigenvalues and eigenvectors of a matrix.
|
92
|
-
*
|
93
|
-
*
|
94
|
-
*
|
97
|
+
* Compute eigenvalues and optionally eigenvectors of a square matrix.
|
98
|
+
* The eigenvalues are sorted by their absolute value, ascending, and
|
99
|
+
* returned as a vector in the `values` property of the returned project.
|
100
|
+
* An eigenvalue with algebraic multiplicity k will be listed k times, so
|
101
|
+
* that the returned `values` vector always has length equal to the size
|
102
|
+
* of the input matrix.
|
103
|
+
*
|
104
|
+
* The `eigenvectors` property of the return value provides the eigenvectors.
|
105
|
+
* It is an array of plain objects: the `value` property of each gives the
|
106
|
+
* associated eigenvalue, and the `vector` property gives the eigenvector
|
107
|
+
* itself. Note that the same `value` property will occur as many times in
|
108
|
+
* the list provided by `eigenvectors` as the geometric multiplicity of
|
109
|
+
* that value.
|
110
|
+
*
|
111
|
+
* If the algorithm fails to converge, it will throw an error –
|
112
|
+
* in that case, however, you may still find useful information
|
95
113
|
* in `err.values` and `err.vectors`.
|
96
114
|
*
|
115
|
+
* Note that the 'precision' option does not directly specify the _accuracy_
|
116
|
+
* of the returned eigenvalues. Rather, it determines how small an entry
|
117
|
+
* of the iterative approximations to an upper triangular matrix must be
|
118
|
+
* in order to be considered zero. The actual accuracy of the returned
|
119
|
+
* eigenvalues may be greater or less than the precision, depending on the
|
120
|
+
* conditioning of the matrix and how far apart or close the actual
|
121
|
+
* eigenvalues are. Note that currently, relatively simple, "traditional"
|
122
|
+
* methods of eigenvalue computation are being used; this is not a modern,
|
123
|
+
* high-precision eigenvalue computation. That said, it should typically
|
124
|
+
* produce fairly reasonable results.
|
125
|
+
*
|
97
126
|
* Syntax:
|
98
127
|
*
|
99
128
|
* math.eigs(x, [prec])
|
129
|
+
* math.eigs(x, {options})
|
100
130
|
*
|
101
131
|
* Examples:
|
102
132
|
*
|
103
|
-
* const { eigs, multiply, column, transpose } = math
|
133
|
+
* const { eigs, multiply, column, transpose, matrixFromColumns } = math
|
104
134
|
* const H = [[5, 2.3], [2.3, 1]]
|
105
|
-
* const ans = eigs(H) // returns {values: [E1,E2...sorted],
|
135
|
+
* const ans = eigs(H) // returns {values: [E1,E2...sorted], eigenvectors: [{value: E1, vector: v2}, {value: e, vector: v2}, ...]
|
106
136
|
* const E = ans.values
|
107
|
-
* const
|
108
|
-
* multiply(H,
|
109
|
-
* const
|
110
|
-
*
|
137
|
+
* const V = ans.eigenvectors
|
138
|
+
* multiply(H, V[0].vector)) // returns multiply(E[0], V[0].vector))
|
139
|
+
* const U = matrixFromColumns(...V.map(obj => obj.vector))
|
140
|
+
* const UTxHxU = multiply(transpose(U), H, U) // diagonalizes H if possible
|
141
|
+
* E[0] == UTxHxU[0][0] // returns true always
|
142
|
+
*
|
143
|
+
* // Compute only approximate eigenvalues:
|
144
|
+
* const {values} = eigs(H, {eigenvectors: false, precision: 1e-6})
|
111
145
|
*
|
112
146
|
* See also:
|
113
147
|
*
|
@@ -115,57 +149,96 @@ var createEigs = exports.createEigs = /* #__PURE__ */(0, _factory.factory)(name,
|
|
115
149
|
*
|
116
150
|
* @param {Array | Matrix} x Matrix to be diagonalized
|
117
151
|
*
|
118
|
-
* @param {number | BigNumber} [
|
119
|
-
* @return {{values: Array|Matrix,
|
152
|
+
* @param {number | BigNumber | OptsObject} [opts] Object with keys `precision`, defaulting to config.epsilon, and `eigenvectors`, defaulting to true and specifying whether to compute eigenvectors. If just a number, specifies precision.
|
153
|
+
* @return {{values: Array|Matrix, eigenvectors?: Array<EVobj>}} Object containing an array of eigenvalues and an array of {value: number|BigNumber, vector: Array|Matrix} objects. The eigenvectors property is undefined if eigenvectors were not requested.
|
120
154
|
*
|
121
155
|
*/
|
122
156
|
return typed('eigs', {
|
157
|
+
// The conversion to matrix in the first two implementations,
|
158
|
+
// just to convert back to an array right away in
|
159
|
+
// computeValuesAndVectors, is unfortunate, and should perhaps be
|
160
|
+
// streamlined. It is done because the Matrix object carries some
|
161
|
+
// type information about its entries, and so constructing the matrix
|
162
|
+
// is a roundabout way of doing type detection.
|
123
163
|
Array: function Array(x) {
|
124
|
-
|
125
|
-
return computeValuesAndVectors(mat);
|
164
|
+
return doEigs(matrix(x));
|
126
165
|
},
|
127
166
|
'Array, number|BigNumber': function ArrayNumberBigNumber(x, prec) {
|
128
|
-
|
129
|
-
|
167
|
+
return doEigs(matrix(x), {
|
168
|
+
precision: prec
|
169
|
+
});
|
170
|
+
},
|
171
|
+
'Array, Object': function ArrayObject(x, opts) {
|
172
|
+
return doEigs(matrix(x), opts);
|
130
173
|
},
|
131
174
|
Matrix: function Matrix(mat) {
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
return {
|
136
|
-
values: matrix(values),
|
137
|
-
vectors: matrix(vectors)
|
138
|
-
};
|
175
|
+
return doEigs(mat, {
|
176
|
+
matricize: true
|
177
|
+
});
|
139
178
|
},
|
140
179
|
'Matrix, number|BigNumber': function MatrixNumberBigNumber(mat, prec) {
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
180
|
+
return doEigs(mat, {
|
181
|
+
precision: prec,
|
182
|
+
matricize: true
|
183
|
+
});
|
184
|
+
},
|
185
|
+
'Matrix, Object': function MatrixObject(mat, opts) {
|
186
|
+
var useOpts = {
|
187
|
+
matricize: true
|
147
188
|
};
|
189
|
+
(0, _extends2["default"])(useOpts, opts);
|
190
|
+
return doEigs(mat, useOpts);
|
148
191
|
}
|
149
192
|
});
|
150
|
-
function
|
151
|
-
|
152
|
-
|
193
|
+
function doEigs(mat) {
|
194
|
+
var _opts$precision;
|
195
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
196
|
+
var computeVectors = 'eigenvectors' in opts ? opts.eigenvectors : true;
|
197
|
+
var prec = (_opts$precision = opts.precision) !== null && _opts$precision !== void 0 ? _opts$precision : config.epsilon;
|
198
|
+
var result = computeValuesAndVectors(mat, prec, computeVectors);
|
199
|
+
if (opts.matricize) {
|
200
|
+
result.values = matrix(result.values);
|
201
|
+
if (computeVectors) {
|
202
|
+
result.eigenvectors = result.eigenvectors.map(function (_ref2) {
|
203
|
+
var value = _ref2.value,
|
204
|
+
vector = _ref2.vector;
|
205
|
+
return {
|
206
|
+
value: value,
|
207
|
+
vector: matrix(vector)
|
208
|
+
};
|
209
|
+
});
|
210
|
+
}
|
211
|
+
}
|
212
|
+
if (computeVectors) {
|
213
|
+
Object.defineProperty(result, 'vectors', {
|
214
|
+
enumerable: false,
|
215
|
+
// to make sure that the eigenvectors can still be
|
216
|
+
// converted to string.
|
217
|
+
get: function get() {
|
218
|
+
throw new Error('eigs(M).vectors replaced with eigs(M).eigenvectors');
|
219
|
+
}
|
220
|
+
});
|
153
221
|
}
|
154
|
-
|
155
|
-
|
156
|
-
|
222
|
+
return result;
|
223
|
+
}
|
224
|
+
function computeValuesAndVectors(mat, prec, computeVectors) {
|
225
|
+
var arr = mat.toArray(); // NOTE: arr is guaranteed to be unaliased
|
226
|
+
// and so safe to modify in place
|
227
|
+
var asize = mat.size();
|
228
|
+
if (asize.length !== 2 || asize[0] !== asize[1]) {
|
229
|
+
throw new RangeError("Matrix must be square (size: ".concat((0, _string.format)(asize), ")"));
|
157
230
|
}
|
158
|
-
var
|
159
|
-
var N = size[0];
|
231
|
+
var N = asize[0];
|
160
232
|
if (isReal(arr, N, prec)) {
|
161
|
-
coerceReal(arr, N);
|
233
|
+
coerceReal(arr, N); // modifies arr by side effect
|
234
|
+
|
162
235
|
if (isSymmetric(arr, N, prec)) {
|
163
|
-
var _type = coerceTypes(mat, arr, N);
|
164
|
-
return
|
236
|
+
var _type = coerceTypes(mat, arr, N); // modifies arr by side effect
|
237
|
+
return doRealSymmetric(arr, N, prec, _type, computeVectors);
|
165
238
|
}
|
166
239
|
}
|
167
|
-
var type = coerceTypes(mat, arr, N);
|
168
|
-
return doComplexEigs(arr, N, prec, type);
|
240
|
+
var type = coerceTypes(mat, arr, N); // modifies arr by side effect
|
241
|
+
return doComplexEigs(arr, N, prec, type, computeVectors);
|
169
242
|
}
|
170
243
|
|
171
244
|
/** @return {boolean} */
|
@@ -56,8 +56,8 @@ var createPickRandom = exports.createPickRandom = /* #__PURE__ */(0, _factory.fa
|
|
56
56
|
* @param {Array | Matrix} array A one dimensional array
|
57
57
|
* @param {Int} number An int or float
|
58
58
|
* @param {Array | Matrix} weights An array of ints or floats
|
59
|
-
* @return {number | Array} Returns a single random value from array when number is
|
60
|
-
* Returns an array with the configured number of elements when number is
|
59
|
+
* @return {number | Array} Returns a single random value from array when number is undefined.
|
60
|
+
* Returns an array with the configured number of elements when number is defined.
|
61
61
|
*/
|
62
62
|
return typed(name, {
|
63
63
|
'Array | Matrix': function ArrayMatrix(possibles) {
|
package/lib/cjs/header.js
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
* It features real and complex numbers, units, matrices, a large set of
|
7
7
|
* mathematical functions, and a flexible expression parser.
|
8
8
|
*
|
9
|
-
* @version
|
10
|
-
* @date 2023-
|
9
|
+
* @version 12.1.0
|
10
|
+
* @date 2023-11-17
|
11
11
|
*
|
12
12
|
* @license
|
13
13
|
* Copyright (C) 2013-2023 Jos de Jong <wjosdejong@gmail.com>
|
package/lib/cjs/type/number.js
CHANGED
@@ -49,7 +49,7 @@ function makeNumberFromNonDecimalParts(parts) {
|
|
49
49
|
}
|
50
50
|
var result = n + f;
|
51
51
|
if (isNaN(result)) {
|
52
|
-
throw new SyntaxError('String "' + parts.input + '" is
|
52
|
+
throw new SyntaxError('String "' + parts.input + '" is not a valid number');
|
53
53
|
}
|
54
54
|
return result;
|
55
55
|
}
|
@@ -103,7 +103,7 @@ var createNumber = exports.createNumber = /* #__PURE__ */(0, _factory.factory)(n
|
|
103
103
|
}
|
104
104
|
var num = Number(x);
|
105
105
|
if (isNaN(num)) {
|
106
|
-
throw new SyntaxError('String "' + x + '" is
|
106
|
+
throw new SyntaxError('String "' + x + '" is not a valid number');
|
107
107
|
}
|
108
108
|
if (wordSizeSuffixMatch) {
|
109
109
|
// x is a signed bin, oct, or hex literal
|
package/lib/cjs/utils/number.js
CHANGED
@@ -604,7 +604,7 @@ function nearlyEqual(x, y, epsilon) {
|
|
604
604
|
if (isFinite(x) && isFinite(y)) {
|
605
605
|
// check numbers are very close, needed when comparing numbers near zero
|
606
606
|
var diff = Math.abs(x - y);
|
607
|
-
if (diff
|
607
|
+
if (diff <= DBL_EPSILON) {
|
608
608
|
return true;
|
609
609
|
} else {
|
610
610
|
// use relative error
|
@@ -18,12 +18,12 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
18
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
|
19
19
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
20
20
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } /**
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
* This file contains helper methods to create expected snapshot structures
|
22
|
+
* of both instance and ES6 exports.
|
23
|
+
*
|
24
|
+
* The files are located here and not under /test or /tools so it's transpiled
|
25
|
+
* into ES5 code under /lib and can be used straight by node.js
|
26
|
+
*/
|
27
27
|
var validateTypeOf = exports.validateTypeOf = allIsFunctions.typeOf;
|
28
28
|
function validateBundle(expectedBundleStructure, bundle) {
|
29
29
|
var originalWarn = console.warn;
|
package/lib/cjs/version.js
CHANGED
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.version = void 0;
|
7
|
-
var version = exports.version = '
|
7
|
+
var version = exports.version = '12.1.0';
|
8
8
|
// Note: This file is automatically generated when building math.js.
|
9
9
|
// Changes made in this file will be overwritten.
|
@@ -25,7 +25,9 @@ import { multiplyScalarDependencies } from './dependenciesMultiplyScalar.generat
|
|
25
25
|
import { numberDependencies } from './dependenciesNumber.generated.js';
|
26
26
|
import { qrDependencies } from './dependenciesQr.generated.js';
|
27
27
|
import { reDependencies } from './dependenciesRe.generated.js';
|
28
|
+
import { reshapeDependencies } from './dependenciesReshape.generated.js';
|
28
29
|
import { sinDependencies } from './dependenciesSin.generated.js';
|
30
|
+
import { sizeDependencies } from './dependenciesSize.generated.js';
|
29
31
|
import { smallerDependencies } from './dependenciesSmaller.generated.js';
|
30
32
|
import { sqrtDependencies } from './dependenciesSqrt.generated.js';
|
31
33
|
import { subtractDependencies } from './dependenciesSubtract.generated.js';
|
@@ -57,7 +59,9 @@ export var eigsDependencies = {
|
|
57
59
|
numberDependencies,
|
58
60
|
qrDependencies,
|
59
61
|
reDependencies,
|
62
|
+
reshapeDependencies,
|
60
63
|
sinDependencies,
|
64
|
+
sizeDependencies,
|
61
65
|
smallerDependencies,
|
62
66
|
sqrtDependencies,
|
63
67
|
subtractDependencies,
|
@@ -1,8 +1,8 @@
|
|
1
1
|
export var roundDocs = {
|
2
2
|
name: 'round',
|
3
3
|
category: 'Arithmetic',
|
4
|
-
syntax: ['round(x)', 'round(x, n)'],
|
4
|
+
syntax: ['round(x)', 'round(x, n)', 'round(unit, valuelessUnit)', 'round(unit, n, valuelessUnit)'],
|
5
5
|
description: 'round a value towards the nearest integer.If x is complex, both real and imaginary part are rounded towards the nearest integer. When n is specified, the value is rounded to n decimals.',
|
6
|
-
examples: ['round(3.2)', 'round(3.8)', 'round(-4.2)', 'round(-4.8)', 'round(pi, 3)', 'round(123.45678, 2)'],
|
6
|
+
examples: ['round(3.2)', 'round(3.8)', 'round(-4.2)', 'round(-4.8)', 'round(pi, 3)', 'round(123.45678, 2)', 'round(3.241cm, 2, cm)', 'round([3.2, 3.8, -4.7])'],
|
7
7
|
seealso: ['ceil', 'floor', 'fix']
|
8
8
|
};
|
@@ -2,7 +2,7 @@ export var eigsDocs = {
|
|
2
2
|
name: 'eigs',
|
3
3
|
category: 'Matrix',
|
4
4
|
syntax: ['eigs(x)'],
|
5
|
-
description: 'Calculate the eigenvalues and eigenvectors of a
|
6
|
-
examples: ['eigs([[5, 2.3], [2.3, 1]])'],
|
5
|
+
description: 'Calculate the eigenvalues and optionally eigenvectors of a square matrix',
|
6
|
+
examples: ['eigs([[5, 2.3], [2.3, 1]])', 'eigs([[1, 2, 3], [4, 5, 6], [7, 8, 9]], { precision: 1e-6, eigenvectors: false }'],
|
7
7
|
seealso: ['inv']
|
8
8
|
};
|
@@ -295,7 +295,7 @@ export var createAssignmentNode = /* #__PURE__ */factory(name, dependencies, _re
|
|
295
295
|
if (needParenthesis(this, options && options.parenthesis, options && options.implicit)) {
|
296
296
|
value = "\\left(".concat(value, "\\right)");
|
297
297
|
}
|
298
|
-
return object + index + '
|
298
|
+
return object + index + '=' + value;
|
299
299
|
}
|
300
300
|
}
|
301
301
|
_defineProperty(AssignmentNode, "name", name);
|
@@ -224,7 +224,7 @@ export var createFunctionAssignmentNode = /* #__PURE__ */factory(name, dependenc
|
|
224
224
|
if (needParenthesis(this, parenthesis, options && options.implicit)) {
|
225
225
|
expr = "\\left(".concat(expr, "\\right)");
|
226
226
|
}
|
227
|
-
return '\\mathrm{' + this.name + '}\\left(' + this.params.map(toSymbol).join(',') + '\\right)
|
227
|
+
return '\\mathrm{' + this.name + '}\\left(' + this.params.map(toSymbol).join(',') + '\\right)=' + expr;
|
228
228
|
}
|
229
229
|
}
|
230
230
|
_defineProperty(FunctionAssignmentNode, "name", name);
|
@@ -208,9 +208,6 @@ export var createDerivative = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
208
208
|
return _derivative(node.expr, constNodes);
|
209
209
|
},
|
210
210
|
'FunctionNode, Object': function FunctionNodeObject(node, constNodes) {
|
211
|
-
if (node.args.length !== 1) {
|
212
|
-
funcArgsCheck(node);
|
213
|
-
}
|
214
211
|
if (constNodes[node] !== undefined) {
|
215
212
|
return createConstantNode(0);
|
216
213
|
}
|
@@ -259,9 +256,12 @@ export var createDerivative = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
259
256
|
}
|
260
257
|
break;
|
261
258
|
case 'pow':
|
262
|
-
|
263
|
-
|
264
|
-
|
259
|
+
if (node.args.length === 2) {
|
260
|
+
constNodes[arg1] = constNodes[node.args[1]];
|
261
|
+
// Pass to pow operator node parser
|
262
|
+
return _derivative(new OperatorNode('^', 'pow', [arg0, node.args[1]]), constNodes);
|
263
|
+
}
|
264
|
+
break;
|
265
265
|
case 'exp':
|
266
266
|
// d/dx(e^x) = e^x
|
267
267
|
funcDerivative = new FunctionNode('exp', [arg0.clone()]);
|
@@ -391,7 +391,7 @@ export var createDerivative = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
391
391
|
break;
|
392
392
|
case 'gamma': // Needs digamma function, d/dx(gamma(x)) = gamma(x)digamma(x)
|
393
393
|
default:
|
394
|
-
throw new Error('
|
394
|
+
throw new Error('Cannot process function "' + node.name + '" in derivative: ' + 'the function is not supported, undefined, or the number of arguments passed to it are not supported');
|
395
395
|
}
|
396
396
|
var op, func;
|
397
397
|
if (div) {
|
@@ -502,33 +502,10 @@ export var createDerivative = /* #__PURE__ */factory(name, dependencies, _ref =>
|
|
502
502
|
// Functional Power Rule, d/dx(f^g) = f^g*[f'*(g/f) + g'ln(f)]
|
503
503
|
return new OperatorNode('*', 'multiply', [new OperatorNode('^', 'pow', [_arg.clone(), _arg2.clone()]), new OperatorNode('+', 'add', [new OperatorNode('*', 'multiply', [_derivative(_arg, constNodes), new OperatorNode('/', 'divide', [_arg2.clone(), _arg.clone()])]), new OperatorNode('*', 'multiply', [_derivative(_arg2, constNodes), new FunctionNode('log', [_arg.clone()])])])]);
|
504
504
|
}
|
505
|
-
throw new Error('
|
505
|
+
throw new Error('Cannot process operator "' + node.op + '" in derivative: ' + 'the operator is not supported, undefined, or the number of arguments passed to it are not supported');
|
506
506
|
}
|
507
507
|
});
|
508
508
|
|
509
|
-
/**
|
510
|
-
* Ensures the number of arguments for a function are correct,
|
511
|
-
* and will throw an error otherwise.
|
512
|
-
*
|
513
|
-
* @param {FunctionNode} node
|
514
|
-
*/
|
515
|
-
function funcArgsCheck(node) {
|
516
|
-
// TODO add min, max etc
|
517
|
-
if ((node.name === 'log' || node.name === 'nthRoot' || node.name === 'pow') && node.args.length === 2) {
|
518
|
-
return;
|
519
|
-
}
|
520
|
-
|
521
|
-
// There should be an incorrect number of arguments if we reach here
|
522
|
-
|
523
|
-
// Change all args to constants to avoid unidentified
|
524
|
-
// symbol error when compiling function
|
525
|
-
for (var i = 0; i < node.args.length; ++i) {
|
526
|
-
node.args[i] = createConstantNode(0);
|
527
|
-
}
|
528
|
-
node.compile().evaluate();
|
529
|
-
throw new Error('Function "' + node.name + '" is not supported by derivative, or a wrong number of arguments is passed');
|
530
|
-
}
|
531
|
-
|
532
509
|
/**
|
533
510
|
* Helper function to create a constant node with a specific type
|
534
511
|
* (number, BigNumber, Fraction)
|
@@ -91,17 +91,10 @@ export var createMod = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
91
91
|
return typed(name, {
|
92
92
|
'number, number': _modNumber,
|
93
93
|
'BigNumber, BigNumber': function BigNumberBigNumber(x, y) {
|
94
|
-
|
95
|
-
throw new Error('Cannot calculate mod for a negative divisor');
|
96
|
-
}
|
97
|
-
return y.isZero() ? x : x.mod(y);
|
94
|
+
return y.isZero() ? x : x.sub(y.mul(floor(x.div(y))));
|
98
95
|
},
|
99
96
|
'Fraction, Fraction': function FractionFraction(x, y) {
|
100
|
-
|
101
|
-
throw new Error('Cannot calculate mod for a negative divisor');
|
102
|
-
}
|
103
|
-
// Workaround suggested in Fraction.js library to calculate correct modulo for negative dividend
|
104
|
-
return x.compare(0) >= 0 ? x.mod(y) : x.mod(y).add(y).mod(y);
|
97
|
+
return y.equals(0) ? x : x.sub(y.mul(floor(x.div(y))));
|
105
98
|
}
|
106
99
|
}, matrixAlgorithmSuite({
|
107
100
|
SS: matAlgo05xSfSf,
|
@@ -36,6 +36,8 @@ export var createRound = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
36
36
|
*
|
37
37
|
* math.round(x)
|
38
38
|
* math.round(x, n)
|
39
|
+
* math.round(unit, valuelessUnit)
|
40
|
+
* math.round(unit, n, valuelessUnit)
|
39
41
|
*
|
40
42
|
* Examples:
|
41
43
|
*
|
@@ -53,14 +55,21 @@ export var createRound = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
53
55
|
* const c = math.complex(3.2, -2.7)
|
54
56
|
* math.round(c) // returns Complex 3 - 3i
|
55
57
|
*
|
58
|
+
* const unit = math.unit('3.241 cm')
|
59
|
+
* const cm = math.unit('cm')
|
60
|
+
* const mm = math.unit('mm')
|
61
|
+
* math.round(unit, 1, cm) // returns Unit 3.2 cm
|
62
|
+
* math.round(unit, 1, mm) // returns Unit 32.4 mm
|
63
|
+
*
|
56
64
|
* math.round([3.2, 3.8, -4.7]) // returns Array [3, 4, -5]
|
57
65
|
*
|
58
66
|
* See also:
|
59
67
|
*
|
60
68
|
* ceil, fix, floor
|
61
69
|
*
|
62
|
-
* @param {number | BigNumber | Fraction | Complex | Array | Matrix} x
|
70
|
+
* @param {number | BigNumber | Fraction | Complex | Unit | Array | Matrix} x Value to be rounded
|
63
71
|
* @param {number | BigNumber | Array} [n=0] Number of decimals
|
72
|
+
* @param {Unit} [valuelessUnit] A valueless unit
|
64
73
|
* @return {number | BigNumber | Fraction | Complex | Array | Matrix} Rounded value
|
65
74
|
*/
|
66
75
|
return typed(name, {
|
@@ -112,37 +121,51 @@ export var createRound = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
112
121
|
}
|
113
122
|
return x.round(n.toNumber());
|
114
123
|
},
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
124
|
+
'Unit, number, Unit': typed.referToSelf(self => function (x, n, unit) {
|
125
|
+
var valueless = x.toNumeric(unit);
|
126
|
+
return unit.multiply(self(valueless, n));
|
127
|
+
}),
|
128
|
+
'Unit, BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => self(x, n.toNumber(), unit)),
|
129
|
+
'Unit, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),
|
130
|
+
'Array | Matrix, number, Unit': typed.referToSelf(self => (x, n, unit) => {
|
131
|
+
// deep map collection, skip zeros since round(0) = 0
|
132
|
+
return deepMap(x, value => self(value, n, unit), true);
|
133
|
+
}),
|
134
|
+
'Array | Matrix, BigNumber, Unit': typed.referToSelf(self => (x, n, unit) => self(x, n.toNumber(), unit)),
|
135
|
+
'Array | Matrix, Unit': typed.referToSelf(self => (x, unit) => self(x, 0, unit)),
|
136
|
+
'Array | Matrix': typed.referToSelf(self => x => {
|
137
|
+
// deep map collection, skip zeros since round(0) = 0
|
138
|
+
return deepMap(x, self, true);
|
139
|
+
}),
|
140
|
+
'SparseMatrix, number | BigNumber': typed.referToSelf(self => (x, n) => {
|
141
|
+
return matAlgo11xS0s(x, n, self, false);
|
119
142
|
}),
|
120
|
-
'DenseMatrix, number | BigNumber': typed.referToSelf(self => (x,
|
121
|
-
return matAlgo14xDs(x,
|
143
|
+
'DenseMatrix, number | BigNumber': typed.referToSelf(self => (x, n) => {
|
144
|
+
return matAlgo14xDs(x, n, self, false);
|
122
145
|
}),
|
123
|
-
'Array, number | BigNumber': typed.referToSelf(self => (x,
|
146
|
+
'Array, number | BigNumber': typed.referToSelf(self => (x, n) => {
|
124
147
|
// use matrix implementation
|
125
|
-
return matAlgo14xDs(matrix(x),
|
148
|
+
return matAlgo14xDs(matrix(x), n, self, false).valueOf();
|
126
149
|
}),
|
127
|
-
'number | Complex | BigNumber | Fraction, SparseMatrix': typed.referToSelf(self => (x,
|
150
|
+
'number | Complex | BigNumber | Fraction, SparseMatrix': typed.referToSelf(self => (x, n) => {
|
128
151
|
// check scalar is zero
|
129
152
|
if (equalScalar(x, 0)) {
|
130
153
|
// do not execute algorithm, result will be a zero matrix
|
131
|
-
return zeros(
|
154
|
+
return zeros(n.size(), n.storage());
|
132
155
|
}
|
133
|
-
return matAlgo12xSfs(
|
156
|
+
return matAlgo12xSfs(n, x, self, true);
|
134
157
|
}),
|
135
|
-
'number | Complex | BigNumber | Fraction, DenseMatrix': typed.referToSelf(self => (x,
|
158
|
+
'number | Complex | BigNumber | Fraction, DenseMatrix': typed.referToSelf(self => (x, n) => {
|
136
159
|
// check scalar is zero
|
137
160
|
if (equalScalar(x, 0)) {
|
138
161
|
// do not execute algorithm, result will be a zero matrix
|
139
|
-
return zeros(
|
162
|
+
return zeros(n.size(), n.storage());
|
140
163
|
}
|
141
|
-
return matAlgo14xDs(
|
164
|
+
return matAlgo14xDs(n, x, self, true);
|
142
165
|
}),
|
143
|
-
'number | Complex | BigNumber | Fraction, Array': typed.referToSelf(self => (x,
|
166
|
+
'number | Complex | BigNumber | Fraction, Array': typed.referToSelf(self => (x, n) => {
|
144
167
|
// use matrix implementation
|
145
|
-
return matAlgo14xDs(matrix(
|
168
|
+
return matAlgo14xDs(matrix(n), x, self, true).valueOf();
|
146
169
|
})
|
147
170
|
});
|
148
171
|
});
|