Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package gauss;
- /**
- * Implementación algoritmo del método de Gauss.
- *
- * @author Lluís Camino
- */
- public class Gauss {
- public static void main(String[] args) {
- int[][] a = {
- {1, 1, -2},
- {2, -1, 4},
- {2, -1, -6}
- };
- int[] b = {9, 4, -1};
- imprimirSistema("Original", a, b);
- metodoGauss(a, b);
- }
- public static void metodoGauss(int[][] a, int[] b) {
- for (int k = 0; k < a.length - 1; k++) {
- for (int i = k + 1; i < a.length; i++) {
- int m = a[i][k] / a[k][k];
- a[i][k] = 0;
- for (int j = k + 1; j < a.length; j++) {
- a[i][j] -= m * a[k][j];
- }
- b[i] -= m * b[k];
- }
- }
- imprimirSistema("Reducida", a, b);
- }
- public static void imprimirSistema(String texto, int[][] a, int[] b) {
- System.out.println(texto + ":");
- for (int i = 0; i < a.length; i++) {
- for (int j = 0; j < a[0].length; j++) {
- System.out.print(a[i][j] + " ");
- }
- System.out.println("| " + b[i]);
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment