Last active
August 29, 2015 14:14
-
-
Save honux77/409fdecf1cbec4264693 to your computer and use it in GitHub Desktop.
math sine implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| def fact(x): | |
| if x == 1: | |
| return 1 | |
| else: | |
| return x * fact(x-1); | |
| def mysin(x): | |
| return x - math.pow(x,3)/fact(3) + pow(x,5)/fact(5) - pow(x,7)/fact(7) \ | |
| + math.pow(x,9)/fact(9) | |
| print mysin(3.14/2), math.sin(3.14/2) | |
| print mysin(3.14/4), math.sin(3.14/4), 1/math.sqrt(2) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
12:03 $ python math_test.py
1.00000320587 0.999999682932
0.706825182846 0.706825181105 0.707106781187