Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double f2(double x) {
- return x*x;
- }
- double f3(double x){
- return x*x*x;
- }
- double integro_l(double (*func) (double), double a, double b, double dx) {
- double S = 0;
- int N = (b - a) / dx;
- for(int i = 0; i < N; i++) {
- S += func(a + i * dx) * dx;
- }
- return S;
- }
- double integro_m(double (*func) (double), double a, double b, double dx) {
- double S = 0;
- int N = (b - a) / dx;
- for(int i = 0; i < N; i++) {
- S += func(a + (i+0.5) * dx) * dx;
- }
- return S;
- }
- double integro_r(double (*func) (double), double a, double b, double dx) {
- double S = 0;
- int N = (b - a) / dx;
- for(int i = 0; i < N; i++) {
- S += func(a + (i+1) * dx) * dx;
- }
- return S;
- }
- int main()
- {
- cout << integro_l(f3, -1, 1, 0.1) << endl;
- cout << integro_m(f3, -1, 1, 0.1) << endl;
- cout << integro_r(f3, -1, 1, 0.1) << endl;
- }
Add Comment
Please, Sign In to add comment