《矩阵求逆及相关运算(Inverse matrix and related operations).doc》由会员分享,可在线阅读,更多相关《矩阵求逆及相关运算(Inverse matrix and related operations).doc(16页珍藏版)》请在金锄头文库上搜索。
1、矩阵求逆及相关运算(Inverse matrix and related operations)使用系统;使用system.collections.generic;使用系统文本;命名空间bytetest / / /算法的大致思想是通过行列式初等变换来求。/matrixcomputer公共类 / / /求逆矩阵/ / / / 公共静态双,逆矩阵(双, dMatrix)/ /获取矩阵的行数智力水平= dMatrix长度(1);/ / / /求矩阵的行列式的值/ /双dmatrixvalue = matrixvalue(dMatrix);/如果(dmatrixvalue = = 0)/ /返回nul
2、l;/ 双, dreversematrix =新的双 2 *级水平;/ /初始化矩阵水平(2级)对于(int = i 0;i 水平;i + +)用于(int = 0;j 2 *级;j + +)如果(j)dreversematrix 我 = dMatrix 我;其他的如果(j水平= i)dreversematrix 我 = 1;其他的dreversematrix 我 = 0;对于(int = i 0,j = 0;i 水平和 I; s-)Temp = dReverseMatrixs, j;For (int t = J; T = 0; i-)For (int j = I + 1; J Level;
3、j+)If (dReverseMatrixi, j = = 0)Double TMP = dReverseMatrixi, j;For (int n = J; n 2*Level; n+)DReverseMatrixi, n = (tmp*dReverseMatrixj, n);/ / returns the inverse matrixDouble, dReturn = new, doubleLevel, Level;For (int i = 0; I Level; i+)For (int j = 0; J Level; j+)DReturni, j = dReverseMatrixi, j
4、 + Level;Return dReturn;/ / / The corresponding matrix determinant value x/ / / Name= MatrixList / / / param/ / / Public, static, double, MatrixValue (double, MatrixList)Int Level = MatrixList.GetLength (1);Double, dMatrix = new, doubleLevel, Level;For (int i = 0; I Level; i+)For (int j = 0; J Level
5、; j+)DMatrixi, j = MatrixListi, j;Int sign = 1;For (int i = 0, j = 0; I J i, cut dMatrixm, j! =0) exchangeIf (dMatrixi, j = 0)If (I = = Level - 1)Return 0;Int m = I + 1;Gets a dMatrixm / / j, not for 0 rows(for; dMatrixm, j = 0; m+)If (M = = Level - 1)Return 0;To determine whether the maximum line /
6、 matrix, if so, it returns 0/ / the I line and the M line changeDouble temp;For (int n = J; n I; s - -)TMP = dmatrix S J;/ / j行后面的所有行For (int t = J; T level; t + +)Dmatrix S, t - = dmatrix I, t * (TMP / dmatrix I, J);The double result = 1;For (int i = 0; I / / / / / / / / / /Public static double , m
7、atrixmultiplication (double , firstmatrix, double , secondmatrix)Double , resultmatrix = new double firstmatrix.getlength (0), secondmatrix.getlength (1);/ / 判断相乘矩阵是否合法, 即第一个矩阵的列要等于第二个矩阵的行If (firstmatrix.getlength (1). Secondmatrix.getlength (0) =Return null;/ / 求结果矩阵For (int rowindex = 0; rowindex
8、firstmatrix.getlength (0); rowindex + +)For (int COLINDEX = 0; COLINDEX secondmatrix.getlength (1); COLINDEX + +)/ / 初始化结果矩阵的元素Resultmatrix rowindex, COLINDEX = 0;For (int i = 0; I firstmatrix.getlength (1); I + +)/ / 求结果矩阵的元素值Resultmatrix rowindex, COLINDEX + = firstmatrix rowindex, I * secondmatrix I, COLINDEX;Return resultmatrix;