public static MatrixClass06 operator -(MatrixClass06 minuend, MatrixClass06 subtrahend) { MatrixClass06 matrixDifference = new MatrixClass06(3, 3); for (int i = 0; i < matrixDifference.GetRows(); i++) { for (int j = 0; j < matrixDifference.GetCols(); j++) { matrixDifference.matrix[i, j] = minuend.matrix[i, j] - subtrahend.matrix[i, j]; } } return(matrixDifference); }
public static MatrixClass06 operator +(MatrixClass06 addend1, MatrixClass06 addend2) { MatrixClass06 matrixSumm = new MatrixClass06(3, 3); for (int i = 0; i < matrixSumm.GetRows(); i++) { for (int j = 0; j < matrixSumm.GetCols(); j++) { matrixSumm.matrix[i, j] = addend1.matrix[i, j] + addend2.matrix[i, j]; } } return(matrixSumm); }
public static MatrixClass06 operator *(MatrixClass06 multiplyable1, MatrixClass06 multiplyable2) { MatrixClass06 matrixProduct = new MatrixClass06(3, 3); for (int i = 0; i < matrixProduct.GetRows(); i++) { for (int j = 0; j < matrixProduct.GetCols(); j++) { switch (i) { case 0: if (j == 0) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j] * multiplyable2.matrix[i, j] + multiplyable1.matrix[i, j + 1] * multiplyable2.matrix[i + 1, j] + multiplyable1.matrix[i, j + 2] * multiplyable2.matrix[i + 2, j]; } else if (j == 1) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j - 1] * multiplyable2.matrix[i, j] + multiplyable1.matrix[i, j] * multiplyable2.matrix[i + 1, j] + multiplyable1.matrix[i, j + 1] * multiplyable2.matrix[i + 2, j]; } else if (j == 2) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j - 2] * multiplyable2.matrix[i, j] + multiplyable1.matrix[i, j - 1] * multiplyable2.matrix[i + 1, j] + multiplyable1.matrix[i, j] * multiplyable2.matrix[i + 2, j]; } break; case 1: if (j == 0) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j] * multiplyable2.matrix[i - 1, j] + multiplyable1.matrix[i, j + 1] * multiplyable2.matrix[i, j] + multiplyable1.matrix[i, j + 2] * multiplyable2.matrix[i + 1, j]; } else if (j == 1) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j - 1] * multiplyable2.matrix[i - 1, j] + multiplyable1.matrix[i, j] * multiplyable2.matrix[i, j] + multiplyable1.matrix[i, j + 1] * multiplyable2.matrix[i + 1, j]; } else if (j == 2) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j - 2] * multiplyable2.matrix[i - 1, j] + multiplyable1.matrix[i, j - 1] * multiplyable2.matrix[i, j] + multiplyable1.matrix[i, j] * multiplyable2.matrix[i + 1, j]; } break; case 2: if (j == 0) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j] * multiplyable2.matrix[i - 2, j] + multiplyable1.matrix[i, j + 1] * multiplyable2.matrix[i - 1, j] + multiplyable1.matrix[i, j + 2] * multiplyable2.matrix[i, j]; } else if (j == 1) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j - 1] * multiplyable2.matrix[i - 2, j] + multiplyable1.matrix[i, j] * multiplyable2.matrix[i - 1, j] + multiplyable1.matrix[i, j + 1] * multiplyable2.matrix[i, j]; } else if (j == 2) { matrixProduct.matrix[i, j] = multiplyable1.matrix[i, j - 2] * multiplyable2.matrix[i - 2, j] + multiplyable1.matrix[i, j - 1] * multiplyable2.matrix[i - 1, j] + multiplyable1.matrix[i, j] * multiplyable2.matrix[i, j]; } break; default: break; } } } return(matrixProduct); }