gogo 通过本文主要向大家介绍了c#矩阵乘法,c#矩阵求逆,c#矩阵转置,c#定义矩阵,c#矩阵运算等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
本文实例讲述了C#实现矩阵乘法的方法。分享给大家供大家参考。具体如下:
static double[][] MatrixMultiplication(double[][] matrixOne, double[][] matrixTwo) { int aRows = matrixOne.Length; int aCols = matrixOne[0].Length; int bRows = matrixTwo.Length; int bCols = matrixTwo[0].Length; if (aCols != bRows) throw new Exception("Out of shape matrices"); double[][] result = CreateMatrix(aRows, bCols); for (int i = 0; i < aRows; ++i) // each row of MatrixOne for (int j = 0; j < bCols; ++j) // each col of MatrixTwo for (int k = 0; k < aCols; ++k) result[i][j] += matrixOne[i][k] * matrixTwo[k][j]; return result; } static double[][] CreateMatrix(int rows, int cols) { double[][] result = new double[rows][]; for (int i = 0; i < rows; ++i) result[i] = new double[cols]; return result; }</div>
希望本文所述对大家的C#程序设计有所帮助。
</div>