我能夠使用這個代碼,找出矩陣2×2的DET:如何找到在C#矩陣3×3的DET
using System;
class find_det
{
static void Main()
{
int[,] x = { { 3, 5, }, { 5, 6 }, { 7, 8 } };
int det_of_x = x[0, 0] * x[1, 0] * x[0, 1] * x[1, 1];
Console.WriteLine(det_of_x);
Console.ReadLine();
}
}
但是,當我試圖找到3x3矩陣的DET,使用此代碼:
using System;
class matrix3x3
{
static void Main()
{
int[,,] x={{3,4,5},{3,5,6},{5,4,3}};
int det_of_x=x[0,0]*x[0,1]*x[0,2]*x[1,0]*x[1,1]*x[1,2]*x[2,0]*x[2,1]*x[2,2];
Console.WriteLine(det_of_x);
Console.ReadLine();
}
}
它出錯。爲什麼?
什麼是錯誤? – 2013-02-16 13:26:17
你確定你計算行列式嗎? – qben 2013-02-16 13:27:27
可怕的模糊問題。編譯器的錯誤應該讓你知道這裏有什麼問題。但正如其他人所說的那樣,它仍然是一個二維陣列,而不是一個3D,在類型中刪除額外的。 – 2013-02-16 13:27:45