Original Post
🔒 Locked
matrix library
Advertisement
From what I've read the standard method of solving a system of linear equations is guassian elimination:
http://mathworld.wolfram.com/GaussianElimination.html
However, if you have a determinant finding method it's very easy to use Cramer's rule(though slower) :
http://mathworld.wolfram.com/CramersRule.html
I do have a method for determinant you can have a look at:
There are some notable problems with this method. Due to the fact that it uses elimination it won't work when elimination is impossible(like when your equations contain several zeros). And....I have more to say about this but I've got class in 15 minutes so I'll have to finish later.
http://mathworld.wolfram.com/GaussianElimination.html
However, if you have a determinant finding method it's very easy to use Cramer's rule(though slower) :
http://mathworld.wolfram.com/CramersRule.html
I do have a method for determinant you can have a look at:
//returns the determinant of a square matrixpublic static double det(double matrix[][]){ double m[][] = new double[matrix.length][matrix.length] ; int k=0,j,l,n=m.length ; double a ; //copies matrix so original is unchanged by row operations for(k=0;k<m.length;k++){ for(j=0;j<m.length;j++){ m[k][j] = matrix[k][j] ; } } for(k=0;k<n-1;k++){//row being added to other rows for(j=k+1;j<n;j++){//row having row added to it a = -m[j][k]/m[k][k] ; for(l=0;l<n;l++){//loop through variables in row and add other row m[j][l]+=m[k][l]*a ; } } } a = 1 ; for(k=0;k<n;k++){//multiplies principal diagonal a*=m[k][k] ; } return a ; }There are some notable problems with this method. Due to the fact that it uses elimination it won't work when elimination is impossible(like when your equations contain several zeros). And....I have more to say about this but I've got class in 15 minutes so I'll have to finish later.
Quote:
Original post by Alrecenk
There are some notable problems with this method. Due to the fact that it uses elimination it won't work when elimination is impossible(like when your equations contain several zeros). And....I have more to say about this but I've got class in 15 minutes so I'll have to finish later.
The most notable problem is that the code will fail when m[0][0] = 0. For the current column being processed, an implementation needs to find the row entry of largest magnitude and "swap" that row into the pivot position (the swap could actually be pointer swapping, depending on how you store your matrix data). The usual recommendation on solving linear systems, though, is to use Gaussian elimination with full pivoting.
Yeah, you can swap the rows to fix some of the problems. Also, that code is in java. Another thing I wanted to mention is that the first part of the guassian elimination is to get rid of the bottom left half of the matrix which can be done a lot like in the method I posted earlier(with swapping if necessarry).
I usually try not to post code because I tend to have code that doesn't account for all cases and if I don't point out all the errors someone else will(as they should I suppose). Though I went ahead and posted some this time because the OP didn't seem interested in working from scratch:
I usually try not to post code because I tend to have code that doesn't account for all cases and if I don't point out all the errors someone else will(as they should I suppose). Though I went ahead and posted some this time because the OP didn't seem interested in working from scratch:
Quote:
I´m looking for a high-perfomance matrix library
The OP will probably be interested in Boost.uBLAS.
Quote:
Original post by Alrecenk
From what I've read the standard method of solving a system of linear equations is guassian elimination:
http://mathworld.wolfram.com/GaussianElimination.html
However, if you have a determinant finding method it's very easy to use Cramer's rule(though slower) :
http://mathworld.wolfram.com/CramersRule.html
Actually, neither of those is good for large systems. Cramer's rule becomes prohibitively expense, and is going to be slower than any other system out there for n > 4 (or maybe 5 or 6 with vectorized processors). Gaussian Elimination fails due to loss of precision for large systems. Iterative methods and specialized techniques for things like tridiagonal or pentadiagonal systems are better for large systems.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement