Guest User

Untitled

a guest
Feb 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package gauss;
  2.  
  3. /**
  4. * Implementación algoritmo del método de Gauss.
  5. *
  6. * @author Lluís Camino
  7. */
  8. public class Gauss {
  9.  
  10. public static void main(String[] args) {
  11. int[][] a = {
  12. {1, 1, -2},
  13. {2, -1, 4},
  14. {2, -1, -6}
  15. };
  16. int[] b = {9, 4, -1};
  17. imprimirSistema("Original", a, b);
  18. metodoGauss(a, b);
  19. }
  20.  
  21. public static void metodoGauss(int[][] a, int[] b) {
  22. for (int k = 0; k < a.length - 1; k++) {
  23. for (int i = k + 1; i < a.length; i++) {
  24. int m = a[i][k] / a[k][k];
  25. a[i][k] = 0;
  26. for (int j = k + 1; j < a.length; j++) {
  27. a[i][j] -= m * a[k][j];
  28. }
  29. b[i] -= m * b[k];
  30. }
  31. }
  32.  
  33. imprimirSistema("Reducida", a, b);
  34. }
  35.  
  36. public static void imprimirSistema(String texto, int[][] a, int[] b) {
  37. System.out.println(texto + ":");
  38. for (int i = 0; i < a.length; i++) {
  39. for (int j = 0; j < a[0].length; j++) {
  40. System.out.print(a[i][j] + " ");
  41. }
  42. System.out.println("| " + b[i]);
  43. }
  44. System.out.println();
  45. }
  46. }
Add Comment
Please, Sign In to add comment