public static Matrix operator -(Matrix A, Matrix B) { if (MatrixUtils.AreDimensionEquals(A, B)) { return(MatrixUtils.ApplyFunction(A, B, new MatrixIteratorByRow(A), new MatrixIteratorByColumn(B), (i, j, ma, mb) => ma[i, j] - mb[i, j])); } else if (MatrixUtils.IsScalar(A) && !MatrixUtils.IsScalar(B)) { return(MatrixUtils.ApplyFunction(A, B, new MatrixIteratorByRow(B), new MatrixIteratorByColumn(B), (i, j, ma, mb) => ma[0, 0] - mb[i, j])); } else if (!MatrixUtils.IsScalar(A) && MatrixUtils.IsScalar(B)) { return(MatrixUtils.ApplyFunction(A, B, new MatrixIteratorByRow(A), new MatrixIteratorByColumn(A), (i, j, ma, mb) => ma[i, j] - mb[0, 0])); } else if (MatrixUtils.RowVector(A) && A.RowCount == B.RowCount) { return(MatrixUtils.ApplyFunction(A, B, new MatrixIteratorByRow(B), new MatrixIteratorByColumn(B), (i, j, ma, mb) => ma[i, 0] - mb[i, j])); } else if (MatrixUtils.RowVector(B) && A.RowCount == B.RowCount) { return(MatrixUtils.ApplyFunction(A, B, new MatrixIteratorByRow(A), new MatrixIteratorByColumn(A), (i, j, ma, mb) => ma[i, j] - mb[i, 0])); } return(null); }