-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSubtractElement.java
More file actions
34 lines (30 loc) · 1.19 KB
/
Copy pathSubtractElement.java
File metadata and controls
34 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package operations;
public class SubtractElement extends AbstractOperation{
/*
Operation C[i][j][k] represents subtracting j column in i row from j column in k row.
M[j][k] -= M[i][k]
*/
private final int column;
private final int targetRow;
public SubtractElement(double[][] matrix, Double[][] eliminationFactors, Double[] normalizationFactors, int sourceRow, int column, int targetRow){
super(matrix, eliminationFactors, normalizationFactors);
this.sourceRow = sourceRow;
this.column = column;
this.targetRow = targetRow;
this.operationSymbol = 'C';
}
@Override
public Void call() {
//target element is 0 and there is no need for row multiplying
if (eliminationFactors[sourceRow][targetRow] != null)
if (column != sourceRow)
matrix[targetRow][column] -= matrix[sourceRow][column];
else //it is known for those elements to be 0 after subtracting
matrix[targetRow][column] = 0; //stability
return null;
}
@Override
public String toString(){
return "%c(%d, %d, %d)".formatted(operationSymbol, sourceRow, column, targetRow);
}
}