Advertisement
Guest User

relaksacyjny

a guest
May 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5. const int n=4;
  6. int iter=30;
  7. int i,j,k;
  8. double sum1,sum2;
  9. double w[n][n];
  10. double z[n];
  11. double x[n]={3,6,4,3};
  12. double x1[n];
  13. float a=1.8;
  14. int main()
  15. {
  16.     ifstream plik("M.txt");
  17.     for(int i=0;i<n;i++){
  18.         for(int j=0;j<n;j++){
  19.             plik>>w[i][j];
  20.         }
  21.     }
  22.     plik.close();
  23.     ifstream plik1("V.txt");
  24.     for(int i=0;i<n;i++){
  25.         plik1>>z[i];
  26.     }
  27.     plik1.close();
  28. //poczatek
  29.     for(int k=0;k<iter;k++){
  30.         sum1=0;
  31.         for(int j=1;j<n;j++){
  32.             sum1=sum1+w[0][j]*x[j];
  33.         }
  34.         x1[0]=sum1+z[0];
  35.         for(int i=1;i<n-1;i++){
  36.             sum1=0;
  37.             for(int j=0;j<i;j++){
  38.                 sum1=sum1+w[i][j]*(x[j]+a*(x1[j]-x[j]));
  39.             }
  40.             sum2=0;
  41.             for(int j=i+1;j<n;j++){
  42.                 sum2=sum2+w[i][j]*x[j];
  43.             }
  44.             x1[i]=sum1+sum2+z[i];
  45.         }
  46.         sum2=0;
  47.         for(int j=0;j<n-1;j++){
  48.             sum2=sum2+w[n-1][j]*(x[j]+a*(x1[j]-x[j]));
  49.         }
  50.         x1[n-1]=sum2+z[n-1];
  51.     for(int i=0;i<n;i++){
  52.         x[i]=x1[i];
  53.     }
  54.     cout<<"interacja:"<<k+1<<endl;
  55. for(int i=0;i<n;i++){
  56.     cout<<x1[i]<<endl;
  57.  
  58. }
  59. }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement