SHARE
TWEET

Untitled

a guest Nov 14th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static void gaussSeidel(double[][] A, double[] b){
  2.         boolean stop = false;
  3.  
  4.         double[] xNew = new double[b.length];
  5.         double[] xOld = new double[b.length];
  6.         double sum = 0.0;
  7.         double sum1 = 0.0;
  8.  
  9.         do{
  10.             for(int i = 0; i < A.length; i++){
  11.                 for(int j = 0; j < A.length; j++){
  12.  
  13.                     if( j != i)
  14.                         sum += (A[i][j]*xOld[j]);
  15.  
  16.                     sum1 += (A[i][j]*xNew[j]);
  17.                 }
  18.  
  19.                 xNew[i] = (b[i] - sum - sum1)*(1/A[i][i]);
  20.                 System.out.println("X" + (i+1) + ": " + xNew[i]);
  21.                 System.out.println("");
  22.  
  23.                 if(Math.abs(xNew[i] - xOld[i]) > 0.001){
  24.                      xNew[i] = xOld[i];
  25.                     //System.out.println("NEW :" +  Arrays.toString(xNew));
  26.                     //System.out.println("OLD : " + Arrays.toString(xOld));
  27.                 } else{
  28.                     stop = true;}
  29.             }
  30.         }while( !stop);
  31.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top