High_Light

kvadratnie formuli

Dec 8th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double f2(double x) {
  6.     return x*x;
  7. }
  8. double f3(double x){
  9.     return x*x*x;
  10.  
  11. }
  12.  
  13.  
  14. double integro_l(double (*func) (double), double a, double b, double dx) {
  15.     double S = 0;
  16.     int N = (b - a) / dx;
  17.     for(int i = 0; i < N; i++) {
  18.         S += func(a + i * dx) * dx;
  19.     }
  20.  
  21.     return S;
  22. }
  23. double integro_m(double (*func) (double), double a, double b, double dx) {
  24.     double S = 0;
  25.     int N = (b - a) / dx;
  26.     for(int i = 0; i < N; i++) {
  27.         S += func(a + (i+0.5) * dx) * dx;
  28.     }
  29.  
  30.     return S;
  31. }
  32. double integro_r(double (*func) (double), double a, double b, double dx) {
  33.     double S = 0;
  34.     int N = (b - a) / dx;
  35.     for(int i = 0; i < N; i++) {
  36.         S += func(a + (i+1) * dx) * dx;
  37.     }
  38.  
  39.     return S;
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45.     cout << integro_l(f3, -1, 1, 0.1) << endl;
  46.     cout << integro_m(f3, -1, 1, 0.1) << endl;
  47.     cout << integro_r(f3, -1, 1, 0.1) << endl;
  48.  
  49. }
Add Comment
Please, Sign In to add comment