Advertisement
Chieffo

Obliczanie całki metodą trapezu

Nov 5th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. float f(float x)
  6. {
  7. return x*x-4;
  8. }
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14. //metoda trapezu
  15.  
  16. int n;
  17. float h,p,w,a,b;
  18.  
  19. cin>>a;
  20. cin>>b;
  21. cin>>n;
  22.  
  23.  
  24. w=(b-a)/n;
  25. h=0;
  26.  
  27. for(int i=1;i<=n;i++)
  28. {
  29. h=h+f(a+i*w);
  30. }
  31. p=(w/2)*(f(a)+f(b)+2*h);
  32. cout<<p;
  33.  
  34.  
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement