Skip to content

Commit 31e2ab1

Browse files
committed
Added more decomposition methods to the matrices
1 parent 92f8a5d commit 31e2ab1

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ Maven
3636
<dependency>
3737
<groupId>com.wildbitsfoundry</groupId>
3838
<artifactId>etk4j</artifactId>
39-
<version>2.2.0</version>
39+
<version>2.2.1</version>
4040
</dependency>
4141
```
4242
Gradle
4343
```bash
44-
implementation 'com.wildbitsfoundry:etk4j:2.2.0'
44+
implementation 'com.wildbitsfoundry:etk4j:2.2.1'
4545
```
4646

4747
Requirements

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.wildbitsfoundry</groupId>
44
<artifactId>etk4j</artifactId>
5-
<version>2.2.0</version>
5+
<version>2.2.1</version>
66
<name>Engineering Toolkit for Java</name>
77
<description>Tools and implementation of mathematical methods or backing math for engineering problems and
88
applications.

src/main/java/com/wildbitsfoundry/etk4j/math/linearalgebra/ComplexMatrixDense.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ public ComplexCholeskyDecompositionDense Chol() {
126126
return new ComplexCholeskyDecompositionDense(this);
127127
}
128128

129+
public ComplexSingularValueDecompositionDense SVD() {
130+
return new ComplexSingularValueDecompositionDense(this);
131+
}
132+
133+
/**
134+
* Eigenvalue decomposition. The {@link Matrix} is balanced ({@link MatrixDense#balance()}) prior to the decomposition.
135+
*
136+
* @return The {@link EigenvalueDecompositionDense} of the {@code Matrix}.
137+
*/
138+
public ComplexEigenvalueDecompositionDense eig() {
139+
return new ComplexEigenvalueDecompositionDense(this);
140+
}
141+
142+
/**
143+
* Schur Decomposition of the {@code Matrix}.
144+
*
145+
* @return The {@link SchurDecompositionDense} of the {@code Matrix}.
146+
* @see <a href="https://en.wikipedia.org/wiki/Schur_decomposition">Schur Decomposition</a>
147+
*/
148+
public ComplexSchurDecompositionDense Schur() {
149+
return new ComplexSchurDecompositionDense(this);
150+
}
151+
129152
public Complex[] getArray() {
130153
return this.data;
131154
}
@@ -514,10 +537,6 @@ public ComplexMatrixDense balance() {
514537
return new ComplexMatrixDense(data, rows, cols);
515538
}
516539

517-
public ComplexSingularValueDecompositionDense SVD() {
518-
return new ComplexSingularValueDecompositionDense(this);
519-
}
520-
521540
public ComplexMatrixDense pinv() {
522541
int rows = this.rows;
523542
int cols = this.cols;

src/main/java/com/wildbitsfoundry/etk4j/math/linearalgebra/MatrixDense.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,16 @@ public CholeskyDecompositionDense Chol() {
530530
public SingularValueDecompositionDense SVD() {
531531
return new SingularValueDecompositionDense(this);
532532
}
533+
534+
/**
535+
* Schur Decomposition of the {@code Matrix}.
536+
*
537+
* @return The {@link SchurDecompositionDense} of the {@code Matrix}.
538+
* @see <a href="https://en.wikipedia.org/wiki/Schur_decomposition">Schur Decomposition</a>
539+
*/
540+
public SchurDecompositionDense Schur() {
541+
return new SchurDecompositionDense(this);
542+
}
533543
// endregion
534544

535545
/***

src/main/java/com/wildbitsfoundry/etk4j/math/linearalgebra/MatrixSparse.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ public MatrixSparse solve(MatrixSparse b) {
216216
*/
217217
public MatrixSparse solve(double[] b) {
218218
double[][] matrix = new double[b.length][1];
219+
for(int i = 0; i < b.length; i++) {
220+
matrix[i][0] = b[i];
221+
}
219222
return solve(from2DArray(matrix));
220223
}
221224

src/test/java/com/wildbitsfoundry/etk4j/math/linearalgebra/MatrixSparseTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,20 @@ public void testLUDecomposition() {
127127
solution.get(1, 0), solution.get(2, 0)}, 1e-12);
128128
}
129129

130+
@Test
131+
public void testSolveArrayRHS() {
132+
double[][] matrix = {
133+
{1, 4, 7},
134+
{2, 5, 8},
135+
{3, 6, 10},
136+
};
137+
MatrixSparse sparseCSC = MatrixSparse.from2DArray(matrix, ConstantsETK.DOUBLE_EPS);
138+
double[] b = {1, 2, 0};
139+
MatrixSparse solution = sparseCSC.solve(b);
140+
assertArrayEquals(new double[]{-2, 6.000000000000005, -3.0000000000000027}, new double[]{solution.get(0, 0),
141+
solution.get(1, 0), solution.get(2, 0)}, 1e-12);
142+
}
143+
130144
@Test
131145
public void testLUDecompositionSparseMatrixRHS() {
132146
double[][] matrix = {

0 commit comments

Comments
 (0)