03-04-2007, 08:16 PM | #1 |
Java inverse matrix?
Hello i need to get the inverse matrix for a 3x3 3x3 4x4 and 5x5 matrix's can you guys help me? (i need in java)
__________________
Frag=Superczar kissing my shotgun.. Wii code: 1999-5973-3442-4435 Brawl: 3050-7344-2657 |
|
03-04-2007, 09:12 PM | #2 |
Re: Java inverse matrix?
Matrices are hard to invert, generally.
I would suggest implementing something like Gaussian Elimination, which is illustarted for finding inverses here. There is also the LU decomposition method, which is supposedly the most used method for computers, but I don't understand it. I haven't studied matrices other than random glimpses in books from time to time, so don't trust me too much.
__________________
"A fool sees not the same tree that a wise man sees." - William Blake |
|
03-05-2007, 05:00 AM | #3 |
Re: Java inverse matrix?
Inverting 3x3 matrices can still be done by hand (see http://mathworld.wolfram.com/MatrixInverse.html).
Everything higher than that has to be done as mentioned by phreak. |
|
10-14-2009, 11:20 PM | #4 |
Re: Java inverse matrix?
Hay, here is my java method for calculating inverse matrix with Gauss-Jordan Method:
Code:
public double[][] inverz_matrike(double[][]in){ int st_vrs=in.length, st_stolp=in[0].length; double[][]out=new double[st_vrs][st_stolp]; double[][]old=new double[st_vrs][st_stolp*2]; double[][]new=new double[st_vrs][st_stolp*2]; for (int v=0;v<st_vrs;v++){//ones vector for (int s=0;s<st_stolp*2;s++){ if (s-v==st_vrs) old[v][s]=1; if(s<st_stolp) old[v][s]=in[v][s]; } } //zeros below the diagonal for (int v=0;v<st_vrs;v++){ for (int v1=0;v1<st_vrs;v1++){ for (int s=0;s<st_stolp*2;s++){ if (v==v1) new[v][s]=old[v][s]/old[v][v]; else new[v1][s]=old[v1][s]; } } old=prepisi(new); for (int v1=v+1;v1<st_vrs;v1++){ for (int s=0;s<st_stolp*2;s++){ new[v1][s]=old[v1][s]-old[v][s]*old[v1][v]; } } old=prepisi(new); } //zeros above the diagonal for (int s=st_stolp-1;s>0;s--){ for (int v=s-1;v>=0;v--){ for (int s1=0;s1<st_stolp*2;s1++){ new[v][s1]=old[v][s1]-old[s][s1]*old[v][s]; } } old=prepisi(new); } for (int v=0;v<st_vrs;v++){//rigt part of matrix is invers for (int s=st_stolp;s<st_stolp*2;s++){ out[v][s-st_stolp]=new[v][s]; } } return out; } public double[][] prepisi(double[][]in){ double[][]out=new double[in.length][in[0].length]; for(int v=0;v<in.length;v++){ for (int s=0;s<in[0].length;s++){ out[v][s]=in[v][s]; } } return out; } |
|
10-15-2009, 03:31 PM | #5 | |
|
Re: Java inverse matrix?
Quote:
If so then cool, I'm not a fan of Java though. |
|
Bookmarks |
|
|