Advertisement
noler89

Untitled

Feb 27th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. const double E1 = 0.000001 / 1.2;
  5. const double E2 = 0.000001 / 4.2;
  6. const double E3 = 0.000001 / 3;
  7. const double PI = 3.141592;
  8.  
  9. int fact (int n0);
  10. double sinM (double x0);
  11. double slagsin (double x00, int k00);
  12. int sgn (double x0);
  13. double slagarctg (double x0, int k0);
  14. double arctgM (double x0);
  15. double sqrtM (double x0);
  16.  
  17.  
  18.  
  19. int main () {
  20. double z = 0;
  21. std::cout << "x" << "\t" << "z" << std::endl;
  22. for (double x = 0.01; x <= 0.06; x += 0.005){
  23. z = sqrtM (1 + arctgM (6.4*x + 1.1)) / sinM (2 * x + 1.08);
  24. std::cout << std::fixed << std::setprecision (6) << x << "\t" << z << std::endl;
  25. }
  26. std::cout << "---------------------------------------------" << std::endl;
  27. std::cout << "x" << "\t" << "z" << std::endl;
  28. z = 0;
  29. for (double x = 0.01; x <= 0.06; x += 0.005){
  30. z = sqrt (1 + atan (6.4*x + 1.1)) / sin (2 * x + 1.08);
  31. std::cout << x << "\t" << z << std::endl;
  32. }
  33. system ("pause");
  34. return 0;
  35. }
  36.  
  37.  
  38.  
  39.  
  40. int fact (int n0) {
  41. int c=1;
  42. for (int i = 1; i <= n0; i++)
  43. c *= i;
  44. return c;
  45. }
  46. double slagsin (double x0, int k0) {
  47. return (pow(-1, k0)*pow (x0, 2 * k0 + 1)) / fact (2 * k0 + 1);
  48. }
  49. double sinM (double x0){//E2
  50. int k = 0;
  51. double sinus = 0;
  52. double slag = 0;
  53. do{
  54. slag = slagsin (x0, k++);
  55. sinus += slag;
  56. //std::cout << " C = " << sinus << " slag = " << slag << std::endl;
  57. }
  58. while (fabs(slag)>E2);
  59. return sinus;
  60. }
  61.  
  62.  
  63. int sgn (double x0) {
  64. if (x0 > 0)
  65. return 1;
  66. else
  67. if (x0 == 0)
  68. return 0;
  69. else
  70. return -1;
  71. }
  72. double slagarctg (double x0, int k0) {
  73. if (fabs (x0) < 1)
  74. return (pow (-1, k0)*pow (x0, 2 * k0 + 1)) / (2 * k0 + 1);
  75. else
  76. if (fabs (x0)>=1)
  77. return( pow (-1, k0)*pow (x0, -(2 * k0 + 1))) / (2 * k0 + 1);
  78. }
  79. double arctgM (double x0) {
  80. int k = 0;
  81. double arctag = 0;
  82. double slag = 0;
  83. do{
  84. slag = slagarctg (x0, k++);
  85. arctag += slag;
  86. //std::cout << " C = " << arctag << " slag = " << slag << std::endl;
  87. } while (fabs (slag)>E1);
  88. double arctag1 = arctag;
  89. if (fabs (x0) >= 1)
  90. arctag1 = PI / 2 * sgn (x0) - arctag;
  91. return arctag1;
  92. }
  93.  
  94.  
  95. double sqrtM (double x0) {
  96. double xk = 1;
  97. double xk1 = 1;
  98. do{
  99. xk = xk1;
  100. xk1 = 0.5* (xk + x0 / xk);
  101. //std::cout << "Xk1= " << xk1 << " xk = " << xk << std::endl;
  102. } while (fabs(xk - xk1) > E3);
  103. return xk1;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement