// --------------------------------------------------------------------- // Subtract a scalar value from a matrix // Usage: // m.sub (3.1415); // --------------------------------------------------------------------- public void sub(double k) { for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { this[i, j] = SimpleComplex.complexSub(this[i, j], new SimpleComplex(k, 0.0)); } } }
// --------------------------------------------------------------------- // Subtract a scalar value from a matrix and return a new matrix // Usage: // Matrix m1 = Matrix.sub (m2, 2.718); // --------------------------------------------------------------------- public static Matrix sub(Matrix x, double k) { var result = new Matrix(x.r, x.c); for (int i = 0; i < x.r; i++) { for (int j = 0; j < x.c; j++) { result[i, j] = SimpleComplex.complexSub(x[i, j], new SimpleComplex(k, 0.0)); } } return(result); }
// --------------------------------------------------------------------- // Subtract a matrix from this. this is modified // Usage: // m.sub (m1); // --------------------------------------------------------------------- public void sub(Matrix x) { if (sameDimensions(this, x)) { for (int i = 0; i < x.r; i++) { for (int j = 0; j < x.c; j++) { this[i, j] = SimpleComplex.complexSub(this[i, j], x[i, j]); } } } else { throw new EMatrixException("Matrices must be the same dimension to perform subtraction"); } }
// Sub Methods: // Methods that return a new matrix // m = Matrix.sub (m1, m2); // m = Matrix.sub (m1, 2.3); // Methods that modify the matrix object // m.sub (m1); // m.sub (2.3); // --------------------------------------------------------------------- // Subtract two matrices together and return the result as a new matrix // Usage: // Matrix m3 = Matrix.sub (m1, m2); // --------------------------------------------------------------------- public static Matrix sub(Matrix x, Matrix y) { if (sameDimensions(x, y)) { var result = new Matrix(x.r, x.c); for (int i = 0; i < x.r; i++) { for (int j = 0; j < x.c; j++) { result[i, j] = SimpleComplex.complexSub(x[i, j], y[i, j]); } } return(result); } else { throw new EMatrixException("Matrices must be the same dimension to perform addition"); } }