Guest User

Untitled

a guest
Nov 12th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. double MyCos(double, double);
  8. double fact(int);
  9. int OneP(int);
  10.  
  11. int main()
  12. {
  13. setlocale(LC_ALL, "ru");
  14. double eps, d, x, x_start, x_end, dx, x_ideal;// невязка, погрешность - остановка расчета, начальный х, конечный х,
  15. //шаг вычисления, х для вычисления значений различной точностью
  16. while (true)
  17. {
  18. cout << "Введите точность эпсилон: ";
  19. cin >> eps;
  20. if (eps <= 0)
  21. {
  22. cout << "Точность должна быть вещественным положительным числом" << endl;
  23. system("pause");
  24. return 0;
  25. }
  26.  
  27. cout << "Введите начальный x_start: ";
  28. cin >> x_start;
  29. x = x_start;
  30.  
  31. cout << "Введите конечный x_end: ";
  32. cin >> x_end;
  33.  
  34. cout << "Введите интервал delta_x: ";
  35. cin >> dx;
  36.  
  37. if (dx <= 0 || eps < 0)
  38. {
  39. cout << "Введите верные данные" << endl;
  40. system("pause");
  41. system("cls");
  42. }
  43.  
  44. else if (x_start >= x_end)
  45. {
  46. printf(" ______________ ___________________ ____________________ ______________ n");
  47. printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
  48. printf("| | | | |n");
  49. x <= x_end + pow(10, -15);////////------
  50. double MC = MyCos(x, eps) * MyCos(x, eps);
  51. double XD = x * cos(3 * x) * x * cos(3 * x);
  52. d = sqrt(fabs(MC - XD));////////////////////////////////////////////////////////
  53. printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
  54.  
  55.  
  56. printf("|______________|___________________|____________________|______________|n");
  57. break;
  58. }
  59.  
  60. else
  61. {
  62. printf(" ______________ ___________________ ____________________ ______________ n");
  63. printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
  64. printf("| | | | |n");
  65. for (x; x <= x_end + pow(10, -15); x = x + dx)//шаг.
  66. {
  67. double MC = MyCos(x, eps) * MyCos(x, eps);
  68. double XD = x * cos(3 * x) * x * cos(3 * x);
  69. d = sqrt(fabs(MC - XD));
  70. //d = sqrt(fabs(MyCos(x, eps) - x * cos(3 * x)));///////////////////////////////////////////////////
  71. printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
  72.  
  73. }
  74. printf("|______________|___________________|____________________|______________|n");
  75. break;
  76. }
  77. }
  78.  
  79. cout << "Введите x_ideal" << endl;
  80. cin >> x_ideal;
  81.  
  82. printf(" _____________ ___________________ ____________________ ______________ n");
  83. printf("|______eps____|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
  84. printf("| | | | |n");
  85. for (int i = 1; i <= 7; i++)
  86. {
  87. double e = pow(0.1, i);
  88. double MC = MyCos(x_ideal, e) * MyCos(x_ideal, e);
  89. double XD = x_ideal * cos(3 * x_ideal) * x_ideal * cos(3 * x_ideal);
  90. //d = sqrt(fabs(MyCos(x_ideal, e) - x_ideal * cos(3 * x_ideal)));
  91. //while (fabsl(MyCos - (x_ideal * cos(3 * x_ideal))) >= eps);
  92. d = sqrt(fabs(MC - XD));
  93. printf("| %9.7f | %15.10f | %15.10f | %f |n", e, MyCos(x_ideal, e), x_ideal*cos(3 * x_ideal), d);
  94. }
  95. printf("|_____________|___________________|____________________|______________|n");
  96.  
  97. system("pause");
  98. return 0;
  99. }
  100.  
  101.  
  102. int OneP(int q)
  103. {
  104. int a = -1;
  105. for (int w = 0; w < q; w++)
  106. {
  107. a = (-1) * a;
  108. }
  109. return a;
  110. }
  111.  
  112.  
  113. double fact(int n)
  114. {
  115. if (n == 0)
  116. {
  117. return 1;
  118. }
  119. if (n > 0)
  120. {
  121. return n * fact(n - 1);
  122. }
  123. }
  124.  
  125.  
  126. double MyCos(double x, double eps)
  127. {
  128. double sum = 0, a;
  129.  
  130. for (int k = 0; fabs(OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k) + OneP(k) * pow(3, 2 * k + 2) * pow(x, 2 * k + 3) / fact(2 * k + 2)) > eps; k++)
  131. {
  132. a = OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k);
  133. sum = sum + a;
  134. }
  135. return sum;
  136. }`#include "pch.h"
  137. #include <iostream>
  138. #include <math.h>
  139.  
  140. using namespace std;
  141.  
  142. double MyCos(double, double);
  143. double fact(int);
  144. int OneP(int);
  145.  
  146. int main()
  147. {
  148. setlocale(LC_ALL, "ru");
  149. double eps, d, x, x_start, x_end, dx, x_ideal;// невязка, погрешность - остановка расчета, начальный х, конечный х,
  150. //шаг вычисления, х для вычисления значений различной точностью
  151. while (true)
  152. {
  153. cout << "Введите точность эпсилон: ";
  154. cin >> eps;
  155. if (eps <= 0)
  156. {
  157. cout << "Точность должна быть вещественным положительным числом" << endl;
  158. system("pause");
  159. return 0;
  160. }
  161.  
  162. cout << "Введите начальный x_start: ";
  163. cin >> x_start;
  164. x = x_start;
  165.  
  166. cout << "Введите конечный x_end: ";
  167. cin >> x_end;
  168.  
  169. cout << "Введите интервал delta_x: ";
  170. cin >> dx;
  171.  
  172. if (dx <= 0 || eps < 0)
  173. {
  174. cout << "Введите верные данные" << endl;
  175. system("pause");
  176. system("cls");
  177. }
  178.  
  179. else if (x_start >= x_end)
  180. {
  181. printf(" ______________ ___________________ ____________________ ______________ n");
  182. printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
  183. printf("| | | | |n");
  184. x <= x_end + pow(10, -15);////////------
  185. double MC = MyCos(x, eps) * MyCos(x, eps);
  186. double XD = x * cos(3 * x) * x * cos(3 * x);
  187. d = sqrt(fabs(MC - XD));////////////////////////////////////////////////////////
  188. printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
  189.  
  190.  
  191. printf("|______________|___________________|____________________|______________|n");
  192. break;
  193. }
  194.  
  195. else
  196. {
  197. printf(" ______________ ___________________ ____________________ ______________ n");
  198. printf("|_______x______|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
  199. printf("| | | | |n");
  200. for (x; x <= x_end + pow(10, -15); x = x + dx)//шаг.
  201. {
  202. double MC = MyCos(x, eps) * MyCos(x, eps);
  203. double XD = x * cos(3 * x) * x * cos(3 * x);
  204. d = sqrt(fabs(MC - XD));
  205. //d = sqrt(fabs(MyCos(x, eps) - x * cos(3 * x)));///////////////////////////////////////////////////
  206. printf("| %10.6f | %15.10f | %15.10f | %f |n", x, MyCos(x, eps), x*cos(3 * x), d);
  207.  
  208. }
  209. printf("|______________|___________________|____________________|______________|n");
  210. break;
  211. }
  212. }
  213.  
  214. cout << "Введите x_ideal" << endl;
  215. cin >> x_ideal;
  216.  
  217. printf(" _____________ ___________________ ____________________ ______________ n");
  218. printf("|______eps____|___MyFunction(x)___|_____x*cos(3*x)_____|_______d______|n");
  219. printf("| | | | |n");
  220. for (int i = 1; i <= 7; i++)
  221. {
  222. double e = pow(0.1, i);
  223. double MC = MyCos(x_ideal, e) * MyCos(x_ideal, e);
  224. double XD = x_ideal * cos(3 * x_ideal) * x_ideal * cos(3 * x_ideal);
  225. //d = sqrt(fabs(MyCos(x_ideal, e) - x_ideal * cos(3 * x_ideal)));
  226. //while (fabsl(MyCos - (x_ideal * cos(3 * x_ideal))) >= eps);
  227. d = sqrt(fabs(MC - XD));
  228. printf("| %9.7f | %15.10f | %15.10f | %f |n", e, MyCos(x_ideal, e), x_ideal*cos(3 * x_ideal), d);
  229. }
  230. printf("|_____________|___________________|____________________|______________|n");
  231.  
  232. system("pause");
  233. return 0;
  234. }
  235.  
  236.  
  237. int OneP(int q)
  238. {
  239. int a = -1;
  240. for (int w = 0; w < q; w++)
  241. {
  242. a = (-1) * a;
  243. }
  244. return a;
  245. }
  246.  
  247.  
  248. double fact(int n)
  249. {
  250. if (n == 0)
  251. {
  252. return 1;
  253. }
  254. if (n > 0)
  255. {
  256. return n * fact(n - 1);
  257. }
  258. }
  259.  
  260.  
  261. double MyCos(double x, double eps)
  262. {
  263. double sum = 0, a;
  264.  
  265. for (int k = 0; fabs(OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k) + OneP(k) * pow(3, 2 * k + 2) * pow(x, 2 * k + 3) / fact(2 * k + 2)) > eps; k++)
  266. {
  267. a = OneP(k + 1) * pow(3, 2 * k) * pow(x, 2 * k + 1) / fact(2 * k);
  268. sum = sum + a;
  269. }
  270. return sum;
  271. }`
  272.  
  273. sum = 0
  274. item = x
  275. i = 1
  276. do {
  277. item = - item * x * x * 3.0 * 3.0 / (2 * i * (2 * i - 1))
  278. sum += item
  279. i++
  280. } while (fabs(item) >= eps);
Add Comment
Please, Sign In to add comment