Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <locale.h>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double moya(double x) {
  7.     return sqrt(1 - x * x);
  8. }
  9.  
  10. double Integrate(double a, double b, int n) {
  11.     double ans = 0;
  12.     double temp = (b - a) / n;
  13.     for (double i = 0; i < n; ++i) {
  14.         double xi = a + temp * i;
  15.         double xi1 = a + temp * (i + 1);
  16.         ans += moya((xi + xi1) / 2) * (xi1 - xi);
  17.     }
  18.     return ans;
  19. }
  20.  
  21. int main() {
  22.     setlocale(LC_ALL, "Rus");
  23.     double a, b;
  24.     cout << "Введите пределы интегрирования:(в моём задании от 0 до 1)\n";
  25.     cin >> a >> b;
  26.     double p = 8;
  27.     cout << "интеграл равен pi/4 = " << atan(1) << " - четверть площади круга\n";
  28.     cout << "n:\tI_appr\t\terr_n:\t\ts_n:\n";
  29.     for (int i = 3; i < 16; ++i) {
  30.         auto ans0 = Integrate(a, b, p);
  31.         auto ans1 = abs(atan(1) - ans0);
  32.         auto ans2 = log(ans1) / (log(b - a) - log(p));
  33.         cout << p << "\t" << ans0 << "\t" << ans1 << "\t" << ans2 << "\n";
  34.         p *= 2;
  35.     }
  36.     return 0;  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement