Advertisement
NabilaShova

Gauss-seidel

Nov 7th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. float a[4][5], b[4], x[4];
  6. int i,j,n;
  7. cout << "Enter number of variables: ";
  8. cin>>n;
  9. cout << "Enter the co-efficients: " << endl;
  10. for(i=1; i<=n; i++)
  11. {
  12. for(j=1; j<=n+1; j++)
  13. {
  14. cin>>a[i][j];
  15. }
  16. }
  17. for(i=1; i<4; i++)
  18. {
  19. x[i] = 0;
  20. }
  21. for (i=1; i<=15; i++){
  22. x[1] = (a[1][4] - (a[1][2]*x[2] + a[1][3]*x[3])) / a[1][1];
  23. x[2] = (a[2][4] - (a[2][1]*x[1] + a[2][3]*x[3])) / a[2][2];
  24. x[3] = (a[3][4] - (a[3][1]*x[1] + a[3][2]*x[2])) / a[3][3];
  25. cout <<"Iteration : "<<i<<" "<<endl
  26. << "x : " << x[1] << " ; y : " << x[2] << " ; z : " << x[3] <<endl;
  27. }
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement