title: Gauss Seidel Method
body: <p>I wrote a Gauss-Seidel method to calculate the unknown x values of a matrix A. Another methods online seemed to check first if the determinant contains non-zeroes, but other algorithms, including my prof's notes, don't have the verification check. </p>
  
  <p>So I just followed the algorithm that my professor gave in class for now, and I think that the first xNew is correct, because I verified it on my calculator, but my other x values are not updating, can anyone see why?</p>
  
  <pre><code>public static void gaussSeidel(double[][] A, double[] b){
  int count = 0;
  boolean stop = false;
  
  do{
    double[] xNew = new double[b.length]; // x2 = 0, x3 = 0,
    double[] xOld = new double[b.length]; 
  
    for(int i = 0; i &lt; A.length; i++){ 
      double sum = 0.0;
      double sum1 = 0.0;
      for(int j = 0; j &lt; A.length; j++){
  
        if( j != i)
          sum += (A[i][j]*xOld[j]);
  
       sum1 += (A[i][j]*xNew[j]);
      }
  
      xNew[i] = (b[i] - sum - sum1)*(1/A[i][i]);
      System.out.println("X_" + (i+1) + ": " + xNew[i]);
      System.out.println("Error is: " + Math.abs((xNew[i] - xOld[i])));
      System.out.println("");
      count++;
  
      if(Math.abs(xNew[i] - xOld[i]) &gt; EPSILON){
        xNew[i] = xOld[i];
        }
  
      else{
        stop = true;}   
    }
  }while( !stop &amp;&amp; count &lt;= MAX_ITERATIONS);
  }
  </code></pre>
  
  <p>My matrix:<br>
        <code>double[][] a = {{12,-2,1,0,0,0,0,0,0,0,0}, 
  {-2,12,2,1,0,0,0,0,0,0,0}, {1,-2,12,-2,1,0,0,0,0,0,0}, {0,1,-2,12,-2,1,0,0,0,0,0}, 
  {0,0,1,-2,12,2,1,0,0,0,0}, {0,0,0,1,-2,12,-2,1,0,0,0},
  {0,0,0,0,1,-2,12,-2,1,0,0},{0,0,0,0,0,1,-2,12,-2,1,0},
  {0,0,0,0,0,0,1,-2,12,-2,0},{0,0,0,0,0,0,0,1,-2,12,0}};</code></p>
  
  <p>My b values:</p>
  
  <p><code>double[] b = {13.97, 5.93, -6.02, 8.32, -23.75, 28.45, -8.9, -10.5, 10.34, -38.74};</code></p>