# Thread: matrix program issue, recursion

1. ## matrix program issue, recursion

hi, i'm working on a program that allows you to enter a matrix, and then do all kinds of stuff to it. i'm having problems with my determinant function, though. I want to use recursion so that if doesn't matter what size matrix is entered. there is a seperate function that gets a sub-matrix for me, but the recursion is killing me.

Code:
```double determinant(double m [][MAXCOLS], int msize)
{

double det = 0;
double subm [MAXCOLS][MAXCOLS];
int i;
int sign = 0;

if(msize < 3)
det = m[0][0] * m[1][1] - m[0][1] * m[1][0];
else
{
for(i = 0; i < msize; i++)
{
if(i%2 == 0)
sign = 1;
else
{
sign = -1;
}

get_submatrix(m, subm, msize, 0, i);
det += (sign * m[0][i] * determinant(subm, msize-i));
}
}

return det;
}```
that's my determinant function as of right now. it gives me an infinite loop. the arguments of my submatrix function are:
arg1, double array [MAXCOLS][MAXCOLS]
arg2, double array [MAXCOLS][MAXCOLS]
arg3, int (the size of the square matrix)
arg4, int (row to be removed)
arg5, int (column to be removed)

if you need more info, just let me know, and i appreciate any help that i can get!

2. Are you sure it's an infinite loop? Then check if your submatrix is really decreasing in size. Take a 3-3 test matrix and print lot's of stuff to see if it works ok.

For larger matrices, your method will seem to run eternally. Better form a LU-decomposition and extract the determinant from U's diagonal.