Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- using namespace std;
- double f(double x)
- {
- double fx = 0;
- fx = x;
- return fx;
- }
- /*double S(double m)
- {
- double sum = 0, x, a=0, b=0, h, fx;
- h = (b-a)/(m);
- for(double i = 1; i < m; i++)
- {
- x = a+i*h;
- fx = f(x);
- sum += fx;
- }
- return sum;
- }
- */
- int main()
- {
- double m = 4;
- double sum = 0, a=0, b=1, h, h1;
- double e=0.0001, grl, grl1, sum1=0;
- double x, fx, fx1, fxn, z, col;
- h = (b-a)/(m);
- h1 = (b-a)/(2*m);
- col = m;
- do{
- sum = sum1 = 0;
- h = (b-a)/(m);
- h1 = (b-a)/(2*m);
- for(double i = 1; i < m; i++)
- {
- x = a+i*h;
- fx = f(x);
- sum += fx;
- }
- for(double i = 1; i < 2*m; i++)
- {
- x = a+i*h1;
- fx = f(x);
- sum1 += fx;
- }
- x = a;
- fx1 = f(x);
- x = b;
- fxn = f(x);
- //cout << "S = " << S(m) << endl;
- //cout << "S = " << S(2*m) << endl;
- grl = h*(sum + (fx1 + fxn)/2);
- grl1 = (h1)*(sum1 + (fx1 + fxn)/2);
- z = grl - grl1;
- col *= 2;
- m *= 2;
- }while(fabs(z) > e);
- cout << "I2 = " << grl1 << endl;
- cout << "Col = " << col << endl;
- system ("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement