// GaussianElimination.java // David Kosbie, 15-111/AB, Spring 2007 /* Standard disclaimer: As usual with sample code designed in class to demonstrate specific issues, the style may not be perfect (it is especially lacking comments and some top-down design, and as we've not yet reviewed classes, it's lacking those, too!), and there may even be a bug or two lurking in the code! To understand the algorithm used here, please see the class notes from today's lecture (31-Jan-2007). They contain a detailed explanation. */ import java.util.*; public class GaussianElimination { // This is the problem we solved in class private static double[][] problem1 = { // x = 1, y = 2, z = 3 { 1, 2, 3, 14 }, // 1x + 2y + 3z = 14 { 1, -1, 1, 2 }, // 1x - 1y + 1z = 2 { 4, -2, 1, 3 } // 4x - 2y + 1z = 3 }; // This is the problem solved in the lecture notes private static double[][] problem2 = { // x = 1, y = 2, z = 3 { 2, 3, -4, -4 }, // 2x + 3y - 4z = -4 { 1, -2, 1, 0 }, // 1x - 2y + 1z = 0 {-1, 1, 2, 7 } // -1x + 1y + 2z = 7 }; public static void solve(double[][] c, int row) { int rows = c.length; int cols = rows + 1; // 1. set c[row][row] equal to 1 double factor = c[row][row]; for (int col=0; col 3) ? ('z' - (rows-1)) : 'x'); System.out.println("Solution:\n"); for (int row=0; row