Thread: Minor of a determinant

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    16

    Minor of a determinant

    This is what I have for finding the minor. I think I could make it more condense to run faster but don't know what to do really. My program works with this function, but I'm just wondering what I can do to make it run smoother.

    Code:
    double minor(double A[][4], int i, int j)
    {
    	double find_minor[3][3];
    	int counta = 0;
    	int countb = 0;
    
    	for (int x = 0; x < 4; x++)
    	{
    		if (x != j)
    		{
    			for (int y = 0; y < 4; y++)
    			{
    				if (y != i)
    				{
    					find_minor[counta][countb] = A[x][y];
    					++countb;
    					if (countb % 3 == 0)
    					{
    						countb = 0;
    					}
    				}
    			}
    			++counta;
    		}
    	}
    	double minordet = find_minor[0][0]*(find_minor[1][1]*find_minor[2][2]-find_minor[2][1]*find_minor[1][2]) -
    		find_minor[0][1]*(find_minor[1][0]*find_minor[2][2]-find_minor[2][0]*find_minor[1][2])+find_minor[0][2] *
    		(find_minor[1][0]*find_minor[2][1]-find_minor[2][0]*find_minor[1][1]);
    	
    	return minordet;
    }

  2. #2
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    I don't know about the speed, but you should iniitlaize find_minor just to make sure no elements contain random data after that loop ends.
    Code:
    double find_minor[3][3] = {0};
    loop counters should be from 0 to 3, not 0 to 4
    Code:
    for (int x = 0; x < 3; x++)
    and
    for (int y = 0; y < 3; y++)
    Last edited by Ancient Dragon; 11-30-2005 at 01:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fast Determinant evaluator
    By jack_carver in forum C Programming
    Replies: 2
    Last Post: 12-28-2009, 08:42 PM
  2. matrix determinant
    By roaan in forum C Programming
    Replies: 1
    Last Post: 06-30-2009, 12:44 PM
  3. Determinant Prob
    By dantu1985 in forum C Programming
    Replies: 2
    Last Post: 08-19-2007, 12:00 AM
  4. 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
  5. determinant?! HELP!!!
    By ankurtrick in forum C Programming
    Replies: 1
    Last Post: 10-08-2004, 09:12 PM