Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace MatrixClass
- {
- class Matrix
- {
- public int matrixDemention = 3;
- public int[,] matrix;
- public Matrix(int size)
- {
- this.matrixDemention = size;
- this.matrix = new int[size, size];
- }
- public int this[int x, int y]
- {
- get
- {
- return matrix[x, y];
- }
- set
- {
- matrix[x, y] = value;
- }
- }
- public static Matrix operator +(Matrix a, Matrix b)
- {
- Matrix newMatrix = new Matrix(a.matrixDemention);
- for (int i = 0; i < a.matrixDemention; i++)
- {
- for (int j = 0; j < a.matrixDemention; j++)
- {
- newMatrix[i, j] = a[i, j] + b[i, j];
- }
- }
- return newMatrix;
- }
- public static Matrix operator -(Matrix a, Matrix b)
- {
- Matrix newMatrix = new Matrix(a.matrixDemention);
- for (int i = 0; i < a.matrixDemention; i++)
- {
- for (int j = 0; j < a.matrixDemention; j++)
- {
- newMatrix[i, j] = a[i, j] - b[i, j];
- }
- }
- return newMatrix;
- }
- public static Matrix operator *(Matrix a, Matrix b)
- {
- Matrix newMatrix = new Matrix(a.matrixDemention);
- for (int i = 0; i < a.matrixDemention; i++)
- {
- for (int j = 0; j < a.matrixDemention; j++)
- {
- newMatrix[i, j] = a[i, j] * b[j, i];
- }
- }
- return newMatrix;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement