SHARE
TWEET

Untitled

a guest Mar 25th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. double gaussKincaid(double b[], const double a[][4], int iterMax){
  2.  
  3.     double x[4] = {1.,1.,1.,1.};
  4.     double estimatorVal = 1.;
  5.     double reziduumVal = 1.;
  6.     double x2[4];
  7.  
  8.     int k=0;
  9.     while ((k<iterMax) && (fabs(estimatorVal)>=e) && (fabs(reziduumVal)>e)){
  10.  
  11.         for (int i=0;i<n;i++){
  12.             x[i] = b[i];
  13.             for (int j=0;j<n;j++){
  14.                 if(i!=j){
  15.                     x[i] -= a[i][j]*x[j];
  16.                 }
  17.             }
  18.             x[i]/=a[i][i];
  19.             x2[i] = x[i+1];
  20.         }
  21.        
  22.         double x3[n];
  23.         for (int i=0; i<4;i++){
  24.             x3[i] = fabs(x[i+1] - x2[i]);
  25.         }  
  26.  
  27.         double max = x3[0];
  28.         for (int i=1;i<4;i++){
  29.             if (x3[i] > max){
  30.                 max = x3[i];
  31.             }
  32.         }
  33.  
  34.         estimatorVal = max;
  35.  
  36.         std::cout << "\niteracja: " << k+1 << std::endl;
  37.  
  38.         for (int i=0;i<4;i++){
  39.             std::cout << x[i] << " ";
  40.         }  
  41.  
  42.         reziduumVal = reziduum(x,b,a);
  43.         std::cout << "\nestymator: " << estimatorVal
  44.         //estimator(x2,x)
  45.         << " reziduum: " <<
  46.         reziduumVal;
  47.         std::cout << "\n";
  48.  
  49.         k++;
  50.     }
  51. }
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