在学习闲暇时间,将做工程过程中比较常用的一些内容段做个记录,下面资料是关于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 k = 0; k < aCols; ++k)
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;
}
网友评论