Java Matrix matrixAbsDiff(double m1[][], double m2[][])

Here you can find the source of matrixAbsDiff(double m1[][], double m2[][])

Description

matrix Abs Diff

License

Open Source License

Declaration

public static double matrixAbsDiff(double m1[][], double m2[][]) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static double matrixAbsDiff(double m1[][], double m2[][]) {
        if (m1.length != m2.length)
            return Double.MAX_VALUE;
        int numElements = 0;
        double diff = 0.0;
        for (int i = 0; i < m1.length; i++) {
            if (m1[i].length != m2[i].length)
                return Double.MAX_VALUE;
            numElements += m1[i].length;
            for (int j = 0; j < m1[i].length; j++) {
                diff += Math.abs(m1[i][j] - m2[i][j]);
            }/*from w ww.j  a v  a 2 s  .  c  o m*/
        }
        if (numElements == 0)
            return 0.0;
        return diff / numElements;
    }
}

Related

  1. matrix_x_matrix(double[][] A, double[][] B)
  2. matrix_x_vectorMatrix(double[][] mat, double[][] vector, int vectorCol)
  3. matrixATrans_x_matrixB(double[][] matA, double[][] matB)
  4. matrixConcatLR(double[][] LMatrix, double[][] RMatrix)
  5. matrixConcatUL(double[][] UMatrix, double[][] LMatrix)
  6. matrixDestructAdd(double[][] m1, double[][] m2)