Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

little Bug #7

Open
miguemorales opened this issue Mar 11, 2021 · 3 comments
Open

little Bug #7

miguemorales opened this issue Mar 11, 2021 · 3 comments

Comments

@miguemorales
Copy link

I have found your code very useful for a project where i use simple Matrix, but i have found a little bug in the determinant calculation, i attach you the code solving this error:
double matDet(Matrix* M) {
Matrix* Copy;
Copy = matCopy(M);
double det, factor;
if (M->columns != M->rows) {
printf("Columns and rows must have same length");
return -1;
}
else if (M->columns ==2){
det = Copy->numbers[0][0]*Copy->numbers[1][1]-Copy->numbers[0][1]*Copy->numbers[1][0];
return det;
}
det = 0;
for (int i = 0; i < Copy->columns; i++) {
Matrix *Submat;
int ncol = Copy->columns-1;
double v = (double)malloc(sizeof(double)ncolncol);
double *cv = v;
unsigned int count;
for (int ii = 0; ii < Copy->columns; ii++){
for ( int jj = 0; jj < Copy->rows; jj++){
if (jj != 0 && ii != i){
*v = Copy->numbers[jj][ii];
v ++;
}
}
}
Submat = matCreator(ncol,ncol,cv);
det += matDet(Submat)*Copy->numbers[i][0]*pow(-1,i);
freee(Submat);
}

return det;

}

@nhomble
Copy link
Owner

nhomble commented Mar 11, 2021

thanks @miguemorales for catching an issue. Do you have an example matrix I can use to reproduce? I've slowly been adding tests as bugs arise. And are you interested in create a pr?

@miguemorales
Copy link
Author

yes, any matrix that contain zeros in the main diagonal, you can try. what is a pr? im not use to code in git hehe

@nhomble
Copy link
Owner

nhomble commented Mar 12, 2021

oh no worries

  1. fork this repo
  2. checkout the code to your own machine
  3. create the change, push to your fork
  4. then github will allow you to create a pull request from your fork to this repo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants