了解矩阵的特定功能行列式的

问题描述:

我发现互联网上的程序,计算矩阵的行列式:了解矩阵的特定功能行列式的

/* 
* 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/

我想从它,但我不学习不明白。它与高斯消除有什么关系?否则,你知道哪个进程使用这个算法吗?

预先感谢您的任何一个谁也许能帮助我

+0

它是一个线性代数数学问题。答案当然是在你的线性代数教科书或[这里](https://en.wikipedia.org/wiki/Determinant): –

+0

如果你想更好地学习你自己写的代码,这个坦率地说很没用因为它只适用于只有一个特定尺寸(10x10) – user463035818

+0

@ tobi303的矩阵,所以它适用于从1x1到10x10的矩阵。 –

这是使用Lapace扩展,通过计算(n-1) x (n-1) subminorsň决定其递归计算一个n x n矩阵的行列式的算法。 2 x 2矩阵的行列式应该是显而易见的。

有更好的方法来做到这一点,如LU分解。

+1

非常感谢您的快速回复 – Muclos

该程序使用递归函数创建子矩阵并计算子矩阵为2x2时的行列式。

当程序具有子矩阵的行列式时,它可以对它进行加减运算,就像您在Wikipedia page上看到的有关行列式。

最后,递归函数返回完整矩阵的行列式。

+1

非常感谢您的快速回复 – Muclos