我發現互聯網上的程序,計算矩陣的行列式:瞭解矩陣的特定功能行列式的
/*
* C++ Program to Find the Determinant of a Given Matrix
*/
#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
double d = 0;
double det(int n, double mat[10][10])
{
int c, subi, i, j, subj;
double submat[10][10];
if (n == 2)
{
return((mat[0][0] * mat[1][1]) - (mat[1][0] * mat[0][1]));
}
else
{
for(c = 0; c < n; c++)
{
subi = 0;
for(i = 1; i < n; i++)
{
subj = 0;
for(j = 0; j < n; j++)
{
if (j == c)
{
continue;
}
submat[subi][subj] = mat[i][j];
subj++;
}
subi++;
}
d = d + (pow(-1 ,c) * mat[0][c] * det(n - 1 ,submat));
}
}
return d;
}
int main()
{
int n;
cout<<"enter the order of matrix" ;
cin>>n;
double mat[10][10];
int i, j;
cout<<"enter the elements"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cin>>mat[i][j];
}
}
cout<<"\ndeterminant"<<det(n,mat);
getch();
}
來源:http://www.sanfoundry.com/cpp-program-find-determinant-given-matrix/
我想從它,但我不學習不明白。它與高斯消除有什麼關係?否則,你知道哪個進程使用這個算法嗎?
預先感謝您的任何一個誰也許能幫助我
它是一個線性代數數學問題。答案當然是在你的線性代數教科書或[這裏](https://en.wikipedia.org/wiki/Determinant): –
如果你想更好地學習你自己寫的代碼,這個坦率地說很沒用因爲它只適用於只有一個特定尺寸(10x10) – user463035818
@ tobi303的矩陣,所以它適用於從1x1到10x10的矩陣。 –