因为课程设计的需要,写的C#矩阵类,可以实现基本的矩阵操作。
_Matrix类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Matrix_Mul
{
public class _Matrix
{
public int m;
public int n;
public double[] arr;
//初始化
public _Matrix()
{
m = 0;
n = 0;
}
public _Matrix(_Matrix s)
{
this.m = s.m;
this.n = s.n;
arr = new double[m * n];
for (int i = 0; i < m * n; i++)
{
this.arr[i] = s.arr[i];
}
}
public _Matrix(int mm, int nn)
{
m = mm;
n = nn;
}
//设置m
public void set_mn(int mm, int nn)
{
m = mm;
n = nn;
}
//设置m
public void set_m(int mm)
{
m = mm;
}
//设置n
public void set_n(int nn)
{
n = nn;
}
//初始化
public void init_matrix()
{
arr = new double[m * n];
}
//释放
public void free_matrix()
{
//delete [] arr;
}
//读取i,j坐标的数据
//失败返回-31415,成功返回值
public double read(int i, int j)
{
if (i >= m || j >= n)
{
return -31415;
}
//return *(arr + i * n + j);
return arr[i * n + j];
}
//写入i,j坐标的数据
//失败返回-1,成功返回1
public int write(int i, int j, double val)
{
if (i >= m || j >= n)
{
return -1;
}
arr[i * n + j] = val;
return 1;
}
public double sums()
{
double a = 0;
for (int i = 0; i < this.m; i++)
{
for (int j = 0; j < this.n; j++)
{
a += this.read(i, j);
}
}
return a;
}
};
}
_Matrix_Calc类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Matrix_Mul
{
public class _Matrix_Calc
{
//初始化
public _Matrix_Calc()
{
}
/// <summary>
/// C=A+B
/// </summary>
/// <param name=