Advertisement
daniv1

а це царський сімпсон

Dec 24th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. // ConsoleApplication49.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <cmath>
  7. double f(double x)  // Ліві частини рівнянь
  8. {
  9.     double y;
  10.     y = x;//           тут потрібно ввести вашу функцію
  11.    
  12.     return y;
  13. }
  14. double sym( int m, double x, double w)
  15. {
  16.     double s;
  17.     s = 0;
  18.     for (int i = 1; i <= m; i++)
  19.     {
  20.         s = s + f(x);
  21.         x = x + w;
  22.  
  23.     }
  24.     return s;
  25. }
  26.  
  27. int main()
  28. {
  29.     double a,b,eps,N;
  30.     std::cout << "vvedit mezi a ta b\n";
  31.     std::cin >> a >> b;
  32.     std::cout << "vvedit tochnist eps\n";
  33.     std::cin >> eps;
  34.     std::cout << "vvedit pochatkovui podil\n";//ну типу наближення(кількість поділів)
  35.     std::cin >> N;
  36.    
  37.     double h = (b - a) / (N);
  38.     double int_new, int_old = 0;
  39.     int_new = h*(f( a) + f( b) + 4 * sym( N, a + h / 2, h) + 2 * sym( N - 1, a + h, h)) / 6;
  40.     while (abs(int_new - int_old) > eps)
  41.     {
  42.         N = N + 1;
  43.         int_old = int_new;
  44.         h = (b - a) / N;
  45.         int_new = h*(f( a) + f( b) + 4 * sym( N, a + h / 2, h) + 2 * sym( N - 1, a + h, h)) / 6;
  46.     }
  47.     std::cout << "znachennja integralu = " << int_new;
  48.     system("pause");
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement