Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <math.h>
  3.  
  4. int main(void)
  5. {
  6. const int n=3;
  7. const double w=0.0001;
  8. double a[n][n]={{4.2,-1.7,1.3},
  9. {0,8.5,2.3},
  10. {4.5,-0.5,8.2}};
  11. double b[n]={2.8,-0.6,0.1};
  12. double x[n];
  13.  
  14. int i,j,k;
  15. double c=0, D=0, norm=0;
  16.  
  17.  
  18.  
  19. for(i=0;i<n;i++)
  20. x[i]=0;
  21.  
  22.  
  23. for(k=0; k<100; k++)
  24. {
  25. for (i=0; i<n; i++)
  26. {
  27. norm=0;
  28. c=b[i];
  29. for(j=0; j<n; j++)
  30. {
  31. if(i!=j) c=c-a[i][j]*x[j];
  32. }
  33. c=c/a[i][i];
  34. D=fabs(c-x[i]);
  35. x[i]=c;
  36. if(norm<D) norm=D;
  37. }
  38. printf("k=%d " , k);
  39. printf(" norm=%.1e " , norm);
  40. printf("\n");
  41. if(norm<w)
  42. {
  43. for(i=0;i<n;i++)
  44. {
  45. printf(" x[%d]= %f" ,i+1,x[i]);
  46. printf("\n");
  47. }
  48. return 0;
  49. }
  50. }
  51. printf("ne sosholsia\n");
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement