mathjs 11.3.2 → 11.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/HISTORY.md +25 -0
- 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/dependenciesLyap.generated.js +26 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesPolynomialRoot.generated.js +42 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSchur.generated.js +30 -0
- package/lib/cjs/entry/dependenciesAny/dependenciesSylvester.generated.js +46 -0
- package/lib/cjs/entry/dependenciesAny.generated.js +28 -0
- package/lib/cjs/entry/impureFunctionsAny.generated.js +21 -17
- package/lib/cjs/entry/pureFunctionsAny.generated.js +100 -48
- package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -0
- package/lib/cjs/expression/embeddedDocs/function/algebra/polynomialRoot.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/arithmetic/sqrtm.js +1 -1
- package/lib/cjs/expression/embeddedDocs/function/matrix/lyap.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/schur.js +15 -0
- package/lib/cjs/expression/embeddedDocs/function/matrix/sylvester.js +15 -0
- package/lib/cjs/factoriesAny.js +28 -0
- package/lib/cjs/function/algebra/decomposition/schur.js +75 -0
- package/lib/cjs/function/algebra/lyap.js +57 -0
- package/lib/cjs/function/algebra/polynomialRoot.js +139 -0
- package/lib/cjs/function/algebra/simplify/wildcards.js +38 -0
- package/lib/cjs/function/algebra/simplify.js +104 -44
- package/lib/cjs/function/algebra/simplifyConstant.js +29 -12
- package/lib/cjs/function/algebra/sylvester.js +127 -0
- package/lib/cjs/function/matrix/forEach.js +1 -1
- package/lib/cjs/function/matrix/sqrtm.js +1 -1
- package/lib/cjs/header.js +2 -2
- package/lib/cjs/type/matrix/SparseMatrix.js +4 -2
- package/lib/cjs/version.js +1 -1
- package/lib/esm/entry/dependenciesAny/dependenciesLyap.generated.js +18 -0
- package/lib/esm/entry/dependenciesAny/dependenciesPolynomialRoot.generated.js +34 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSchur.generated.js +22 -0
- package/lib/esm/entry/dependenciesAny/dependenciesSylvester.generated.js +38 -0
- package/lib/esm/entry/dependenciesAny.generated.js +4 -0
- package/lib/esm/entry/impureFunctionsAny.generated.js +22 -18
- package/lib/esm/entry/pureFunctionsAny.generated.js +87 -39
- package/lib/esm/expression/embeddedDocs/embeddedDocs.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/algebra/polynomialRoot.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/arithmetic/sqrtm.js +1 -1
- package/lib/esm/expression/embeddedDocs/function/matrix/lyap.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/schur.js +8 -0
- package/lib/esm/expression/embeddedDocs/function/matrix/sylvester.js +8 -0
- package/lib/esm/factoriesAny.js +4 -0
- package/lib/esm/function/algebra/decomposition/schur.js +70 -0
- package/lib/esm/function/algebra/lyap.js +52 -0
- package/lib/esm/function/algebra/polynomialRoot.js +122 -0
- package/lib/esm/function/algebra/simplify/wildcards.js +20 -0
- package/lib/esm/function/algebra/simplify.js +105 -45
- package/lib/esm/function/algebra/simplifyConstant.js +29 -12
- package/lib/esm/function/algebra/sylvester.js +118 -0
- package/lib/esm/function/matrix/forEach.js +1 -1
- package/lib/esm/function/matrix/sqrtm.js +1 -1
- package/lib/esm/type/matrix/SparseMatrix.js +4 -2
- package/lib/esm/version.js +1 -1
- package/package.json +13 -13
- package/types/index.d.ts +85 -7
@@ -1,4 +1,5 @@
|
|
1
|
-
import {
|
1
|
+
import { isParenthesisNode } from '../../utils/is.js';
|
2
|
+
import { isConstantNode, isVariableNode, isNumericNode, isConstantExpression } from './simplify/wildcards.js';
|
2
3
|
import { factory } from '../../utils/factory.js';
|
3
4
|
import { createUtil } from './simplify/util.js';
|
4
5
|
import { hasOwnProperty } from '../../utils/object.js';
|
@@ -75,9 +76,15 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
75
76
|
* expression is that variables starting with the following characters are
|
76
77
|
* interpreted as wildcards:
|
77
78
|
*
|
78
|
-
* - 'n' -
|
79
|
-
* - 'c' -
|
80
|
-
* - '
|
79
|
+
* - 'n' - Matches any node [Node]
|
80
|
+
* - 'c' - Matches a constant literal (5 or 3.2) [ConstantNode]
|
81
|
+
* - 'cl' - Matches a constant literal; same as c [ConstantNode]
|
82
|
+
* - 'cd' - Matches a decimal literal (5 or -3.2) [ConstantNode or unaryMinus wrapping a ConstantNode]
|
83
|
+
* - 'ce' - Matches a constant expression (-5 or √3) [Expressions consisting of only ConstantNodes, functions, and operators]
|
84
|
+
* - 'v' - Matches a variable; anything not matched by c (-5 or x) [Node that is not a ConstantNode]
|
85
|
+
* - 'vl' - Matches a variable literal (x or y) [SymbolNode]
|
86
|
+
* - 'vd' - Matches a non-decimal expression; anything not matched by cd (x or √3) [Node that is not a ConstantNode or unaryMinus that is wrapping a ConstantNode]
|
87
|
+
* - 've' - Matches a variable expression; anything not matched by ce (x or 2x) [Expressions that contain a SymbolNode or other non-constant term]
|
81
88
|
*
|
82
89
|
* The default list of rules is exposed on the function as `simplify.rules`
|
83
90
|
* and can be used as a basis to built a set of custom rules. Note that since
|
@@ -250,7 +257,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
250
257
|
}
|
251
258
|
}
|
252
259
|
}, {
|
253
|
-
s: '-(
|
260
|
+
s: '-(cl*v) -> v * (-cl)',
|
254
261
|
// make non-constant terms positive
|
255
262
|
assuming: {
|
256
263
|
multiply: {
|
@@ -261,7 +268,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
261
268
|
}
|
262
269
|
}
|
263
270
|
}, {
|
264
|
-
s: '-(
|
271
|
+
s: '-(cl*v) -> (-cl) * v',
|
265
272
|
// non-commutative version, part 1
|
266
273
|
assuming: {
|
267
274
|
multiply: {
|
@@ -272,7 +279,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
272
279
|
}
|
273
280
|
}
|
274
281
|
}, {
|
275
|
-
s: '-(v*
|
282
|
+
s: '-(v*cl) -> v * (-cl)',
|
276
283
|
// non-commutative version, part 2
|
277
284
|
assuming: {
|
278
285
|
multiply: {
|
@@ -330,24 +337,24 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
330
337
|
},
|
331
338
|
// collect like factors; into a sum, only do this for nonconstants
|
332
339
|
{
|
333
|
-
l: '
|
334
|
-
r: '
|
340
|
+
l: ' vd * ( vd * n1 + n2)',
|
341
|
+
r: 'vd^2 * n1 + vd * n2'
|
335
342
|
}, {
|
336
|
-
s: '
|
343
|
+
s: ' vd * (vd^n4 * n1 + n2) -> vd^(1+n4) * n1 + vd * n2',
|
337
344
|
assuming: {
|
338
345
|
divide: {
|
339
346
|
total: true
|
340
347
|
}
|
341
348
|
} // v*1/v = v^(1+-1) needs 1/v
|
342
349
|
}, {
|
343
|
-
s: '
|
350
|
+
s: 'vd^n3 * ( vd * n1 + n2) -> vd^(n3+1) * n1 + vd^n3 * n2',
|
344
351
|
assuming: {
|
345
352
|
divide: {
|
346
353
|
total: true
|
347
354
|
}
|
348
355
|
}
|
349
356
|
}, {
|
350
|
-
s: '
|
357
|
+
s: 'vd^n3 * (vd^n4 * n1 + n2) -> vd^(n3+n4) * n1 + vd^n3 * n2',
|
351
358
|
assuming: {
|
352
359
|
divide: {
|
353
360
|
total: true
|
@@ -390,8 +397,8 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
390
397
|
l: 'n+-n',
|
391
398
|
r: '0'
|
392
399
|
}, {
|
393
|
-
l: '
|
394
|
-
r: '
|
400
|
+
l: 'vd*n + vd',
|
401
|
+
r: 'vd*(n+1)'
|
395
402
|
},
|
396
403
|
// NOTE: leftmost position is special:
|
397
404
|
{
|
@@ -406,7 +413,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
406
413
|
l: 'n3^(-n4)*n1 + n3^n5 * n2',
|
407
414
|
r: 'n3^(-n4)*(n1 + n3^(n4+n5)*n2)'
|
408
415
|
}, {
|
409
|
-
s: 'n*
|
416
|
+
s: 'n*vd + vd -> (n+1)*vd',
|
410
417
|
// noncommutative additional cases
|
411
418
|
assuming: {
|
412
419
|
multiply: {
|
@@ -435,10 +442,10 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
435
442
|
}
|
436
443
|
}
|
437
444
|
}, {
|
438
|
-
l: 'n*
|
439
|
-
r: '(n+1)*
|
445
|
+
l: 'n*cd + cd',
|
446
|
+
r: '(n+1)*cd'
|
440
447
|
}, {
|
441
|
-
s: '
|
448
|
+
s: 'cd*n + cd -> cd*(n+1)',
|
442
449
|
assuming: {
|
443
450
|
multiply: {
|
444
451
|
commutative: false
|
@@ -469,7 +476,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
469
476
|
},
|
470
477
|
// final ordering of constants
|
471
478
|
{
|
472
|
-
s: '
|
479
|
+
s: 'ce+ve -> ve+ce',
|
473
480
|
assuming: {
|
474
481
|
add: {
|
475
482
|
commutative: true
|
@@ -481,7 +488,7 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
481
488
|
}
|
482
489
|
}
|
483
490
|
}, {
|
484
|
-
s: '
|
491
|
+
s: 'vd*cd -> cd*vd',
|
485
492
|
assuming: {
|
486
493
|
multiply: {
|
487
494
|
commutative: true
|
@@ -1047,9 +1054,8 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1047
1054
|
}
|
1048
1055
|
} else if (rule instanceof SymbolNode) {
|
1049
1056
|
// If the rule is a SymbolNode, then it carries a special meaning
|
1050
|
-
// according to the first
|
1051
|
-
//
|
1052
|
-
// n.* matches any node
|
1057
|
+
// according to the first one or two characters of the symbol node name.
|
1058
|
+
// These meanings are expalined in the documentation for simplify()
|
1053
1059
|
if (rule.name.length === 0) {
|
1054
1060
|
throw new Error('Symbol in rule has 0 length...!?');
|
1055
1061
|
}
|
@@ -1058,29 +1064,83 @@ export var createSimplify = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
1058
1064
|
if (rule.name !== node.name) {
|
1059
1065
|
return [];
|
1060
1066
|
}
|
1061
|
-
} else if (rule.name[0] === 'n' || rule.name.substring(0, 2) === '_p') {
|
1062
|
-
// rule matches _anything_, so assign this node to the rule.name placeholder
|
1063
|
-
// Assign node to the rule.name placeholder.
|
1064
|
-
// Our parent will check for matches among placeholders.
|
1065
|
-
res[0].placeholders[rule.name] = node;
|
1066
|
-
} else if (rule.name[0] === 'v') {
|
1067
|
-
// rule matches any variable thing (not a ConstantNode)
|
1068
|
-
if (!isConstantNode(node)) {
|
1069
|
-
res[0].placeholders[rule.name] = node;
|
1070
|
-
} else {
|
1071
|
-
// Mis-match: rule was expecting something other than a ConstantNode
|
1072
|
-
return [];
|
1073
|
-
}
|
1074
|
-
} else if (rule.name[0] === 'c') {
|
1075
|
-
// rule matches any ConstantNode
|
1076
|
-
if (node instanceof ConstantNode) {
|
1077
|
-
res[0].placeholders[rule.name] = node;
|
1078
|
-
} else {
|
1079
|
-
// Mis-match: rule was expecting a ConstantNode
|
1080
|
-
return [];
|
1081
|
-
}
|
1082
1067
|
} else {
|
1083
|
-
|
1068
|
+
// wildcards are composed of up to two alphabetic or underscore characters
|
1069
|
+
switch (rule.name[1] >= 'a' && rule.name[1] <= 'z' ? rule.name.substring(0, 2) : rule.name[0]) {
|
1070
|
+
case 'n':
|
1071
|
+
case '_p':
|
1072
|
+
// rule matches _anything_, so assign this node to the rule.name placeholder
|
1073
|
+
// Assign node to the rule.name placeholder.
|
1074
|
+
// Our parent will check for matches among placeholders.
|
1075
|
+
res[0].placeholders[rule.name] = node;
|
1076
|
+
break;
|
1077
|
+
case 'c':
|
1078
|
+
case 'cl':
|
1079
|
+
// rule matches a ConstantNode
|
1080
|
+
if (isConstantNode(node)) {
|
1081
|
+
res[0].placeholders[rule.name] = node;
|
1082
|
+
} else {
|
1083
|
+
// mis-match: rule does not encompass current node
|
1084
|
+
return [];
|
1085
|
+
}
|
1086
|
+
break;
|
1087
|
+
case 'v':
|
1088
|
+
// rule matches anything other than a ConstantNode
|
1089
|
+
if (!isConstantNode(node)) {
|
1090
|
+
res[0].placeholders[rule.name] = node;
|
1091
|
+
} else {
|
1092
|
+
// mis-match: rule does not encompass current node
|
1093
|
+
return [];
|
1094
|
+
}
|
1095
|
+
break;
|
1096
|
+
case 'vl':
|
1097
|
+
// rule matches VariableNode
|
1098
|
+
if (isVariableNode(node)) {
|
1099
|
+
res[0].placeholders[rule.name] = node;
|
1100
|
+
} else {
|
1101
|
+
// mis-match: rule does not encompass current node
|
1102
|
+
return [];
|
1103
|
+
}
|
1104
|
+
break;
|
1105
|
+
case 'cd':
|
1106
|
+
// rule matches a ConstantNode or unaryMinus-wrapped ConstantNode
|
1107
|
+
if (isNumericNode(node)) {
|
1108
|
+
res[0].placeholders[rule.name] = node;
|
1109
|
+
} else {
|
1110
|
+
// mis-match: rule does not encompass current node
|
1111
|
+
return [];
|
1112
|
+
}
|
1113
|
+
break;
|
1114
|
+
case 'vd':
|
1115
|
+
// rule matches anything other than a ConstantNode or unaryMinus-wrapped ConstantNode
|
1116
|
+
if (!isNumericNode(node)) {
|
1117
|
+
res[0].placeholders[rule.name] = node;
|
1118
|
+
} else {
|
1119
|
+
// mis-match: rule does not encompass current node
|
1120
|
+
return [];
|
1121
|
+
}
|
1122
|
+
break;
|
1123
|
+
case 'ce':
|
1124
|
+
// rule matches expressions that have a constant value
|
1125
|
+
if (isConstantExpression(node)) {
|
1126
|
+
res[0].placeholders[rule.name] = node;
|
1127
|
+
} else {
|
1128
|
+
// mis-match: rule does not encompass current node
|
1129
|
+
return [];
|
1130
|
+
}
|
1131
|
+
break;
|
1132
|
+
case 've':
|
1133
|
+
// rule matches expressions that do not have a constant value
|
1134
|
+
if (!isConstantExpression(node)) {
|
1135
|
+
res[0].placeholders[rule.name] = node;
|
1136
|
+
} else {
|
1137
|
+
// mis-match: rule does not encompass current node
|
1138
|
+
return [];
|
1139
|
+
}
|
1140
|
+
break;
|
1141
|
+
default:
|
1142
|
+
throw new Error('Invalid symbol in rule: ' + rule.name);
|
1143
|
+
}
|
1084
1144
|
}
|
1085
1145
|
} else if (rule instanceof ConstantNode) {
|
1086
1146
|
// Literal constant must match exactly
|
@@ -286,20 +286,37 @@ export var createSimplifyConstant = /* #__PURE__ */factory(name, dependencies, _
|
|
286
286
|
* @return - Either a Node representing a binary expression or Fraction
|
287
287
|
*/
|
288
288
|
function foldOp(fn, args, makeNode, options) {
|
289
|
-
|
290
|
-
|
289
|
+
var first = args.shift();
|
290
|
+
|
291
|
+
// In the following reduction, sofar always has one of the three following
|
292
|
+
// forms: [NODE], [CONSTANT], or [NODE, CONSTANT]
|
293
|
+
var reduction = args.reduce((sofar, next) => {
|
294
|
+
if (!isNode(next)) {
|
295
|
+
var last = sofar.pop();
|
296
|
+
if (isNode(last)) {
|
297
|
+
return [last, next];
|
298
|
+
}
|
299
|
+
// Two constants in a row, try to fold them into one
|
291
300
|
try {
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
} else if (!isNode(b)) {
|
299
|
-
b = _toNode(b);
|
301
|
+
sofar.push(_eval(fn, [last, next], options));
|
302
|
+
return sofar;
|
303
|
+
} catch (ignoreandcontinue) {
|
304
|
+
sofar.push(last);
|
305
|
+
// fall through to Node case
|
306
|
+
}
|
300
307
|
}
|
301
|
-
|
302
|
-
|
308
|
+
|
309
|
+
// Encountered a Node, or failed folding --
|
310
|
+
// collapse everything so far into a single tree:
|
311
|
+
sofar.push(_ensureNode(sofar.pop()));
|
312
|
+
var newtree = sofar.length === 1 ? sofar[0] : makeNode(sofar);
|
313
|
+
return [makeNode([newtree, _ensureNode(next)])];
|
314
|
+
}, [first]);
|
315
|
+
if (reduction.length === 1) {
|
316
|
+
return reduction[0];
|
317
|
+
}
|
318
|
+
// Might end up with a tree and a constant at the end:
|
319
|
+
return makeNode([reduction[0], _toNode(reduction[1])]);
|
303
320
|
}
|
304
321
|
|
305
322
|
// destroys the original node and returns a folded one
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import { factory } from '../../utils/factory.js';
|
2
|
+
var name = 'sylvester';
|
3
|
+
var dependencies = ['typed', 'schur', 'matrixFromColumns', 'matrix', 'multiply', 'range', 'concat', 'transpose', 'index', 'subset', 'add', 'subtract', 'identity', 'lusolve', 'abs'];
|
4
|
+
export var createSylvester = /* #__PURE__ */factory(name, dependencies, _ref => {
|
5
|
+
var {
|
6
|
+
typed,
|
7
|
+
schur,
|
8
|
+
matrixFromColumns,
|
9
|
+
matrix,
|
10
|
+
multiply,
|
11
|
+
range,
|
12
|
+
concat,
|
13
|
+
transpose,
|
14
|
+
index,
|
15
|
+
subset,
|
16
|
+
add,
|
17
|
+
subtract,
|
18
|
+
identity,
|
19
|
+
lusolve,
|
20
|
+
abs
|
21
|
+
} = _ref;
|
22
|
+
/**
|
23
|
+
*
|
24
|
+
* Solves the real-valued Sylvester equation AX+XB=C for X, where A, B and C are
|
25
|
+
* matrices of appropriate dimensions, being A and B squared. Notice that other
|
26
|
+
* equivalent definitions for the Sylvester equation exist and this function
|
27
|
+
* assumes the one presented in the original publication of the the Bartels-
|
28
|
+
* Stewart algorithm, which is implemented by this function.
|
29
|
+
* https://en.wikipedia.org/wiki/Sylvester_equation
|
30
|
+
*
|
31
|
+
* Syntax:
|
32
|
+
*
|
33
|
+
* math.sylvester(A, B, C)
|
34
|
+
*
|
35
|
+
* Examples:
|
36
|
+
*
|
37
|
+
* const A = [[-1, -2], [1, 1]]
|
38
|
+
* const B = [[2, -1], [1, -2]]
|
39
|
+
* const C = [[-3, 2], [3, 0]]
|
40
|
+
* math.sylvester(A, B, C) // returns DenseMatrix [[-0.25, 0.25], [1.5, -1.25]]
|
41
|
+
*
|
42
|
+
* See also:
|
43
|
+
*
|
44
|
+
* schur, lyap
|
45
|
+
*
|
46
|
+
* @param {Matrix | Array} A Matrix A
|
47
|
+
* @param {Matrix | Array} B Matrix B
|
48
|
+
* @param {Matrix | Array} C Matrix C
|
49
|
+
* @return {Matrix | Array} Matrix X, solving the Sylvester equation
|
50
|
+
*/
|
51
|
+
return typed(name, {
|
52
|
+
'Matrix, Matrix, Matrix': _sylvester,
|
53
|
+
'Array, Matrix, Matrix': function ArrayMatrixMatrix(A, B, C) {
|
54
|
+
return _sylvester(matrix(A), B, C);
|
55
|
+
},
|
56
|
+
'Array, Array, Matrix': function ArrayArrayMatrix(A, B, C) {
|
57
|
+
return _sylvester(matrix(A), matrix(B), C);
|
58
|
+
},
|
59
|
+
'Array, Matrix, Array': function ArrayMatrixArray(A, B, C) {
|
60
|
+
return _sylvester(matrix(A), B, matrix(C));
|
61
|
+
},
|
62
|
+
'Matrix, Array, Matrix': function MatrixArrayMatrix(A, B, C) {
|
63
|
+
return _sylvester(A, matrix(B), C);
|
64
|
+
},
|
65
|
+
'Matrix, Array, Array': function MatrixArrayArray(A, B, C) {
|
66
|
+
return _sylvester(A, matrix(B), matrix(C));
|
67
|
+
},
|
68
|
+
'Matrix, Matrix, Array': function MatrixMatrixArray(A, B, C) {
|
69
|
+
return _sylvester(A, B, matrix(C));
|
70
|
+
},
|
71
|
+
'Array, Array, Array': function ArrayArrayArray(A, B, C) {
|
72
|
+
return _sylvester(matrix(A), matrix(B), matrix(C)).toArray();
|
73
|
+
}
|
74
|
+
});
|
75
|
+
function _sylvester(A, B, C) {
|
76
|
+
var n = B.size()[0];
|
77
|
+
var m = A.size()[0];
|
78
|
+
var sA = schur(A);
|
79
|
+
var F = sA.T;
|
80
|
+
var U = sA.U;
|
81
|
+
var sB = schur(multiply(-1, B));
|
82
|
+
var G = sB.T;
|
83
|
+
var V = sB.U;
|
84
|
+
var D = multiply(multiply(transpose(U), C), V);
|
85
|
+
var all = range(0, m);
|
86
|
+
var y = [];
|
87
|
+
var hc = (a, b) => concat(a, b, 1);
|
88
|
+
var vc = (a, b) => concat(a, b, 0);
|
89
|
+
for (var k = 0; k < n; k++) {
|
90
|
+
if (k < n - 1 && abs(subset(G, index(k + 1, k))) > 1e-5) {
|
91
|
+
var RHS = vc(subset(D, index(all, k)), subset(D, index(all, k + 1)));
|
92
|
+
for (var j = 0; j < k; j++) {
|
93
|
+
RHS = add(RHS, vc(multiply(y[j], subset(G, index(j, k))), multiply(y[j], subset(G, index(j, k + 1)))));
|
94
|
+
}
|
95
|
+
var gkk = multiply(identity(m), multiply(-1, subset(G, index(k, k))));
|
96
|
+
var gmk = multiply(identity(m), multiply(-1, subset(G, index(k + 1, k))));
|
97
|
+
var gkm = multiply(identity(m), multiply(-1, subset(G, index(k, k + 1))));
|
98
|
+
var gmm = multiply(identity(m), multiply(-1, subset(G, index(k + 1, k + 1))));
|
99
|
+
var LHS = vc(hc(add(F, gkk), gmk), hc(gkm, add(F, gmm)));
|
100
|
+
var yAux = lusolve(LHS, RHS);
|
101
|
+
y[k] = yAux.subset(index(range(0, m), 0));
|
102
|
+
y[k + 1] = yAux.subset(index(range(m, 2 * m), 0));
|
103
|
+
k++;
|
104
|
+
} else {
|
105
|
+
var _RHS = subset(D, index(all, k));
|
106
|
+
for (var _j = 0; _j < k; _j++) {
|
107
|
+
_RHS = add(_RHS, multiply(y[_j], subset(G, index(_j, k))));
|
108
|
+
}
|
109
|
+
var _gkk = subset(G, index(k, k));
|
110
|
+
var _LHS = subtract(F, multiply(_gkk, identity(m)));
|
111
|
+
y[k] = lusolve(_LHS, _RHS);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
var Y = matrix(matrixFromColumns(...y));
|
115
|
+
var X = multiply(U, multiply(Y, transpose(V)));
|
116
|
+
return X;
|
117
|
+
}
|
118
|
+
});
|
@@ -33,7 +33,7 @@ export var createForEach = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
33
33
|
return typed(name, {
|
34
34
|
'Array, function': _forEach,
|
35
35
|
'Matrix, function': function MatrixFunction(x, callback) {
|
36
|
-
|
36
|
+
x.forEach(callback);
|
37
37
|
}
|
38
38
|
});
|
39
39
|
});
|
@@ -59,7 +59,7 @@ export var createSqrtm = /* #__PURE__ */factory(name, dependencies, _ref => {
|
|
59
59
|
*
|
60
60
|
* Examples:
|
61
61
|
*
|
62
|
-
* math.sqrtm([[
|
62
|
+
* math.sqrtm([[33, 24], [48, 57]]) // returns [[5, 2], [4, 7]]
|
63
63
|
*
|
64
64
|
* See also:
|
65
65
|
*
|
@@ -526,8 +526,10 @@ export var createSparseMatrixClass = /* #__PURE__ */factory(name, dependencies,
|
|
526
526
|
_remove(k, j, this._values, this._index, this._ptr);
|
527
527
|
}
|
528
528
|
} else {
|
529
|
-
|
530
|
-
|
529
|
+
if (!eq(v, zero)) {
|
530
|
+
// insert value @ (i, j)
|
531
|
+
_insert(k, i, j, v, this._values, this._index, this._ptr);
|
532
|
+
}
|
531
533
|
}
|
532
534
|
return this;
|
533
535
|
};
|
package/lib/esm/version.js
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mathjs",
|
3
|
-
"version": "11.
|
3
|
+
"version": "11.4.0",
|
4
4
|
"description": "Math.js is an extensive math library for JavaScript and Node.js. It features a flexible expression parser with support for symbolic computation, comes with 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, fractions, units, and matrices.",
|
5
5
|
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
|
6
6
|
"homepage": "https://mathjs.org",
|
@@ -25,7 +25,7 @@
|
|
25
25
|
"unit"
|
26
26
|
],
|
27
27
|
"dependencies": {
|
28
|
-
"@babel/runtime": "^7.
|
28
|
+
"@babel/runtime": "^7.20.1",
|
29
29
|
"complex.js": "^2.1.1",
|
30
30
|
"decimal.js": "^10.4.2",
|
31
31
|
"escape-latex": "^1.2.0",
|
@@ -36,28 +36,28 @@
|
|
36
36
|
"typed-function": "^4.1.0"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@babel/core": "7.
|
39
|
+
"@babel/core": "7.20.2",
|
40
40
|
"@babel/plugin-transform-object-assign": "7.18.6",
|
41
41
|
"@babel/plugin-transform-runtime": "7.19.6",
|
42
|
-
"@babel/preset-env": "7.
|
42
|
+
"@babel/preset-env": "7.20.2",
|
43
43
|
"@babel/register": "7.18.9",
|
44
44
|
"@types/assert": "1.5.6",
|
45
45
|
"@types/mocha": "10.0.0",
|
46
|
-
"@typescript-eslint/eslint-plugin": "5.
|
47
|
-
"@typescript-eslint/parser": "5.
|
46
|
+
"@typescript-eslint/eslint-plugin": "5.43.0",
|
47
|
+
"@typescript-eslint/parser": "5.43.0",
|
48
48
|
"assert": "2.0.0",
|
49
|
-
"babel-loader": "
|
49
|
+
"babel-loader": "9.1.0",
|
50
50
|
"benchmark": "2.1.4",
|
51
51
|
"codecov": "3.8.3",
|
52
|
-
"core-js": "3.26.
|
52
|
+
"core-js": "3.26.1",
|
53
53
|
"del": "6.1.1",
|
54
54
|
"dtslint": "4.2.1",
|
55
|
-
"eslint": "8.
|
55
|
+
"eslint": "8.27.0",
|
56
56
|
"eslint-config-prettier": "8.5.0",
|
57
57
|
"eslint-config-standard": "17.0.0",
|
58
58
|
"eslint-plugin-import": "2.26.0",
|
59
59
|
"eslint-plugin-mocha": "10.1.0",
|
60
|
-
"eslint-plugin-n": "15.
|
60
|
+
"eslint-plugin-n": "15.5.1",
|
61
61
|
"eslint-plugin-prettier": "4.2.1",
|
62
62
|
"eslint-plugin-promise": "6.1.1",
|
63
63
|
"expect-type": "0.15.0",
|
@@ -78,7 +78,7 @@
|
|
78
78
|
"math-expression-evaluator": "1.4.0",
|
79
79
|
"mkdirp": "1.0.4",
|
80
80
|
"mocha": "10.1.0",
|
81
|
-
"mocha-junit-reporter": "2.
|
81
|
+
"mocha-junit-reporter": "2.2.0",
|
82
82
|
"ndarray": "1.0.19",
|
83
83
|
"ndarray-determinant": "1.0.0",
|
84
84
|
"ndarray-gemm": "1.0.0",
|
@@ -91,8 +91,8 @@
|
|
91
91
|
"process": "0.11.10",
|
92
92
|
"sylvester": "0.0.21",
|
93
93
|
"ts-node": "10.9.1",
|
94
|
-
"typescript": "4.
|
95
|
-
"webpack": "5.
|
94
|
+
"typescript": "4.9.3",
|
95
|
+
"webpack": "5.75.0",
|
96
96
|
"zeros": "1.0.0"
|
97
97
|
},
|
98
98
|
"type": "module",
|