Advertisement
Guest User

l

a guest
Apr 1st, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cmath>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. double c1(double x) {
  9. return sin(x);
  10. }
  11. double c2(double x) {
  12. return 2*sin(x);
  13. }
  14.  
  15.  
  16. int main()
  17. {
  18. float a, b, h, calka1, calka;
  19. int ilosc;
  20.  
  21.  
  22.  
  23. // przedział
  24. a = 0;
  25. b = 3.14;
  26.  
  27. ilosc = 20;
  28.  
  29. h = (b - a) / (float)ilosc;
  30.  
  31. cout << "krok: h=" << h << endl;
  32.  
  33.  
  34. //trapezy
  35. calka = 0;
  36. for (int i=1; i<ilosc; i++)
  37. {
  38. calka += c2(a + i * h);
  39. }
  40. calka += c2(a) / 2;
  41. calka += c2(b) / 2;
  42. calka *= h;
  43.  
  44. //prostokaty
  45. calka1 = 0;
  46.  
  47. for (int i=1; i<=ilosc; i++)
  48. {
  49. calka1 += c1(a + i*h)*h;
  50. }
  51.  
  52.  
  53.  
  54. cout << "Wynik sin(x): " << calka1 << endl;
  55. cout << "Wynik 2sin(x): " << calka << endl;
  56. cout << "Pole pomiedzy: "<<calka-calka1<< endl;
  57. system("PAUSE");
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement