Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //aproxima el sen(30°) por serie de taylor
- #include<iostream>
- #include<cmath>
- using namespace std;
- #define s30 0.5
- double const Pi=4*atan(1); // Pi=3.14
- double diff, expan, x;
- int count, k;
- /*
- sin(x) = \sum_{k=0}^{\infty} \frac{(-1)^k x^{1+2k}}{(1+2k)!}
- sin(30°) = 0.5 cout << sin(4*PI/180) << endl;
- */
- double factorial (int num)
- {
- if (num==1)
- return 1;
- return factorial(num-1)*num;
- }
- int main()
- {
- x = 30*(Pi/180);
- count = 1;
- for(k = 0; k <= 3; k++)
- {
- count++;
- expan += (pow(-1.0,k)*pow(x,(1+2*k)))/(factorial(1+2*k));
- cout << expan << endl;
- // diff = s30 - expan;
- // if ( diff == 1E-9)
- // {
- // cout << count << endl;
- // return 0;
- // }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment