# Matrice Recursive Determinant Calculation

• 10-31-2008
overlord21
Matrice Recursive Determinant Calculation
Hi i have problems calculating the determinant of more than a 2 x2 can anyone help

Code:

``` nt determinant(int matrix_temp[10][10],int size_matrice)  //Get the minor of the matrice {  int i,j,determinant_sum = 0;  int matrice[10][10];//matrice[maximum][maximum]  if(size_matrice==2)   {                                        //basic step         determinant_sum = matrix_temp[0][0]*matrix_temp[1][1] - matrix_temp[0][1]*matrix_temp[1][0];         return determinant_sum;   }  for(int count=0;count<size_matrice;count++)  {   int h = 0,k = 0;   for(i=1;i<size_matrice;i++)   {         for( j=0;j<size_matrice;j++)         {         if(j==count)                   matrice[h][k] = matrix_temp[i][j];         k++;         if(k == size_matrice-1)           {                 h++;                 k = 0;           }         }   } //recursive formula   determinant_sum = determinant_sum + matrix_temp[0][count]*pow(-1,count)*determinant(matrice,size_matrice-1);   //Force the sum to return an "int" result    }  return determinant_sum; }```
• 10-31-2008
tabstop
You managed to not write down the recursive formula very well, in that putting the word "sum" in a variable name does not make the program give you a sum. For instance in a 3x3 matrix you would need to compute
matrix_temp[0][0]*pow(-1,0)*determinant(minor(matrix_temp, 0, 0), 2) +
matrix_temp[0][1]*pow(-1,1)*determinant(minor(matrix_temp, 0, 1), 2) +
matrix_temp[0][2]*pow(-1,2)*determinant(minor(matrix_temp, 0, 2), 2)

Notice in your code that only one of those lines happens. Notice also that you will have to write a function to get the minor, and that the function to get the minor has to know which row and which column to eliminate.