1 Replies - 4108 Views - Last Post: 07 August 2011 - 02:27 PM Rate Topic: -----

#1 keshvari  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10464
  • View blog
  • Posts: 38,783
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1