Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <limits>
- #include <tgmath.h>
- using namespace std;
- double triangle (int k_max, double omega, double x)
- {
- double sum=0;
- for (int k=0; k<=k_max; k++)
- {
- double tmp = (pow(-1,k)*sin((2*k+1)*omega*x))/(pow(2*k+1,2));
- sum+=tmp;
- }
- return sum*8/pow(M_PI,2);
- }
- double f1(int k_max, double omega, double x,double h)
- {
- return (triangle(k_max, omega, x+h)- triangle(k_max, omega, x))/h;
- }
- double f2(int k_max, double omega, double x,double h)
- {
- return (triangle(k_max, omega, x+h)- triangle(k_max, omega, x-h))/(2*h);
- }
- int main()
- {
- double h=0.999;
- int k;
- double omega;
- double x;
- cout<< "Podaj rzad harmonicznej: ";
- cin>>k;
- cout<< "Podaj czestotliwosc sygnalu: ";
- cin>>omega;
- cout<< "Podaj argument x: ";
- cin>>x;
- cout<<endl<< triangle(k,omega,x)<<endl<<endl;
- cout<<f1(k,omega,x,h)<<endl;
- cout<<f2(k,omega,x,h)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement