import java.util.Scanner; public class Gauss2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); double[][] A; double[] b, x; double pivot, factor; int n; // Number of variables int i, j, k; System.out.print("Number of unknows: "); n = in.nextInt(); // Read in problem size A = new double[n][n]; // Reserve space for coefficient matrix b = new double[n]; // Reserve space for RHS vector // Read in the rows, one row at a time for (i = 0; i < n; i++) { // Read in row i's coefficients for (j = 0; j < n; j++) { System.out.print("A["+i+"]["+j+"] = "); A[i][j] = in.nextDouble(); } // Read in row i's RHS System.out.print("b["+i+"] = "); b[i] = in.nextDouble(); } System.out.println("\nSimultaneous equations:"); Print(A, b); x = MathTools.GaussianElim(A, b); System.out.println("Solution:"); for (i = 0; i < n; i++) System.out.println("x[" + (i+1) + "] = " + x[i]); } public static void Print(double[][] A, double b[]) { int i, j; // Print the equations for (i = 0; i < b.length; i++) { // Print row i for (j = 0; j < b.length; j++) { if ( j != 0 ) System.out.print(" + "); System.out.print(A[i][j] + " x" + (j+1)); } System.out.println(" = " + b[i]); } System.out.println(); } }