我有一个2x2和一个2x1矩阵,想要乘以它们。这是代码。
for (i = 0; i < row; i++)
{
for (j = 0; j < col; j++)
{
for (k = 0; k < 2; k++)
{
mulMatrix[k] = Mat1[i, j] * Mat2[j];
}
}
}
答案 0 :(得分:0)
我认为.NET已经有了这个库。请在此处阅读:https://msdn.microsoft.com/en-us/library/system.windows.media.matrix.multiply(v=vs.110).aspx
基本上,例子是:
private void multiplicationExample()
{
Matrix matrix1 = new Matrix(5, 10, 15, 20, 25, 30);
Matrix matrix2 = new Matrix(2, 4, 6, 8, 10, 12);
// matrixResult is equal to (70,100,150,220,240,352)
Matrix matrixResult = Matrix.Multiply(matrix1, matrix2);
// matrixResult2 is also
// equal to (70,100,150,220,240,352)
Matrix matrixResult2 = matrix1 * matrix2;
}
答案 1 :(得分:0)
试试math.net。这是一个例子:
var matrixA = DenseMatrix.OfArray(new[,] { { 1.0, 2.0 }, { 4.0, 5.0 } });
var matrixB = DenseMatrix.OfArray(new[,] { { 1.0 }, { 2.0 } });
var result = matrixA * matrixB;
Console.WriteLine(result);