guitar-player

taylor.cpp

May 31st, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. //aproxima el sen(30°) por serie de taylor
  2. #include<iostream>
  3. #include<cmath>
  4.  
  5. using namespace std;
  6.  
  7. #define s30 0.5
  8. double const Pi=4*atan(1); // Pi=3.14
  9.  
  10. double diff, expan, x;
  11. int count, k;
  12.  
  13. /*
  14. sin(x) = \sum_{k=0}^{\infty} \frac{(-1)^k x^{1+2k}}{(1+2k)!}
  15. sin(30°) = 0.5     cout << sin(4*PI/180) << endl;
  16. */
  17.  
  18.  
  19. double factorial (int num)
  20. {
  21. if (num==1)
  22. return 1;
  23. return factorial(num-1)*num;
  24. }
  25.  
  26.  
  27. int main()
  28. {
  29.  x = 30*(Pi/180);
  30.  count = 1;
  31.  for(k = 0; k <= 3; k++)
  32.   {
  33.    count++;
  34.    expan += (pow(-1.0,k)*pow(x,(1+2*k)))/(factorial(1+2*k));
  35.    cout << expan << endl;
  36. //   diff = s30 - expan;
  37. //   if ( diff == 1E-9)
  38. //    {
  39. //        cout << count << endl;
  40. //     return 0;
  41. //    }
  42.   }
  43.  
  44.  return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment