Advertisement
MaPV

2VP_2_INTEGR

May 31st, 2017
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <conio.h>             
  4. #include <fstream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. double func (double x){
  10.     return sqrt (2 * x + 1);
  11. }
  12.  
  13.  
  14. double Sr_pr (double a,double b,int N){
  15.     double Summ = 0;
  16.     double h = (b - a) / N;
  17.  
  18.     for (int n = 1; n <= N; n++){
  19.         Summ += func (a + h*(2 * n - 1) / 2)*h;
  20.     }
  21.     return Summ;
  22. }
  23.  
  24. double trapeze (double a,double b,int N){
  25.     double Summ = 0;
  26.     double h = (b - a) / N;
  27.  
  28.     for (int n = 1; n <= N; n++){
  29.         Summ += h*(func (a + h*(n - 1)) + func (a + h*n)) / 2;
  30.     }
  31.     return Summ;
  32. }
  33.  
  34. double Simpson (double a,double b,int N){
  35.     double Summ = 0;
  36.     double h = (b - a) / N;
  37.  
  38.     for (int n = 1; n <= N; n++){
  39.         Summ += (func (a + h*(n - 1)) + 4 * func (a + h*(2 * n - 1) / 2) + func (a + h*n))*h / 6;
  40.     }
  41.     return Summ;
  42. }
  43.  
  44. int main (){
  45.     setlocale (LC_ALL,"Russian");
  46.  
  47.     cout.precision (10);
  48.  
  49.     cout << "Прямоуг 20 " << Sr_pr (0,1,20) << "\n";
  50.     cout << "Прямоуг 50 " << Sr_pr (0,1,50) << "\n";
  51.     cout << "Прямоуг 100 " << Sr_pr (0,1,100) << "\n\n";
  52.  
  53.     cout << "Трапеция 20 " << trapeze (0,1,20) << "\n";
  54.     cout << "Трапеция 50 " << trapeze (0,1,50) << "\n";
  55.     cout << "Трапеция 100 " << trapeze (0,1,100) << "\n\n";
  56.  
  57.     cout << "Симпсон 20 " << Simpson (0,1,20) << "\n";
  58.     cout << "Симпсон 50 " << Simpson (0,1,50) << "\n";
  59.     cout << "Симпсон 100 " << Simpson (0,1,100) << "\n\n";
  60.  
  61.     system ("pause");
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement