Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <limits>
  3. #include <tgmath.h>
  4.  
  5. using namespace std;
  6. double triangle (int k_max, double omega, double x)
  7. {
  8. double sum=0;
  9. for (int k=0; k<=k_max; k++)
  10. {
  11. double tmp = (pow(-1,k)*sin((2*k+1)*omega*x))/(pow(2*k+1,2));
  12. sum+=tmp;
  13. }
  14. return sum*8/pow(M_PI,2);
  15. }
  16. double f1(int k_max, double omega, double x,double h)
  17. {
  18. return (triangle(k_max, omega, x+h)- triangle(k_max, omega, x))/h;
  19. }
  20.  
  21. double f2(int k_max, double omega, double x,double h)
  22. {
  23. return (triangle(k_max, omega, x+h)- triangle(k_max, omega, x-h))/(2*h);
  24. }
  25. int main()
  26. {
  27. double h=0.999;
  28. int k;
  29. double omega;
  30. double x;
  31. cout<< "Podaj rzad harmonicznej: ";
  32. cin>>k;
  33. cout<< "Podaj czestotliwosc sygnalu: ";
  34. cin>>omega;
  35. cout<< "Podaj argument x: ";
  36. cin>>x;
  37. cout<<endl<< triangle(k,omega,x)<<endl<<endl;
  38. cout<<f1(k,omega,x,h)<<endl;
  39. cout<<f2(k,omega,x,h)<<endl;
  40.  
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement