code: public static double[] solve(double[] a, double[] b, double[] c, double[] r) {
          if (b[0] == 0.0) {
              throw new IllegalArgumentException("Invalid value of b[0] == 0. The equations should be rewritten as a set of order n - 1.");
          }
  
          int n = a.length;
          double[] u = new double[n];
          double[] gam = new double[n];
  
          double bet = b[0];
          u[0] = r[0] / bet;
  
          for (int j = 1; j < n; j++) {
              gam[j] = c[j - 1] / bet;
              bet = b[j] - a[j] * gam[j];
              if (bet == 0.0) {
                  throw new IllegalArgumentException("The tridagonal matrix is not of diagonal dominance.");
              }
              u[j] = (r[j] - a[j] * u[j - 1]) / bet;
          }
  
          for (int j = (n - 2); j >= 0; j--) {
              u[j] -= gam[j + 1] * u[j + 1];
          }
  
          return u;
      }
docs: Solve the tridiagonal linear set which is of diagonal dominance
  |b<sub>i</sub>| &gt; |a<sub>i</sub>| + |c<sub>i</sub>|.
  <pre>
  | b0 c0  0  0  0 ...                        |
  | a1 b1 c1  0  0 ...                        |
  |  0 a2 b2 c2  0 ...                        |
  |                ...                        |
  |                ... a(n-2)  b(n-2)  c(n-2) |
  |                ... 0       a(n-1)  b(n-1) |
  </pre>
  @param a the lower part of tridiagonal matrix. a[0] is undefined and not
  referenced by the method.
  @param b the diagonal of tridiagonal matrix.
  @param c the upper of tridiagonal matrix. c[n-1] is undefined and not
  referenced by the method.
  @param r the right-hand side of linear equations.
  @return the solution.