Georgiy031

Untitled

Nov 24th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.60 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. typedef long long ll;
  5. typedef unsigned long long ull;
  6. #define all(x) x.begin(), x.end()
  7. #define rall(x) x.rbegin(), x.rend()
  8. //#define endl '\n'
  9. #define boostIO() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  10. ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
  11.  
  12. double f(double x) {
  13.     return (3 * x - 6) / sqrt(x * x - 4 * x + 5);
  14. }
  15.  
  16. signed main() {
  17.  
  18.     vector<double> y(7);
  19.     double a = -1;
  20.     double b = 1;
  21.    
  22.     for (int i = 0; i <= 6; ++i) {
  23.         double x = a + (b - a) * i / 6;
  24.         y[i] = f(x);
  25.         cout << "f(" << x << ") = " << y[i] << endl;
  26.     }
  27.  
  28.     {
  29.         double sum = 0;
  30.         for (int i = 1; i < 6; ++i) sum += y[i];
  31.         double I = (b - a) / 6 * (accumulate(all(y), 0.0) - (y[0] + y[6]) / 2);
  32.         cout << "I = " << I << endl;
  33.         double del = fabs(-5.2442 - I);
  34.         cout << "d = " << del << endl << endl;
  35.     }
  36.     {
  37.         double q1 = 0, q2 = 0;
  38.         for (int i = 1; i < 6; i += 2) q1 += y[i];
  39.         for (int i = 2; i < 6; i += 2) q2 += y[i];
  40.         double I = (b - a) / (3 * 6) * (y[0] + y[6] + 4 * q1 + 2 * q2);
  41.         cout << "I = " << I << endl;
  42.         double del = fabs(-5.2442 - I);
  43.         cout << "d = " << del << endl << endl;
  44.     }
  45.     {
  46.         vector<double> t(5), A(5);
  47.         t[4] = 0.906179846;
  48.         t[3] = 0.538469310;
  49.         t[2] = 0;
  50.         t[1] = -t[3];
  51.         t[0] = -t[4];
  52.         A[0] = A[4] = 0.236926885;
  53.         A[1] = A[3] = 0.478628670;
  54.         A[2] = 0.568888889;
  55.        
  56.         double sum = 0;
  57.         for (int i = 0; i < 5; ++i) {
  58.             double cur = A[i] * f((a + b) / 2 + (b - a) / 2 * t[i]);
  59.             sum += cur;
  60.         }
  61.  
  62.         double I = (b - a) / 2 * sum;
  63.         cout << "I = " << I << endl;
  64.         double del = fabs(-5.2442 - I);
  65.         cout << "d = " << del << endl;
  66.  
  67.     }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment