i cant think A blog belong to Mohammad Azwan bin Ali. Most of his writings are about his real life story, ideas, thoughts, moderate political views, computer, programming, tips & tricks, particularly in Linux…. and of course it includes some random unspecified crappy stuffs too! Don't forget to check Movies and Junkyard pages out!
note: most of entries is not suitable for faint hearted person or anybody with iq below 100.

c programming: computing sine using triple-angle formula

http://upload.wikimedia.org/math/8/f/e/8feede92bfdb547d1d1c1b4dd581d442.png

* image taken from list of trigonometric identities at Wikipedia.
* simplify above equation to make our life easier, we get


from above equation we can now solve sin(x).

here's a simple solution using recursive loop until angle reach zero value

  1. double cube (double x) {
  2. return x*x*x;
  3. }
  4. double sine (double angle) {
  5. if (angle < 0.00000001) { return angle; }
  6. return 3*(sine (angle/3.0)) - 4*cube(sine (angle/3.0));
  7. }
  8. int main() {
  9. printf("sine(1000): %f\n",sine(1000.0));
  10. return 0;
  11. }
  12.  

the output is: 0.826880


No Comments Yet


There are no comments yet. You could be the first!

Leave a Comment

:D [angely] [argh] [blindfold] [color] [cry] [bye] [cutie] [dance] [flirt] [ghost] [thumb] >_< hmmm more »