Advertisement
cacodemon665

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

Dec 11th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include "pch.h" //для версий вижлы старше последних версий 2017 здесь должно быть #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. typedef double(*uf)(double, double, int &);
  9. void tabl(double, double, double, double, uf);
  10. double y(double, double, int &);
  11. double s(double, double, int &);
  12.  
  13. int main()
  14. {
  15.     cout << setw(8) << "x" << setw(15) << "y(x)" << setw(10) << "k" << endl;
  16.     tabl(-0.9, 0.9, 0.1, 1e-4, y);
  17.     cout << endl;
  18.     cout << setw(8) << "x" << setw(15) << "s(x)" << setw(10) << "k" << endl;
  19.     tabl(-0.9, 0.9, 0.1, 1e-4, s);
  20.     return 0;
  21. }
  22.  
  23. void tabl(double a, double b, double h, double eps, uf fun)
  24. {
  25.     int k = 0; double sum;
  26.     for (double x = a; x < b + h / 2; x += h)
  27.     {
  28.         sum = fun(x, eps, k);
  29.         cout << setw(8) << x << setw(15) << sum << setw(10) << k << endl;
  30.     }
  31. }
  32.  
  33. double y(double x, double eps, int &k)
  34. {
  35.     return 0.5 * log((1 + x) / (1 - x));
  36. }
  37.  
  38. double s(double x, double eps, int &k)
  39. {
  40.     double a = x, b = 1, sum = 0;
  41.     k = 1;
  42.    
  43.     while (fabs(a / b) >= eps)
  44.     {
  45.         sum += a / b;
  46.         b += 2;
  47.         a *= pow(x, 2);
  48.         k++;
  49.     }
  50.     return sum;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement