Advertisement
Guest User

Untitled

a guest
Dec 10th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int n = 3;
  8. int m = 3;
  9.  
  10. double e = 0.001;
  11.  
  12. int main()
  13. {
  14. int k = 0;
  15. double A[50][50];
  16. double B[50];
  17. double P2[50];
  18. double P[50][50];
  19.  
  20. A[0][0]=2; A[0][1]=3; A[0][2]=8;
  21. A[1][0]=5; A[1][1]=4; A[1][2]=9;
  22. A[2][0]=2; A[2][1]=1; A[2][2]=3;
  23.  
  24.  
  25. for(int i = 0; i < n; i++)
  26. {
  27. for(int j = 0; j < m; j++)
  28. {
  29. cout << A[i][j]<<" ";
  30. }
  31. cout<<endl;
  32. }
  33.  
  34.  
  35. B[0]=5; B[1]=4; B[2]=5;
  36. P2[0]=0; P2[1]=0; P2[2]=0;
  37. double A1[n][m];
  38. for(int i = 0; i < n; i++)
  39. {
  40.  
  41. for(int j = 0; j < m; j++)
  42. {
  43. if(i==j) A1[i][j] = B[i] / A[i][j];
  44. else A1[i][j] = A[i][j] / A[i][i]*(-1);
  45. }
  46. P[k][i]=P2[i];
  47. }
  48. cout<< endl;
  49. for(int i = 0; i < n; i++)
  50. {
  51. for(int j = 0; j < m; j++)
  52. {
  53. cout << A1[i][j]<<" ";
  54. }
  55. cout<<endl;
  56. }
  57.  
  58. cout << endl;
  59. double sum;
  60.  
  61. do
  62. {
  63. k++;
  64. sum=0;
  65. cout << "N=" << k << endl;
  66. for(int i = 0; i < n; i++)
  67. {
  68. double s=0;
  69. for(int j = 0; j < m; j++)
  70. {
  71. if (i==j) {
  72. s+=A1[i][j];
  73. cout << "+"<<A1[i][j];
  74. }
  75. else {
  76. s+=A1[i][j]*P2[j];
  77. cout <<A1[i][j]<<"*"<<P[k-1][j];
  78. }
  79. P2[i]=s;
  80. }
  81. P[k][i]=P2[i];
  82. cout<<"="<<P[k][i]<<" "<<endl;
  83.  
  84. }
  85. cout <<endl;
  86.  
  87. for (int i = 0; i < n; i++)
  88. {
  89. sum += (P[k][i] - P[k-1][i]) * (P[k][i] - P[k-1][i]);
  90. }
  91. }while(sqrt(sum)>= e);
  92.  
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement