2024-10-08 10:42:11 +00:00
|
|
|
|
namespace MatrixProject;
|
|
|
|
|
|
|
|
|
|
public struct Matrix
|
|
|
|
|
{
|
|
|
|
|
private double[,] _data;
|
|
|
|
|
|
|
|
|
|
public int Rows { get => _data.GetLength(0);}
|
|
|
|
|
public int Columns { get => _data.GetLength(1);}
|
|
|
|
|
|
2024-10-08 12:24:58 +00:00
|
|
|
|
|
2024-10-08 10:42:11 +00:00
|
|
|
|
public Matrix(int rows)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_data = new double[rows, rows];
|
|
|
|
|
FillMatrixByNumber(0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public Matrix(int rows, int columns) {
|
|
|
|
|
|
|
|
|
|
_data = new double[rows,columns];
|
|
|
|
|
FillMatrixByNumber(0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
public Matrix(int rows, int columns, int fillNumber)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_data = new double[rows, columns];
|
|
|
|
|
FillMatrixByNumber(fillNumber);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 12:24:58 +00:00
|
|
|
|
public static Matrix operator +(Matrix matrix, Matrix matrixTwo) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Matrix operator *(Matrix matrix, int scalar)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < matrix.Rows; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < matrix.Columns; j++)
|
|
|
|
|
{
|
|
|
|
|
matrix[i, j] *= scalar;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return matrix;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-08 10:42:11 +00:00
|
|
|
|
public double this[int row, int column] {
|
|
|
|
|
get => _data[row,column];
|
2024-10-08 12:24:58 +00:00
|
|
|
|
set => _data[row,column] = value;
|
2024-10-08 10:42:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void FillMatrixByNumber(int number) {
|
|
|
|
|
for (int i = 0; i < Rows; i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j= 0; j < Columns; j++)
|
|
|
|
|
{
|
|
|
|
|
_data[i, j] = number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|