Advertisement
cacodemon665

Лаба 8 Вариант 7

Oct 21st, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <iomanip>
  5.  
  6.  
  7. using namespace std;
  8.  
  9.  
  10. typedef double(*uf)(double, double, int &);
  11. void tabl(double, double, double, double, uf);
  12. double y(double, double, int &);
  13. double s(double, double, int &);
  14.  
  15. int main()
  16. {
  17.     cout << setw(8) << "x" << setw(15) << "y(x)" << setw(10) << "k" << endl;
  18.     tabl(-0.5, 0.5, 0.1, 1e-5, y);
  19.     cout << endl;
  20.     cout << setw(8) << "x" << setw(15) << "s(x)" << setw(10) << "k" << endl;
  21.     tabl(-0.5, 0.5, 0.1, 1e-5, s);
  22.     return 0;
  23. }
  24.  
  25. void tabl(double a, double b, double h, double eps, uf fun)
  26. {
  27.     int k = 0; double sum;
  28.     for (double x = a; x < b + h / 2; x += h)
  29.     {
  30.         //таки я столкнулся с таким феноменом что -0,1 + 0.1 != 0
  31.         //а равно 2.7755e-17
  32.         if (fabs(x) < 1e-8)
  33.             x = 0;
  34.  
  35.         sum = fun(x, eps, k);
  36.         cout << setw(8) << x << setw(15) << sum << setw(10) << k << endl;
  37.     }
  38. }
  39.  
  40. double y(double x, double eps, int &k)
  41. {
  42.     double a = (1 + x) / (1 - x);
  43.     return 0.25 * log(a) - 0.5 * atan(x);
  44. }
  45.  
  46. double s(double x, double eps, int &k)
  47. {
  48.     double sum = 0, a = pow(x, 3), b = 3, r = 0;
  49.     k = 1;
  50.     while (fabs(a / b) > eps)
  51.     {
  52.         sum += a / b;
  53.         a *= pow(x, 4);
  54.         b += 4;
  55.         k++;
  56.     }
  57.     return sum;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement