Guest User

Untitled

a guest
Nov 14th, 2019
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void main(String[] args) {
  2. double[][] A = {{2, 0, -1, -2}, {0, 1, 2, -1}, {1, -1, 0, -1}, {-1, 3, -2, 0}}; //Коэф. уравнений
  3. double[] B = {-8, -1, -6, 7}; //Значения
  4.  
  5. ArrayList<Double> xValues = new ArrayList<>(4);
  6.  
  7. for(int i = 0; i < 4; i++) {
  8. xValues.add((double) 0);
  9. }
  10.  
  11. int k = 0;
  12. double prevX = 0;
  13.  
  14. while(xValues.get(4-1) - prevX > 0.000001 || k == 0) {
  15.  
  16. prevX = xValues.get(4-1);
  17.  
  18. System.out.println("k = " + k);
  19. System.out.println();
  20.  
  21. double x = 0;
  22.  
  23. for(int i = 0; i < 4; i++) {
  24.  
  25. for(int j = 0; j < 4; j++) {
  26. x += xValues.get(j) * A[i][j];
  27. }
  28.  
  29. x += B[i];
  30. xValues.set(i,x);
  31. System.out.print("X" + (i+1) +": " + x);
  32. System.out.println();
  33.  
  34. x = 0;
  35. }
  36.  
  37. k++;
  38. }
  39. System.out.println(xValues);
  40. }
RAW Paste Data