hi,

i am computing for a determinant(k.det) of a matrix in my program.

at first i was using int and everything worked fine

however we were required to use double for the matrix, however, when i used double, the formula won't work any more for getting the determinant of a matrix.. it always returned a 0 value...

can anyone help me with this please?

k.det is a double

here's part of the code:

``````double computation(matrix k, int mA, int nA, int matrix, int m1, int m2, int m3, int m4, int m5, int m6, int m7, int m8, int m9, int m10, int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int n10, double **pX1, double **pX2,double **pX3, double **pX4,double **pX5, double**pX6,double **pX7, double **pX8,double **pX9, double **pX10, int ctrrow, int ctrcol){    /*function for computation of determinant*/
int m,n;
double temp;
double **pA=(double**)malloc(m * sizeof(double));
if(matrix == 1){
pA=pX1;
mA=m1;
nA=n1;
}
else if(matrix == 2){
pA=pX2;
mA=m2;
nA=n2;
}
else if(matrix == 3){
pA=pX3;
mA=m3;
nA=n3;
}
else if(matrix == 4){
pA=pX4;
mA=m4;
nA=n4;
}
else if(matrix == 5){
pA=pX5;
mA=m5;
nA=n5;
}
else if(matrix == 6){
pA=pX6;
mA=m6;
nA=n6;
}
else if(matrix == 7){
pA=pX7;
mA=m7;
nA=n7;
}
else if(matrix == 8){
pA=pX8;
mA=m8;
nA=n8;
}
else if(matrix == 9){
pA=pX9;
mA=m9;
nA=n9;
}
else if(matrix == 10){
pA=pX10;
mA=m10;
nA=n10;
}
if(mA == nA){
if(mA == 1 || nA == 1){
ctrrow = 0;
ctrcol = 0;
k.det = pA[ctrrow][ctrcol];
}//closes 1 by 1 matrices
else if(mA == 2 || nA == 2){
ctrrow = 0;
ctrcol = 0;
k.det = 0;
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1];
ctrcol = 1;
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol-1];
}//closes 2 by 2 matrices
else if(mA == 3 || nA == 3){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2];
break;
}
}
ctrrow = 2;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2];
break;
}//closes switch
}//closes for loop
}//closes 3 by 3 matrices
else if(mA == 4 || nA == 4){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 3:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1] * pA[ctrrow+3][2];
break;
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0] * pA[ctrrow+3][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][0];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3];
break;
}
}
ctrrow = 3;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 3:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1] * pA[ctrrow-3][2];
break;
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0] * pA[ctrrow-3][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][0];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3];
break;
}//closes switch
}//closes for loop
}//closes 4 by 4 matrices
else if(mA == 5 || nA == 5){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 4:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1] * pA[ctrrow+3][2] * pA[ctrrow+4][3];
break;
case 3:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0] * pA[ctrrow+3][1] * pA[ctrrow+4][2];
break;
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][0] * pA[ctrrow+4][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][0];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4];
break;
}
}
ctrrow = 4;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 4:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1] * pA[ctrrow-3][2] * pA[ctrrow-4][3];
break;
case 3:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0] * pA[ctrrow-3][1] * pA[ctrrow-4][2];
break;
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][0] * pA[ctrrow-4][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][0];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4];
break;
}//closes switch
}//closes for loop
}//closes 5 by 5 matrices
else if(mA == 6 || nA == 6){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 5:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1] * pA[ctrrow+3][2] * pA[ctrrow+4][3] * pA[ctrrow+5][4];
break;
case 4:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0] * pA[ctrrow+3][1] * pA[ctrrow+4][2] * pA[ctrrow+5][3];
break;
case 3:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][0] * pA[ctrrow+4][1] * pA[ctrrow+5][2];
break;
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][0] * pA[ctrrow+5][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][0];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5];
break;
}
}
ctrrow = 5;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 5:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1] * pA[ctrrow-3][2] * pA[ctrrow-4][3] * pA[ctrrow-5][4];
break;
case 4:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0] * pA[ctrrow-3][1] * pA[ctrrow-4][2] * pA[ctrrow-5][3];
break;
case 3:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][0] * pA[ctrrow-4][1] * pA[ctrrow-5][2];
break;
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][0] * pA[ctrrow-5][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][0];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5];
break;
}//closes switch
}//closes for loop
}//closes 6 by 6 matrices
else if(mA == 7 || nA == 7){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 6:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1] * pA[ctrrow+3][2] * pA[ctrrow+4][3] * pA[ctrrow+5][4] * pA[ctrrow+6][5];
break;
case 5:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0] * pA[ctrrow+3][1] * pA[ctrrow+4][2] * pA[ctrrow+5][3] * pA[ctrrow+6][4];
break;
case 4:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][0] * pA[ctrrow+4][1] * pA[ctrrow+5][2] * pA[ctrrow+6][3];
break;
case 3:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][0] * pA[ctrrow+5][1] * pA[ctrrow+6][2];
break;
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][0] * pA[ctrrow+6][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][0];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6];
break;
}
}
ctrrow = 6;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 6:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1] * pA[ctrrow-3][2] * pA[ctrrow-4][3] * pA[ctrrow-5][4] * pA[ctrrow-6][5];
break;
case 5:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0] * pA[ctrrow-3][1] * pA[ctrrow-4][2] * pA[ctrrow-5][3] * pA[ctrrow-6][4];
break;
case 4:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][0] * pA[ctrrow-4][1] * pA[ctrrow-5][2] * pA[ctrrow-6][3];
break;
case 3:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][0] * pA[ctrrow-5][1] * pA[ctrrow-6][2];
break;
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][0] * pA[ctrrow-6][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][0];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6];
break;
}//closes switch
}//closes for loop
}//closes 7 by 7 matrices
else if(mA == 8 || nA == 8){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 7:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1] * pA[ctrrow+3][2] * pA[ctrrow+4][3] * pA[ctrrow+5][4] * pA[ctrrow+6][5] * pA[ctrrow+7][6];
break;
case 6:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0] * pA[ctrrow+3][1] * pA[ctrrow+4][2] * pA[ctrrow+5][3] * pA[ctrrow+6][4] * pA[ctrrow+7][5];
break;
case 5:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][0] * pA[ctrrow+4][1] * pA[ctrrow+5][2] * pA[ctrrow+6][3] * pA[ctrrow+7][4];
break;
case 4:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][0] * pA[ctrrow+5][1] * pA[ctrrow+6][2] * pA[ctrrow+7][3];
break;
case 3:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][0] * pA[ctrrow+6][1] * pA[ctrrow+7][2];
break;
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][0] * pA[ctrrow+7][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][0];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][ctrcol+7];
break;
}
}
ctrrow = 7;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 7:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1] * pA[ctrrow-3][2] * pA[ctrrow-4][3] * pA[ctrrow-5][4] * pA[ctrrow-6][5] * pA[ctrrow-7][6];
break;
case 6:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0] * pA[ctrrow-3][1] * pA[ctrrow-4][2] * pA[ctrrow-5][3] * pA[ctrrow-6][4] * pA[ctrrow-7][5];
break;
case 5:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][0] * pA[ctrrow-4][1] * pA[ctrrow-5][2] * pA[ctrrow-6][3] * pA[ctrrow-7][4];
break;
case 4:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][0] * pA[ctrrow-5][1] * pA[ctrrow-6][2] * pA[ctrrow-7][3];
break;
case 3:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][0] * pA[ctrrow-6][1] * pA[ctrrow-7][2];
break;
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][0] * pA[ctrrow-7][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][0];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][ctrcol+7];
break;
}//closes switch
}//closes for loop
}//closes 8 by 8 matrices
else if(mA == 9 || nA == 9){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 8:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1] * pA[ctrrow+3][2] * pA[ctrrow+4][3] * pA[ctrrow+5][4] * pA[ctrrow+6][5] * pA[ctrrow+7][6] * pA[ctrrow+8][7];
break;
case 7:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0] * pA[ctrrow+3][1] * pA[ctrrow+4][2] * pA[ctrrow+5][3] * pA[ctrrow+6][4] * pA[ctrrow+7][5] * pA[ctrrow+8][6];
break;
case 6:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][0] * pA[ctrrow+4][1] * pA[ctrrow+5][2] * pA[ctrrow+6][3] * pA[ctrrow+7][4] * pA[ctrrow+8][5];
break;
case 5:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][0] * pA[ctrrow+5][1] * pA[ctrrow+6][2] * pA[ctrrow+7][3] * pA[ctrrow+8][4];
break;
case 4:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][0] * pA[ctrrow+6][1] * pA[ctrrow+7][2] * pA[ctrrow+8][3];
break;
case 3:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][0] * pA[ctrrow+7][1] * pA[ctrrow+8][2];
break;
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][0] * pA[ctrrow+8][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][ctrcol+7] * pA[ctrrow+8][0];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][ctrcol+7] * pA[ctrrow+8][ctrcol+8];
break;
}
}
ctrrow = 8;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 8:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1] * pA[ctrrow-3][2] * pA[ctrrow-4][3] * pA[ctrrow-5][4] * pA[ctrrow-6][5] * pA[ctrrow-7][6] * pA[ctrrow-8][7];
break;
case 7:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0] * pA[ctrrow-3][1] * pA[ctrrow-4][2] * pA[ctrrow-5][3] * pA[ctrrow-6][4] * pA[ctrrow-7][5] * pA[ctrrow-8][6];
break;
case 6:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][0] * pA[ctrrow-4][1] * pA[ctrrow-5][2] * pA[ctrrow-6][3] * pA[ctrrow-7][4] * pA[ctrrow-8][5];
break;
case 5:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][0] * pA[ctrrow-5][1] * pA[ctrrow-6][2] * pA[ctrrow-7][3] * pA[ctrrow-8][4];
break;
case 4:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][0] * pA[ctrrow-6][1] * pA[ctrrow-7][2] * pA[ctrrow-8][3];
break;
case 3:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][0] * pA[ctrrow-7][1] * pA[ctrrow-8][2];
break;
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][0] * pA[ctrrow-8][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][ctrcol+7] * pA[ctrrow-8][0];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][ctrcol+7] * pA[ctrrow-8][ctrcol+8];
break;
}//closes switch
}//closes for loop (-)
}//closes else if for 9 by 9 matrices
else if(mA == 10 || nA == 10){
ctrrow = 0;
k.det = 0;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 9:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][0] * pA[ctrrow+2][1] * pA[ctrrow+3][2] * pA[ctrrow+4][3] * pA[ctrrow+5][4] * pA[ctrrow+6][5] * pA[ctrrow+7][6] * pA[ctrrow+8][7] * pA[ctrrow+9][8];
break;
case 8:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][0] * pA[ctrrow+3][1] * pA[ctrrow+4][2] * pA[ctrrow+5][3] * pA[ctrrow+6][4] * pA[ctrrow+7][5] * pA[ctrrow+8][6] * pA[ctrrow+9][7];
break;
case 7:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][0] * pA[ctrrow+4][1] * pA[ctrrow+5][2] * pA[ctrrow+6][3] * pA[ctrrow+7][4] * pA[ctrrow+8][5] * pA[ctrrow+9][6];
break;
case 6:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][0] * pA[ctrrow+5][1] * pA[ctrrow+6][2] * pA[ctrrow+7][3] * pA[ctrrow+8][4] * pA[ctrrow+9][5];
break;
case 5:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][0] * pA[ctrrow+6][1] * pA[ctrrow+7][2] * pA[ctrrow+8][3] * pA[ctrrow+9][4];
break;
case 4:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][0] * pA[ctrrow+7][1] * pA[ctrrow+8][2] * pA[ctrrow+9][3];
break;
case 3:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][0] * pA[ctrrow+8][1] * pA[ctrrow+9][2];
break;
case 2:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][ctrcol+7] * pA[ctrrow+8][0] * pA[ctrrow+9][1];
break;
case 1:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][ctrcol+7] * pA[ctrrow+8][ctrcol+8] * pA[ctrrow+9][1];
break;
case 0:
k.det += pA[ctrrow][ctrcol] * pA[ctrrow+1][ctrcol+1] * pA[ctrrow+2][ctrcol+2] * pA[ctrrow+3][ctrcol+3] * pA[ctrrow+4][ctrcol+4] * pA[ctrrow+5][ctrcol+5] * pA[ctrrow+6][ctrcol+6] * pA[ctrrow+7][ctrcol+7] * pA[ctrrow+8][ctrcol+8] * pA[ctrrow+9][ctrcol+9];
break;
}
}
ctrrow = 9;
for ( ctrcol = 0 ; ctrcol < nA ; ctrcol++)
{
switch (ctrcol)
{
case 9:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][0] * pA[ctrrow-2][1] * pA[ctrrow-3][2] * pA[ctrrow-4][3] * pA[ctrrow-5][4] * pA[ctrrow-6][5] * pA[ctrrow-7][6] * pA[ctrrow-8][7] * pA[ctrrow-9][8];
break;
case 8:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][0] * pA[ctrrow-3][1] * pA[ctrrow-4][2] * pA[ctrrow-5][3] * pA[ctrrow-6][4] * pA[ctrrow-7][5] * pA[ctrrow-8][6] * pA[ctrrow-9][7];
break;
case 7:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][0] * pA[ctrrow-4][1] * pA[ctrrow-5][2] * pA[ctrrow-6][3] * pA[ctrrow-7][4] * pA[ctrrow-8][5] * pA[ctrrow-9][6];
break;
case 6:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][0] * pA[ctrrow-5][1] * pA[ctrrow-6][2] * pA[ctrrow-7][3] * pA[ctrrow-8][4] * pA[ctrrow-9][5];
break;
case 5:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][0] * pA[ctrrow-6][1] * pA[ctrrow-7][2] * pA[ctrrow-8][3] * pA[ctrrow-9][4];
break;
case 4:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][0] * pA[ctrrow-7][1] * pA[ctrrow-8][2] * pA[ctrrow-9][3];
break;
case 3:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][0] * pA[ctrrow-8][1] * pA[ctrrow-9][2];
break;
case 2:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][ctrcol+7] * pA[ctrrow-8][0] * pA[ctrrow-9][1];
break;
case 1:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][ctrcol+7] * pA[ctrrow-8][ctrcol+8] * pA[ctrrow-9][1];
break;
case 0:
k.det -= pA[ctrrow][ctrcol] * pA[ctrrow-1][ctrcol+1] * pA[ctrrow-2][ctrcol+2] * pA[ctrrow-3][ctrcol+3] * pA[ctrrow-4][ctrcol+4] * pA[ctrrow-5][ctrcol+5] * pA[ctrrow-6][ctrcol+6] * pA[ctrrow-7][ctrcol+7] * pA[ctrrow-8][ctrcol+8] * pA[ctrrow-9][ctrcol+9];
break;
}//closes switch
}//closes for loop (-)
}//closes else if for 10 by 10 matrix
}//closes if for square matrices
temp =k.det;
return temp;
}``````
500 lines on ONE function, and f-ugly posting - puke puke puke
4
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Dave Sinkula

holy indentation, batman! :icon_eek:

seriously, dude, i can't even look at that. you've got to properly indent that mess.

.

Edited by jephthah: n/a

oh it's because the formulas take more than 1 line.. in my program it's properly indented

Wow over 500 lines for a determinant. Maybe you should be a teacher?

Seriously, I wouldn't want use that function to calculate the determinate, becuase I would have to do this : compute(matrixVar,var1,var2,matrixVar,a,b,c,d,e,f,g ..........);
``double computation(matrix k, int mA, int nA, int matrix, int m1, int m2, int m3, int m4, int m5, int m6, int m7, int m8, int m9, int m10, int n1,int n2,int n3,int n4,int n5,int n6,int n7,int n8,int n9,int n10, double **pX1, double **pX2,double **pX3, double **pX4,double **pX5, double**pX6,double **pX7, double **pX8,double **pX9, double **pX10, int ctrrow, int ctrcol){    /*function for computation of determinant*/``