# matrix determinant with cofactor method

Page 1 of 1

## 1 Replies - 10967 Views - Last Post: 07 August 2011 - 02:27 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=242645&amp;s=45f78843783f5b68ec2f25b45a5c43ab&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 keshvari

Reputation: 0
• Posts: 2
• Joined: 07-August 11

# matrix determinant with cofactor method

Posted 07 August 2011 - 10:57 AM

hello
You can find some information in this link about how to find a determinant with cofactor method but my implementation is different from this link and I didn't checked the link implementation.My link
I think that My problem is in recursive calls but I don't know how to get out of that and Maybe my code has a logical problem but I can not find that. I use to function 1- Getminorof( ) and 2- cofactro(). Getminorof() give me the subtract of the matrix given that one defined column and one row is omitted and it is what I want. But in cofactor function when I try to make it recursive problem appeared.

```	int GetMinor(Matrix *src,Matrix *dest, int row, int col, int order)
{
// indicate which col and row is being copied to dest

int colCount = 0,rowCount = 0;
int i,j;

for(i = 0; i < order; i++ ){
if( i != row )
{
colCount = 0;
for( j = 0; j < order; j++ )
{
// when j is not the element
if( j != col )
{
dest->elements[rowCount][colCount] = src->elements[i][j];
colCount++;
}
}
rowCount++;
}
}
return 0;
}

int matrixCofact(Matrix* mat,int order,double* determinan){
int i;
Matrix* minor;
minor = malloc(sizeof(double));
newMatrix(order-1,order-1,minor);
double* det;
det = malloc(sizeof(double));
if( order == 1 ){
printf("The End");
}
for(i = 0; i <order;i++){
GetMinor( mat, minor, 0, i, order);
printf("\n");
matrixPrint(minor);
if( minor->colCount > 3){
*det += pow(-1.0,i+0) * minor->elements[1][i] * matrixCofact(minor,order-1,det);
printf("\nThe matrix determinant is: %f",*det);
}else{
matrix3dDeterminan(minor,det);
printf("\nThe matrix determinant is: %f",*det);
}
}
printf("BYE ");
return 0;
}

```

if the complete code needed let me know.

This post has been edited by keshvari: 08 August 2011 - 03:00 PM

Is This A Good Question/Topic? 0

## Replies To: matrix determinant with cofactor method

### #2 macosxnerd101

• Games, Graphs, and Auctions

Reputation: 12276
• Posts: 45,364
• Joined: 27-December 08

## Re: matrix determinant with cofactor method

Posted 07 August 2011 - 02:27 PM

Moved to C/C++. Please do not post help questions in the tutorials section.