C#中矩阵乘法演示源码

2019-01-20  本文已影响0人  程序媛宝

在学习闲暇时间,将做工程过程中比较常用的一些内容段做个记录,下面资料是关于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;

}

上一篇 下一篇

猜你喜欢

热点阅读