mathjs 11.3.3 → 11.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. package/HISTORY.md +14 -0
  2. package/lib/browser/math.js +1 -1
  3. package/lib/browser/math.js.LICENSE.txt +2 -2
  4. package/lib/browser/math.js.map +1 -1
  5. package/lib/cjs/entry/dependenciesAny/dependenciesLyap.generated.js +26 -0
  6. package/lib/cjs/entry/dependenciesAny/dependenciesPolynomialRoot.generated.js +42 -0
  7. package/lib/cjs/entry/dependenciesAny/dependenciesSchur.generated.js +30 -0
  8. package/lib/cjs/entry/dependenciesAny/dependenciesSylvester.generated.js +46 -0
  9. package/lib/cjs/entry/dependenciesAny.generated.js +28 -0
  10. package/lib/cjs/entry/impureFunctionsAny.generated.js +21 -17
  11. package/lib/cjs/entry/pureFunctionsAny.generated.js +100 -48
  12. package/lib/cjs/expression/embeddedDocs/embeddedDocs.js +8 -0
  13. package/lib/cjs/expression/embeddedDocs/function/algebra/polynomialRoot.js +15 -0
  14. package/lib/cjs/expression/embeddedDocs/function/matrix/lyap.js +15 -0
  15. package/lib/cjs/expression/embeddedDocs/function/matrix/schur.js +15 -0
  16. package/lib/cjs/expression/embeddedDocs/function/matrix/sylvester.js +15 -0
  17. package/lib/cjs/factoriesAny.js +28 -0
  18. package/lib/cjs/function/algebra/decomposition/schur.js +75 -0
  19. package/lib/cjs/function/algebra/lyap.js +57 -0
  20. package/lib/cjs/function/algebra/polynomialRoot.js +139 -0
  21. package/lib/cjs/function/algebra/simplify/wildcards.js +38 -0
  22. package/lib/cjs/function/algebra/simplify.js +104 -44
  23. package/lib/cjs/function/algebra/simplifyConstant.js +29 -12
  24. package/lib/cjs/function/algebra/sylvester.js +127 -0
  25. package/lib/cjs/function/matrix/forEach.js +1 -1
  26. package/lib/cjs/header.js +2 -2
  27. package/lib/cjs/version.js +1 -1
  28. package/lib/esm/entry/dependenciesAny/dependenciesLyap.generated.js +18 -0
  29. package/lib/esm/entry/dependenciesAny/dependenciesPolynomialRoot.generated.js +34 -0
  30. package/lib/esm/entry/dependenciesAny/dependenciesSchur.generated.js +22 -0
  31. package/lib/esm/entry/dependenciesAny/dependenciesSylvester.generated.js +38 -0
  32. package/lib/esm/entry/dependenciesAny.generated.js +4 -0
  33. package/lib/esm/entry/impureFunctionsAny.generated.js +22 -18
  34. package/lib/esm/entry/pureFunctionsAny.generated.js +87 -39
  35. package/lib/esm/expression/embeddedDocs/embeddedDocs.js +8 -0
  36. package/lib/esm/expression/embeddedDocs/function/algebra/polynomialRoot.js +8 -0
  37. package/lib/esm/expression/embeddedDocs/function/matrix/lyap.js +8 -0
  38. package/lib/esm/expression/embeddedDocs/function/matrix/schur.js +8 -0
  39. package/lib/esm/expression/embeddedDocs/function/matrix/sylvester.js +8 -0
  40. package/lib/esm/factoriesAny.js +4 -0
  41. package/lib/esm/function/algebra/decomposition/schur.js +70 -0
  42. package/lib/esm/function/algebra/lyap.js +52 -0
  43. package/lib/esm/function/algebra/polynomialRoot.js +122 -0
  44. package/lib/esm/function/algebra/simplify/wildcards.js +20 -0
  45. package/lib/esm/function/algebra/simplify.js +105 -45
  46. package/lib/esm/function/algebra/simplifyConstant.js +29 -12
  47. package/lib/esm/function/algebra/sylvester.js +118 -0
  48. package/lib/esm/function/matrix/forEach.js +1 -1
  49. package/lib/esm/version.js +1 -1
  50. package/package.json +8 -8
  51. package/types/index.d.ts +83 -5
@@ -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
- return x.forEach(callback);
36
+ x.forEach(callback);
37
37
  }
38
38
  });
39
39
  });
@@ -1,3 +1,3 @@
1
- export var version = '11.3.3';
1
+ export var version = '11.4.0';
2
2
  // Note: This file is automatically generated when building math.js.
3
3
  // Changes made in this file will be overwritten.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mathjs",
3
- "version": "11.3.3",
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",
@@ -43,13 +43,13 @@
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.42.0",
47
- "@typescript-eslint/parser": "5.42.0",
46
+ "@typescript-eslint/eslint-plugin": "5.43.0",
47
+ "@typescript-eslint/parser": "5.43.0",
48
48
  "assert": "2.0.0",
49
49
  "babel-loader": "9.1.0",
50
50
  "benchmark": "2.1.4",
51
51
  "codecov": "3.8.3",
52
- "core-js": "3.26.0",
52
+ "core-js": "3.26.1",
53
53
  "del": "6.1.1",
54
54
  "dtslint": "4.2.1",
55
55
  "eslint": "8.27.0",
@@ -57,7 +57,7 @@
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.5.0",
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.1.1",
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.8.4",
95
- "webpack": "5.74.0",
94
+ "typescript": "4.9.3",
95
+ "webpack": "5.75.0",
96
96
  "zeros": "1.0.0"
97
97
  },
98
98
  "type": "module",
package/types/index.d.ts CHANGED
@@ -465,6 +465,11 @@ declare namespace math {
465
465
  R: MathCollection
466
466
  }
467
467
 
468
+ interface SchurDecomposition {
469
+ U: MathCollection
470
+ T: MathCollection
471
+ }
472
+
468
473
  interface FractionDefinition {
469
474
  a: number
470
475
  b: number
@@ -894,6 +899,22 @@ declare namespace math {
894
899
  threshold?: number
895
900
  ): MathArray
896
901
 
902
+ /* Finds the roots of a polynomial of degree three or less. Coefficients are given constant first
903
+ * followed by linear and higher powers in order; coefficients beyond the degree of the polynomial
904
+ * need not be specified.
905
+ * @param {number|Complex} constantCoeff
906
+ * @param {number|Complex} linearCoeff
907
+ * @param {number|Complex} quadraticCoeff
908
+ * @param {number|Complex} cubicCoeff
909
+ * @returns {Array<number|Complex>} array of roots of specified polynomial
910
+ */
911
+ polynomialRoot(
912
+ constantCoeff: number | Complex,
913
+ linearCoeff: number | Complex,
914
+ quadraticCoeff?: number | Complex,
915
+ cubicCoeff?: number | Complex
916
+ ): (number | Complex)[]
917
+
897
918
  /**
898
919
  * Calculate the Matrix QR decomposition. Matrix A is decomposed in two
899
920
  * matrices (Q, R) where Q is an orthogonal matrix and R is an upper
@@ -1807,6 +1828,41 @@ declare namespace math {
1807
1828
  */
1808
1829
  expm(x: Matrix): Matrix
1809
1830
 
1831
+ /**
1832
+ * Solves the real-valued Sylvester equation AX-XB=C for X, where A, B and C are
1833
+ * matrices of appropriate dimensions, being A and B squared. The method used is
1834
+ * the Bartels-Stewart algorithm.
1835
+ * https://en.wikipedia.org/wiki/Sylvester_equation
1836
+ * @param A Matrix A
1837
+ * @param B Matrix B
1838
+ * @param C Matrix C
1839
+ * @returns Matrix X, solving the Sylvester equation
1840
+ */
1841
+ sylvester(
1842
+ A: Matrix | MathArray,
1843
+ B: Matrix | MathArray,
1844
+ C: Matrix | MathArray
1845
+ ): Matrix | MathArray
1846
+
1847
+ /**
1848
+ * Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal
1849
+ * and T is upper quasi-triangular.
1850
+ * https://en.wikipedia.org/wiki/Schur_decomposition
1851
+ * @param A Matrix A
1852
+ * @returns Object containing both matrix U and T of the Schur Decomposition A=UTU'
1853
+ */
1854
+ schur(A: Matrix | MathArray): SchurDecomposition
1855
+
1856
+ /**
1857
+ * Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite
1858
+ * matrix.
1859
+ * https://en.wikipedia.org/wiki/Lyapunov_equation
1860
+ * @param A Matrix A
1861
+ * @param Q Matrix Q
1862
+ * @returns Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
1863
+ */
1864
+ lyap(A: Matrix | MathArray, Q: Matrix | MathArray): Matrix | MathArray
1865
+
1810
1866
  /**
1811
1867
  * Create a 2-dimensional identity matrix with size m x n or n x n. The
1812
1868
  * matrix has ones on the diagonal and zeros elsewhere.
@@ -3572,6 +3628,9 @@ declare namespace math {
3572
3628
  invDependencies: FactoryFunctionMap
3573
3629
  expmDependencies: FactoryFunctionMap
3574
3630
  sqrtmDependencies: FactoryFunctionMap
3631
+ sylvesterDependencies: FactoryFunctionMap
3632
+ schurDependencies: FactoryFunctionMap
3633
+ lyapDependencies: FactoryFunctionMap
3575
3634
  divideDependencies: FactoryFunctionMap
3576
3635
  distanceDependencies: FactoryFunctionMap
3577
3636
  intersectDependencies: FactoryFunctionMap
@@ -3977,8 +4036,8 @@ declare namespace math {
3977
4036
  */
3978
4037
  forEach(
3979
4038
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3980
- callback: (node: MathNode, path: string, parent: MathNode) => any
3981
- ): MathNode[]
4039
+ callback: (node: MathNode, path: string, parent: MathNode) => void
4040
+ ): void
3982
4041
 
3983
4042
  /**
3984
4043
  * Transform a node. Creates a new MathNode having it’s child's be the
@@ -4071,8 +4130,7 @@ declare namespace math {
4071
4130
  */
4072
4131
  traverse(
4073
4132
  callback: (node: MathNode, path: string, parent: MathNode) => void
4074
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4075
- ): any
4133
+ ): void
4076
4134
  }
4077
4135
 
4078
4136
  interface Parser {
@@ -5273,6 +5331,26 @@ declare namespace math {
5273
5331
 
5274
5332
  expm(this: MathJsChain<Matrix>): MathJsChain<Matrix>
5275
5333
 
5334
+ /**
5335
+ * Performs a real Schur decomposition of the real matrix A = UTU' where U is orthogonal
5336
+ * and T is upper quasi-triangular.
5337
+ * https://en.wikipedia.org/wiki/Schur_decomposition
5338
+ * @returns Object containing both matrix U and T of the Schur Decomposition A=UTU'
5339
+ */
5340
+ schur(this: MathJsChain<Matrix | MathArray>): SchurDecomposition
5341
+
5342
+ /**
5343
+ * Solves the Continuous-time Lyapunov equation AP+PA'=Q for P, where Q is a positive semidefinite
5344
+ * matrix.
5345
+ * https://en.wikipedia.org/wiki/Lyapunov_equation
5346
+ * @param Q Matrix Q
5347
+ * @returns Matrix P solution to the Continuous-time Lyapunov equation AP+PA'=Q
5348
+ */
5349
+ lyap(
5350
+ this: MathJsChain<Matrix | MathArray>,
5351
+ Q: Matrix | MathArray
5352
+ ): MathJsChain<Matrix | MathArray>
5353
+
5276
5354
  /**
5277
5355
  * Create a 2-dimensional identity matrix with size m x n or n x n. The
5278
5356
  * matrix has ones on the diagonal and zeros elsewhere.
@@ -5323,7 +5401,7 @@ declare namespace math {
5323
5401
  this: MathJsChain<T>,
5324
5402
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
5325
5403
  callback: (value: any, index: any, matrix: T) => void
5326
- ): MathJsChain<T>
5404
+ ): void
5327
5405
 
5328
5406
  /**
5329
5407
  * Calculate the inverse of a square matrix.