Advertisement
Guest User

Gauss

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