@danielsimonjr/mathts-matrix 0.4.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +17 -1
- package/dist/index.js +38 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1986,8 +1986,24 @@ interface EigResult {
|
|
|
1986
1986
|
re: number;
|
|
1987
1987
|
im: number;
|
|
1988
1988
|
}>;
|
|
1989
|
-
/**
|
|
1989
|
+
/**
|
|
1990
|
+
* Eigenvectors as columns (each column is an eigenvector). For a real
|
|
1991
|
+
* eigenvalue this is the full (real) eigenvector, unit-normalised. For a
|
|
1992
|
+
* complex-conjugate eigenvalue pair this holds the REAL PART of the
|
|
1993
|
+
* corresponding complex eigenvector — see {@link vectorsIm} for the
|
|
1994
|
+
* imaginary part.
|
|
1995
|
+
*/
|
|
1990
1996
|
vectors: number[][];
|
|
1997
|
+
/**
|
|
1998
|
+
* Imaginary parts of the eigenvector columns (same shape as {@link vectors}).
|
|
1999
|
+
* All-zero for real eigenvalues. For a complex-conjugate eigenvalue pair at
|
|
2000
|
+
* indices `j`/`j+1`, the full complex eigenvectors are
|
|
2001
|
+
* `vectors[j] + i*vectorsIm[j]` (for `values[j]`) and
|
|
2002
|
+
* `vectors[j+1] - i*vectorsIm[j] === vectors[j+1] + i*vectorsIm[j+1]` (for
|
|
2003
|
+
* the conjugate `values[j+1]`), each unit-normalised by the complex 2-norm
|
|
2004
|
+
* `sqrt(sum(re_i^2 + im_i^2))`.
|
|
2005
|
+
*/
|
|
2006
|
+
vectorsIm: number[][];
|
|
1991
2007
|
/** Whether the matrix was symmetric */
|
|
1992
2008
|
isSymmetric: boolean;
|
|
1993
2009
|
}
|
package/dist/index.js
CHANGED
|
@@ -5740,11 +5740,13 @@ function eigGeneral(A, computeVectors, symmetric) {
|
|
|
5740
5740
|
const values = [];
|
|
5741
5741
|
for (let j = 0; j < nn; j++) values.push({ re: d[j], im: e[j] });
|
|
5742
5742
|
let vectors;
|
|
5743
|
+
let vectorsIm;
|
|
5743
5744
|
if (computeVectors) {
|
|
5744
5745
|
vectors = [];
|
|
5745
|
-
|
|
5746
|
-
|
|
5746
|
+
vectorsIm = [];
|
|
5747
|
+
for (let j = 0; j < nn; ) {
|
|
5747
5748
|
if (e[j] === 0) {
|
|
5749
|
+
const vec = new Array(nn).fill(0);
|
|
5748
5750
|
let colNorm = 0;
|
|
5749
5751
|
for (let i = 0; i < nn; i++) colNorm += V[i * nn + j] * V[i * nn + j];
|
|
5750
5752
|
colNorm = Math.sqrt(colNorm);
|
|
@@ -5753,13 +5755,42 @@ function eigGeneral(A, computeVectors, symmetric) {
|
|
|
5753
5755
|
} else {
|
|
5754
5756
|
for (let i = 0; i < nn; i++) vec[i] = V[i * nn + j];
|
|
5755
5757
|
}
|
|
5758
|
+
vectors.push(vec);
|
|
5759
|
+
vectorsIm.push(new Array(nn).fill(0));
|
|
5760
|
+
j++;
|
|
5761
|
+
} else {
|
|
5762
|
+
const vecRe = new Array(nn).fill(0);
|
|
5763
|
+
const vecIm = new Array(nn).fill(0);
|
|
5764
|
+
let colNorm = 0;
|
|
5765
|
+
for (let i = 0; i < nn; i++) {
|
|
5766
|
+
const re = V[i * nn + j];
|
|
5767
|
+
const im = V[i * nn + (j + 1)];
|
|
5768
|
+
colNorm += re * re + im * im;
|
|
5769
|
+
}
|
|
5770
|
+
colNorm = Math.sqrt(colNorm);
|
|
5771
|
+
if (colNorm > 1e-300) {
|
|
5772
|
+
for (let i = 0; i < nn; i++) {
|
|
5773
|
+
vecRe[i] = V[i * nn + j] / colNorm;
|
|
5774
|
+
vecIm[i] = V[i * nn + (j + 1)] / colNorm;
|
|
5775
|
+
}
|
|
5776
|
+
} else {
|
|
5777
|
+
for (let i = 0; i < nn; i++) {
|
|
5778
|
+
vecRe[i] = V[i * nn + j];
|
|
5779
|
+
vecIm[i] = V[i * nn + (j + 1)];
|
|
5780
|
+
}
|
|
5781
|
+
}
|
|
5782
|
+
vectors.push(vecRe);
|
|
5783
|
+
vectorsIm.push(vecIm);
|
|
5784
|
+
vectors.push(vecRe.slice());
|
|
5785
|
+
vectorsIm.push(vecIm.map((x2) => -x2));
|
|
5786
|
+
j += 2;
|
|
5756
5787
|
}
|
|
5757
|
-
vectors.push(vec);
|
|
5758
5788
|
}
|
|
5759
5789
|
} else {
|
|
5760
5790
|
vectors = eye(nn);
|
|
5791
|
+
vectorsIm = Array.from({ length: nn }, () => new Array(nn).fill(0));
|
|
5761
5792
|
}
|
|
5762
|
-
return { values, vectors, isSymmetric: symmetric };
|
|
5793
|
+
return { values, vectors, vectorsIm, isSymmetric: symmetric };
|
|
5763
5794
|
}
|
|
5764
5795
|
function eig(matrix2, options = {}) {
|
|
5765
5796
|
const { computeVectors = true } = options;
|
|
@@ -5775,7 +5806,7 @@ function eig(matrix2, options = {}) {
|
|
|
5775
5806
|
}
|
|
5776
5807
|
const n = A.length;
|
|
5777
5808
|
if (n === 0) {
|
|
5778
|
-
return { values: [], vectors: [], isSymmetric: true };
|
|
5809
|
+
return { values: [], vectors: [], vectorsIm: [], isSymmetric: true };
|
|
5779
5810
|
}
|
|
5780
5811
|
for (let i = 0; i < n; i++) {
|
|
5781
5812
|
if (A[i].length !== n) {
|
|
@@ -5787,6 +5818,7 @@ function eig(matrix2, options = {}) {
|
|
|
5787
5818
|
return {
|
|
5788
5819
|
values: [{ re: A[0][0], im: 0 }],
|
|
5789
5820
|
vectors: [[1]],
|
|
5821
|
+
vectorsIm: [[0]],
|
|
5790
5822
|
isSymmetric: symmetric
|
|
5791
5823
|
};
|
|
5792
5824
|
}
|
|
@@ -6224,7 +6256,7 @@ function normFro(matrix2) {
|
|
|
6224
6256
|
async function eigWasm(matrix2, options) {
|
|
6225
6257
|
const n = matrix2.length;
|
|
6226
6258
|
if (n === 0) {
|
|
6227
|
-
return { values: [], vectors: [], isSymmetric: true };
|
|
6259
|
+
return { values: [], vectors: [], vectorsIm: [], isSymmetric: true };
|
|
6228
6260
|
}
|
|
6229
6261
|
for (let i = 0; i < n; i++) {
|
|
6230
6262
|
if (matrix2[i].length !== n) {
|