Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <iomanip>
  4. #include <random>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. setlocale(LC_ALL, "Rus");
  10. double n;
  11. cout << "Введите точность вычисления: ";
  12. cin >> n;
  13.  
  14. while (n < 0.000001 || n > 1)
  15. {
  16. cout << "Веденное не соответствует условию" << "\nВведите точность вычислений: " << endl;
  17. cin >> n;
  18. }
  19.  
  20. //Рандомные числа с промежутком
  21. random_device generator;
  22. uniform_real_distribution<double> distribution(-700, 700); //потому что функция "sinh" не считает > 700
  23. double x = distribution(generator);
  24. cout << "На множестве R выбран x, равный: " << x << "\n";
  25.  
  26. //Подсчёт формулы
  27. double sum = 0.0;
  28. double a = x;
  29. double t = 1;
  30. while (abs(a) >= n)
  31. {
  32. sum += a;
  33. a *= (x * x / ((t + 1) * (t + 2)));
  34. t += 2;
  35. }
  36.  
  37. //Функция, сравнение, погрешность
  38. double func = sinh(x);
  39. double diff = abs(sum - func);
  40. cout << setprecision(ceil(log10(1 / n))) << "Результат функции: " << func <<"\nРезультат просчета ряда: " << sum << endl;
  41. cout << "Погрешность составляет: " << diff << endl;
  42. return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement