电脑桌面
添加小米粒文库到电脑桌面
安装后可以在桌面快捷访问

C矩阵类(实现转置,相乘,相加,求逆)

C矩阵类(实现转置,相乘,相加,求逆)_第1页
1/7
C矩阵类(实现转置,相乘,相加,求逆)_第2页
2/7
C矩阵类(实现转置,相乘,相加,求逆)_第3页
3/7
using System; class Matrix { double [,] matrix; public int row=0, col=0; //int i=0,j=0; //int count=1; //定义三个不同情况下的构造函数 public Matrix() { } public Matrix(int row) { matrix = new double[row, row]; } public Matrix(int row, int col) { this.row = row; this.col = col; matrix = new double[row, col]; } //复制构造函数 public Matrix(Matrix m) { int row = m.row; int col = m.col; matrix = new double[row, col]; for (int i = 0; i < row; i++) for (int j = 0; j < col; j++) matrix[i, j] = m.getNum(i, j); } //输入相应的值,对矩阵进行设置 public void SetNum(int i,int j, double num) { matrix[i, j] = num; } //得到相应的矩阵某个数 public double getNum(int i,int j) { return matrix[i, j]; } //输出矩阵 public void OutputM() { Console.WriteLine("矩阵为:"); for (int p = 0; p < row; p++) { for (int q = 0; q < col; q++) { Console.Write("\t"+matrix[p,q]); } Console.Write("\n"); } } //输入矩阵具体数字实现 public void InputM(int Row, int Col) { for (int a = 0; a < Col; a++) { for (int b = 0; b < Col; b++) { Console.WriteLine("第{0}行,第{1}列", a + 1, b + 1); double value = Convert.ToDouble(Console.ReadLine()); this.SetNum(a, b, value); } } } //得到 matrix public double[,] Detail { get { return matrix; } set { matrix = value; } } //矩阵转置实现 public Matrix Transpose() { Matrix another = new Matrix(row, col); for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { another.SetNum(j, i, matrix[i, j]); } } return another; } //矩阵相加实现 public static Matrix Add(Matrix lm,Matrix rm) { //行出错 if (lm.row != rm.row) { System.Exception e = new Exception("相加的两个矩阵的行数不等"); throw e; } //列出错 if (lm.col != rm.col) { System.Exception e = new Exception("相加的两个矩阵的列数不等"); throw e...

1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。

碎片内容

C矩阵类(实现转置,相乘,相加,求逆)

确认删除?
VIP
微信客服
  • 扫码咨询
会员Q群
  • 会员专属群点击这里加入QQ群
客服邮箱
回到顶部