/************************************************************ !* This program calculates the determinant of a real square * !* matrix using Function FindDet (see ref. below). * !* -------------------------------------------------------- * !* SAMPLE RUN: * !* * !* Calculate the deteminant of square matrix: * !* * !* ! 0 -1 -1 -1 ! * !* ! 1 0 -1 -1 ! * !* ! 1 1 0 -1 ! * !* ! 1 1 1 0 ! * !* * !* Determinant = 1.000000 * !* * !* -------------------------------------------------------- * !* C++ Version By Jean-Pierre Moreau, Paris. * !***********************************************************/ #include #include #define N 4 #define FALSE 0 #define TRUE 1 typedef double MAT[N+1][N+1]; // index 0 not used here /*--------------------------------------------------------------------------------------------------- !Function to find the determinant of a square matrix !Author : Louisda16th a.k.a Ashwith J. Rego !Description: The subroutine is based on two key points: !1] A determinant is unaltered when row operations are performed: Hence, using this principle, !row operations (column operations would work as well) are used !to convert the matrix into upper traingular form !2]The determinant of a triangular matrix is obtained by finding the product of the diagonal elements !--------------------------------------------------------------------------------------------------*/ double FindDet(MAT matrix, int n) { double m, tmp; int i, j, k, l; bool DetExists = TRUE; l = 1; // Convert to upper triangular form for (k = 1; k