Advertisement
Guest User

Untitled

a guest
May 27th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. double f(double x){
  7. return 2*sqrt(fabs(1-(x-1)*(x-1)));
  8. }
  9. void trapezoid(double a,double b, int n)
  10. {
  11. double pole = 0.0;
  12. double x1 = a;
  13. double x2 = (b-a)/n;
  14. for(int i = 0; i < n; i++)
  15. {
  16. pole += (f(x1)+f(x2))*((b-a)/n)*0.5;
  17. x1 = x1+((b-a)/n);
  18. x2 = x2+((b-a)/n);
  19. cout << pole << endl;
  20. }
  21. }
  22. void midpoint(double a,double b, int n)
  23. {
  24. double pole = 0.0;
  25. double x2 = (b-a)/n;
  26. for(int i = 0; i < n; i++)
  27. {
  28. pole += ((b-a)/n)*f((i+1)*(b-a)/n-0.5*(b-a)/n);
  29. cout << pole << endl;
  30. }
  31.  
  32. }
  33. int main()
  34. {
  35. midpoint(0,2, 1000);
  36. system("PAUSE");
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement