Hey everybody I really need help on a problem in a Java code. Any help would be really appreciated. The problem is to :
Write a test program that prompts the user to enter a11, a12, a13, a21, a22, a23, a31, a32, a33 for a matrix and displays its inverse matrix. Here is the sample runs:

Enter a11, a12, a13, a21, a22, a23, a31, a32, a33: 1 2 1 2 3 1 4 5 3

-2 0.5 0.5

1 0.5 -0.5

1 -1.5 0.5

Can any one fill in the blanks and explain please.

This is what i got so far:

import java.util.Scanner;


public class MatrixProblem {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter a11, a12, a13, a21, a22, a23, a31, a32, a33: ");

double[][] A = new double[3][3];

for (int i = 0; i < 3; i++)

for (int j = 0; j < 3; j++)

A[i][j] = input.nextDouble();



double[][] inverseOfA = inverse(A);



printMatrix(inverseOfA);

}



public static void printMatrix(double[][] m) {

// ????

}



public static double[][] inverse(double[][] A) {

double[][] result = new double[A.length][A.length];



// Compute |A|

double determinantOfA = 1; // A[0][0] * A[1][1] * A[2][2] * ...;



result[0][0] = (A[1][1] * A[2][2] - A[1][2] * A[2][1]) / determinantOfA;

result[0][1] = 1; // ??

result[0][2] = 1; // ??

result[1][0] = 1; // ??



return result;

}

}

For printing you could use the same looping as you did for reading in the values of the array.

What is the algorithm for the inverse() method?
Can you write a mapping for the 9 elements in the input array to the 9 elements to the output array?
For example:
0,0 => x0,y0
...
2,2 =>x2,y2

If you are going to use determinant to compute inverse matrix, write it down by hand and see how it is done first. Then you should get some idea about what you should proceed...

@glamorhits: This is a direct copy of code that you found here: http://wiki.answers.com/Q/Inverse_of_matrix_in_java

It doesn't seem that you have put any effort of your own into this and simply want others to finish it for you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.