Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: need help solving Gaussian method for inverse

1. ## need help solving Gaussian method for inverse

i got some code but its not working or compiling. i need to use this code to find inverse of any size matrix. specific help would be appreciated. here is my code:

public static double[][] GaussianEliminverse(double[][] A,int B)
{
double[][] b = new double[B][B];
for (int row = 0; row < B; row++) {
for (int col = 0; col < B; col++) {
if (row == col) {
b[row][col] = 1;
} else {
b[row][col] = 0;
}
}
}

double pivot, factor;
int i;
int j;
int k;

int n = b.length;

for (i = 0; i < n; i++) {
pivot = A[i][i];

for (j = 0; j < n; j++)
A[i][j] = A[i][j] / pivot;

b[i][j] = b[i][j] / pivot;

for (k = 0; k < n; k++) {
if (k != i) {
factor = A[k][i];

for (j = 0; j < n; j++)
A[k][j] = A[k][j] - factor * A[i][j];

b[k][j] = b[k][j] - factor * b[i][j];
}
}
}
for (int row = 0; row < b.length; row++) {
for (int col = 0; col < b[row].length; col++) {
System.out.print(b[row][col] + " ");
}
System.out.println();
}
return (b);
} 3. ## Re: need help solving Gaussian method for inverse 