MaxiBarometer

solve LGS dumb

Jul 25th, 2021 (edited)
902
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static double[] solveDumb(double[][] A, double[] b) {
  2.     final double speed = 0.1;
  3.     double[] x = DoubleStream.generate(() -> 0).limit(b.length).toArray();
  4.     boolean done = false;
  5.     outer:
  6.     while (!done) {
  7.         done = true;
  8.         for (int i = 0; i < b.length; ++i) {
  9.             for (int j = 0; j < b.length; ++j) {
  10.                 double result = 0;
  11.                 for (int k = 0; k < b.length; ++k)
  12.                     result += A[i][k] * x[k];
  13.                 double error = b[i] - result;
  14.                 if (!isZero(error) && !isZero(A[i][j])) {
  15.                     done = false;
  16.                     x[j] += speed * error / A[i][j];
  17.                 }
  18.             }
  19.         }
  20.     }
  21.     return x;
  22. }
RAW Paste Data