InvMatrix - (a[0[0*a[1[1 a[0[1*a[1[0 for(int r = 0 r <...

This preview shows page 1 - 2 out of 2 pages.

import java.util.*; public class InvMatrix { public static void main (String[] args) { double[][] matrix = new double[3][3]; readMatrix(matrix); inverse(matrix); writeMatrix(matrix); } public static void readMatrix( double[][] a) { Scanner in = new Scanner(System.in); System.out.println("Enter a 3x3 Matrix:"); for (int r = 0; r < a.length; r++) { for (int c = 0; c < a[r].length; c++) a[r][c] = in.nextInt(); } } public static void inverse( double[][] a) { double temp = 1/determinant(a); double[][] inverse = { { (a[1][1]*a[2][2] - a[1][2]*a[2][1] ), (a[0][2]*a[2][1] - a[0][1]*a[2][2] ), (a[0][1]*a[1][2] - a[0][2]*a[1][1] ) }, { (a[1][2]*a[2][0] - a[1][0]*a[2][2] ), (a[0][0]*a[2][2] - a[0][2]*a[2][0] ), (a[0][2]*a[1][0] - a[0][0]*a[1][2] ) }, { (a[1][0]*a[2][1] - a[1][1]*a[2][0] ), (a[0][1]*a[2][0] - a[0][0]*a[2][1]

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture