public Matrix subtract(Matrix m) { if (m.getWidth() != getWidth() || m.getHeight() != getHeight()) throw new ArrayIndexOutOfBoundsException("Matrix size mismatch!"); for (int x = 0; x < getWidth(); x++) { for (int y = 0; y < getHeight(); y++) { data[x][y] -= m.data[x][y]; } } return this; }
@Override public boolean equals(Object o) { if (o instanceof Matrix) { Matrix m = (Matrix) o; if (m.getWidth() == getWidth() && m.getHeight() == getHeight()) { return Arrays.deepEquals(m.data, data); } } return false; }
public static Matrix multiply(Matrix a, Matrix b) { if (a.getWidth() != b.getHeight()) throw new ArrayIndexOutOfBoundsException("Matrix size mismatch!"); Matrix result = new Matrix(a.getHeight(), b.getWidth()); for (int x = 0; x < result.getWidth(); x++) { for (int y = 0; y < result.getHeight(); y++) { for (int i = 0; i < a.getWidth(); i++) { result.data[x][y] += (a.data[i][y] * b.data[x][i]); } } } return result; }
public static Matrix subtract(Matrix a, Matrix b) { return ((Matrix) a.clone()).subtract(b); }
public static Matrix add(Matrix a, Matrix b) { return ((Matrix) a.clone()).add(b); }