compare method
Compares two matrices mat1
and mat2
. If all elements are not different
more than epsilon
, the matrices are considered as equals, and null is
returned. Otherwise, a String of the form "i, k, mat1k
, mat2k
"
is returned showing the first encountered unequal matrix element.
Implementation
String compare(List<List<double>> mat1, List<List<double>> mat2, double epsilon){
for (int i = 0; i < mat1.length; i++) {
for (int k = 0; k < mat1[0].length; k++) {
if ((mat1[i][k] - mat2[i][k]).abs() > epsilon) {
return
"$i, $k, ${mat1[i][k]}, ${mat2[i][k]}";
}
}
}
return null;
}