Skip to content

Commit 6c59d78

Browse files
committed
Added LU decomposition algorthim
1 parent f2b078a commit 6c59d78

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/test/java/com/thealgorithms/matrix/LUDecompositionTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ public class LUDecompositionTest {
88

99
@Test
1010
public void testLUDecomposition() {
11-
double[][] A = {{4, 3}, {6, 3}};
11+
double[][] a = {{4, 3}, {6, 3}};
1212

1313
// Perform LU decomposition
14-
LUDecomposition.LU lu = LUDecomposition.decompose(A);
15-
double[][] L = lu.l;
16-
double[][] U = lu.u;
14+
LUDecomposition.LU lu = LUDecomposition.decompose(a);
15+
double[][] l = lu.l;
16+
double[][] u = lu.u;
1717

18-
// Reconstruct A from L and U
19-
double[][] reconstructed = multiplyMatrices(L, U);
18+
// Reconstruct a from l and u
19+
double[][] reconstructed = multiplyMatrices(l, u);
2020

21-
// Assert that reconstructed matrix matches original A
22-
for (int i = 0; i < A.length; i++) {
23-
assertArrayEquals(A[i], reconstructed[i], 1e-9);
21+
// Assert that reconstructed matrix matches original a
22+
for (int i = 0; i < a.length; i++) {
23+
assertArrayEquals(a[i], reconstructed[i], 1e-9);
2424
}
2525
}
2626

2727
// Helper method to multiply two matrices
28-
private double[][] multiplyMatrices(double[][] A, double[][] B) {
29-
int n = A.length;
30-
double[][] C = new double[n][n];
28+
private double[][] multiplyMatrices(double[][] a, double[][] b) {
29+
int n = a.length;
30+
double[][] c = new double[n][n];
3131
for (int i = 0; i < n; i++) {
3232
for (int j = 0; j < n; j++) {
3333
for (int k = 0; k < n; k++) {
34-
C[i][j] += A[i][k] * B[k][j];
34+
c[i][j] += a[i][k] * b[k][j];
3535
}
3636
}
3737
}
38-
return C;
38+
return c;
3939
}
4040
}

0 commit comments

Comments
 (0)