Advertisement
Guest User

Untitled

a guest
May 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <string>
  6. #include <sstream>
  7. #include <iomanip>
  8. #include <cmath>
  9. #include <math.h>
  10.  
  11. using namespace std;
  12.  
  13. int count_r = 9;
  14. double eps = 0.001;
  15. double a = 0;//1kek
  16. double b = 0.9;//2
  17.  
  18. double f(double x) {
  19. //return x*x*log(x);
  20. //return 1/(x*x-1);
  21. return x*asin(x);
  22. }
  23.  
  24. double f1(double x) {
  25. return asin(x) + x/sqrt(1-x*x);
  26. }
  27.  
  28. double f2(double x) {
  29. //return (6 * x*x + 2) / (pow(x*x - 1, 3));
  30. return -(x*x - 2.0) / pow((1 - x*x), 1.5);
  31. }
  32.  
  33. int main() {
  34. system("color F2");
  35. ifstream fin("in.txt");
  36. ofstream fout("res.txt");
  37. double x2 = b;
  38. double M = abs(f2(x2));
  39. {
  40.  
  41. cout << "M = " << M << endl;
  42. double h1 = sqrt(eps * 12 / M / abs(b - a));
  43. double h2 = sqrt(eps * 12 / M / abs(b - a));
  44.  
  45. double res1 = 0, res2 = 0;
  46.  
  47. {
  48. cout << "h1 < " << h1 << endl;
  49.  
  50.  
  51. double n = (b - a) / h1;
  52. cout << "n1 ~= " << n << endl;
  53. while ((int)n % 4 != 0) {
  54. n += 1;
  55. }
  56. n = (int(n));
  57. cout << "n1 = " << n << endl;
  58. //n = 32;
  59.  
  60. h1 = (b - a) / n;
  61. cout << "h1 = " << h1 << endl;
  62.  
  63. //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
  64.  
  65. for (int i = 1; i < n; i++) {
  66. res1 += f(a + h1 * i);
  67. }
  68.  
  69. res1 += f(a) / 2 + f(b) / 2;
  70. res1 *= h1;
  71. }
  72. cout << "------------------------------------" << endl;
  73. {
  74. h2 = 2 * h1;
  75. cout << "h < " << h2 << endl;
  76.  
  77. double n = (b - a) / h2;
  78. cout << "n2 ~= " << n << endl;
  79. /*while ((int)n % 4 != 0) {
  80. n += 1;
  81. }*/
  82. n = (int(n));
  83. cout << "n2 = " << n << endl;
  84. //n = 32;
  85.  
  86. h2 = (b - a) / n;
  87. cout << "h2 = " << h2 << endl;
  88.  
  89. //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
  90.  
  91. for (int i = 1; i < n; i++) {
  92. res2 += f(a + h2 * i);
  93. }
  94. res2 += f(a) / 2 + f(b) / 2;
  95. res2 *= h2;
  96. }
  97. cout << "------------------------------------" << endl;
  98.  
  99. cout << "res1 = " << res1 << " " << "res2 = " << res2 << endl;
  100. cout << "delta = " << (res2 - res1) / 3 << '\n';
  101.  
  102. }
  103.  
  104.  
  105.  
  106. {
  107. double h1 = sqrt(eps * 12 / M / abs(b - a));
  108. double h2 = sqrt(eps * 12 / M / abs(b - a));
  109.  
  110. double res1 = 0, res2 = 0;
  111.  
  112. cout << "------------------------------------" << endl;
  113. {
  114. cout << "h1 < " << h1 << endl;
  115.  
  116. double n = (b - a) / h1;
  117. cout << "n1 ~= " << n << endl;
  118. while ((int)n % 4 != 0) {
  119. n += 1;
  120. }
  121. n = (int(n));
  122. cout << "n1 = " << n << endl;
  123. //n = 32;
  124.  
  125. h1 = (b - a) / n;
  126. cout << "h1 = " << h1 << endl;
  127.  
  128. //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
  129. //int m = n / 2;
  130. for (int i = 1; i < n; i++) {
  131. if (i%2 == 0) res1 += f(a + h1 * i);
  132. else res1 += 2*f(a + h1 * i);
  133. }
  134. res1 += f(a) / 2 + f(b) / 2;
  135. res1 *= 2*h1/3;
  136. }
  137. cout << "------------------------------------" << endl;
  138. {
  139. h2 = 2 * h1;
  140. cout << "h < " << h2 << endl;
  141.  
  142.  
  143. double n = (b - a) / h2;
  144. cout << "n2 ~= " << n << endl;
  145. /*while ((int)n % 4 != 0) {
  146. n += 1;
  147. }*/
  148. n = (int(n));
  149. cout << "n2 = " << n << endl;
  150. //n = 32;
  151.  
  152. h2 = (b - a) / n;
  153. cout << "h2 = " << h2 << endl;
  154.  
  155. //cout << "~ = " << (f(a) + f(b))*h / 2 << endl;
  156.  
  157. for (int i = 1; i < n; i++) {
  158. if (i % 2 == 0) res2 += f(a + h2 * i);
  159. else res2 += 2 * f(a + h2 * i);
  160. }
  161. res2 += f(a) / 2 + f(b) / 2;
  162. res2 *= 2 * h2 / 3;
  163. }
  164. cout << "------------------------------------" << endl;
  165.  
  166. cout << "res1 = " << res1 << " " << "res2 = " << res2 << endl;
  167. cout << "delta = " << (res2 - res1) / 3 << '\n';
  168. }
  169. system("pause");
  170. return 0;
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement