Thread: Matrice Recursive Determinant Calculation

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    72

    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;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Matrice Recursive Determinant Calculation
    By overlord21 in forum C Programming
    Replies: 6
    Last Post: 11-01-2008, 01:41 AM
  2. Recursive algorithm to find the determinant of a matrix
    By mahesh.mach in forum C Programming
    Replies: 3
    Last Post: 06-07-2007, 09:13 AM
  3. difference between recursive and iterative
    By Micko in forum C Programming
    Replies: 33
    Last Post: 07-06-2004, 09:34 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Determinant calculation
    By Sang-drax in forum C++ Programming
    Replies: 3
    Last Post: 12-04-2002, 02:32 PM

Tags for this Thread