Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <math.h>
- using namespace std;
- double f(double x){
- return 2*sqrt(fabs(1-(x-1)*(x-1)));
- }
- void trapezoid(double a,double b, int n)
- {
- double pole = 0.0;
- double x1 = a;
- double x2 = (b-a)/n;
- for(int i = 0; i < n; i++)
- {
- pole += (f(x1)+f(x2))*((b-a)/n)*0.5;
- x1 = x1+((b-a)/n);
- x2 = x2+((b-a)/n);
- cout << pole << endl;
- }
- }
- void midpoint(double a,double b, int n)
- {
- double pole = 0.0;
- double x2 = (b-a)/n;
- for(int i = 0; i < n; i++)
- {
- pole += ((b-a)/n)*f((i+1)*(b-a)/n-0.5*(b-a)/n);
- cout << pole << endl;
- }
- }
- int main()
- {
- midpoint(0,2, 1000);
- system("PAUSE");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement