2010年2月2日 星期二

行列式

其實在國中就有學過行列式的運算,但是當初只了解他如何計算而已

其算法如下圖所示:

行列式公式

直到最近看 Eigenvalue 與 Eigenvector 的計算時,發現其可以用來求解特徵值,

才了解到他的重要性,所以就實作了行列式的算法,其內容如下


double[][] data= new double[3][]{
new double[3]{10,10,5},
new double[3]{10,30,15},
new double[3]{5,15,20}
double result = 0, temp, negTemp;
int rowBoundary = data.GetLength(0);
int colBoundary = data[0].GetLength(0);
for (int i = 0; i < rowBoundary; i++)
{
temp = 1;
negTemp = 1;
for (int j = 0; j < colBoundary; j++) {
temp *= data[(i + j) % rowBoundary][j];
negTemp *= data[(i + j) % rowBoundary][(rowBoundary - 1) - j];
}
result += temp - negTemp;
}

沒有留言:

張貼留言