1010 * LU decomposition of matrix M produces 2 matrices L and U such that M = L*U
1111 * where L is lower triangular matrix and U is upper triangular matrix
1212 * <p>
13- * https://en.wikipedia.org/wiki/LU_decomposition
13+ * @see <a href=" https://en.wikipedia.org/wiki/LU_decomposition">LU Decomposition (Wikipedia)</a>
1414 * <br>
1515 * @author Mateusz Cianciara <[email protected] > 16+ * @author Justin Wetherell <[email protected] > 1617 */
1718public class LUDecomposition {
19+
20+ private int n = 0 ;
1821 private Double [][] L = null ;
1922 private Double [][] A = null ;
2023 private Integer [] permutation = null ;
21- private int n = 0 ;
2224
2325 public Matrix <Double > getL () {
2426 return new Matrix <Double >(n , n , L );
@@ -33,9 +35,9 @@ public List<Integer> getPermutation() {
3335 }
3436
3537 public LUDecomposition (Matrix <Double > input ) {
36- if (input .getCols () != input .getRows ()) {
38+ if (input .getCols () != input .getRows ())
3739 throw new IllegalArgumentException ("Matrix is not square" );
38- }
40+
3941 n = input .getCols ();
4042 L = new Double [n ][n ];
4143 A = new Double [n ][n ];
@@ -68,22 +70,25 @@ public LUDecomposition(Matrix<Double> input) {
6870 double temp = A [row ][i ];
6971 A [row ][i ] = A [max_in_col ][i ];
7072 A [max_in_col ][i ] = temp ;
73+
7174 if (i < row ) {
7275 temp = L [row ][i ];
7376 L [row ][i ] = L [max_in_col ][i ];
7477 L [max_in_col ][i ] = temp ;
7578 }
7679 }
77- int temp = permutation [row ];
80+ final int temp = permutation [row ];
7881 permutation [row ] = permutation [max_in_col ];
7982 permutation [max_in_col ] = temp ;
8083 }
84+
8185 //zero column number row
82- double p = A [row ][row ];
83- if (p == 0 ) return ;
86+ final double p = A [row ][row ];
87+ if (p == 0 )
88+ return ;
8489
8590 for (int i = row + 1 ; i < n ; i ++) {
86- double y = A [i ][row ];
91+ final double y = A [i ][row ];
8792 L [i ][row ] = y / p ;
8893
8994 for (int j = row ; j < n ; j ++) {
0 commit comments