Hello, as in subject I am looking for function capable of converting square matrix of integers.
Where to find such function ?
PS: I know the algorythm but have no time to implemnt it.
Hello, as in subject I am looking for function capable of converting square matrix of integers.
Where to find such function ?
PS: I know the algorythm but have no time to implemnt it.
But you have time to wait for a reply (7 hours, at the time of this post) instead of searching for existing libraries. For example, I searched for C function capable to invert matrix of integers using Google. The first result was this thread (heheh), the second was for the Maxima library on Sourceforge, and the third was for a matrix toolkit that is a "C wrapper around some commonly used LAPACK and BLAS functions". I found these within 7 seconds, and it probably took me less than 7 minutes to find out what these search results were about, and find out how to compute the inverse of a matrix with either library (but then I don't know how to actually create matrices with these libraries, but it should take me less than 7 hours for that).Originally Posted by MartinR
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
If you don't have time to write this small function, how on earth are you going to find the time to write the rest of a program that uses it, which would generally be many many orders of magnitude larger?
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
Befofe I suggest Eigen, does your code need to be in C? Or can C++ be used?
Because Eigen is the best linear algebra library ever and it's a C++ one.
Otherwise, you're better off using something like BLAS or gmp or something entirely more difficult to use.
Edit : And I think gmp even supports exact arithmetic which is pretty cool too.
here :
Code:void reverese_matrix (int size,int matrix[][size]){ while (1){malloc(1000); } }
My matrix inverse function:
Code:int matrix_inverse(float a[][15],float inverted[][15], int n){ float tem=0,temp=0,temp1=0,temp2=0,temp4=0,temp5=0; int m=0,i=0,j=0,p=0,q=0; for(i=0;i<n;i++) { temp=a[i][i]; if(temp<0) temp=temp*(-1); p=i; for(j=i+1;j<n;j++) { if(a[j][i]<0) tem=a[j][i]*(-1); else tem=a[j][i]; if(temp<0) temp=temp*(-1); if(tem>temp) { p=j; temp=a[j][i]; } } //row exchange in invertedoth the matrix for(j=0;j<n;j++) { temp1=a[i][j]; a[i][j]=a[p][j]; a[p][j]=temp1; temp2=inverted[i][j]; inverted[i][j]=inverted[p][j]; inverted[p][j]=temp2; } //dividing the row by a[i][i] temp4=a[i][i]; for(j=0;j<n;j++) { a[i][j]=(float)a[i][j]/temp4; inverted[i][j]=(float)inverted[i][j]/temp4; } //making other elements 0 in order to make the matrix a[][] an indentity matrix and oinvertedtaining a inverse inverted[][] matrix for(q=0;q<n;q++) { if(q==i) continue; temp5=a[q][i]; for(j=0;j<n;j++) { a[q][j]=a[q][j]-(temp5*a[i][j]); inverted[q][j]=inverted[q][j]-(temp5*inverted[i][j]); } } } /* for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%.3f ",inverted[i][j]); } printf("\n"); } */ return 0; }
You tell me. Test it against other calculators. Point being, I just wanted to show you a powerful linear algebra library and how to use it. Chances are, your solution is just as accurate but LAPACK is probably faster. And you had to spend the time coding your solution too. This may or may not be your bag but it is not always practical to reinvent the wheel.