code: public static boolean isConstantVal(DMatrixRMaj mat , double val , double tol )
      {
          // see if the result is an identity matrix
          int index = 0;
          for( int i = 0; i < mat.numRows; i++ ) {
              for( int j = 0; j < mat.numCols; j++ ) {
                  if( !(Math.abs(mat.get(index++)-val) <= tol) )
                      return false;
  
              }
          }
  
          return true;
      }
docs: Checks to see if every value in the matrix is the specified value.
  
  @param mat The matrix being tested.  Not modified.
  @param val Checks to see if every element in the matrix has this value.
  @param tol True if all the elements are within this tolerance.
  @return true if the test passes.