Skip to content

Instantly share code, notes, and snippets.

@AFAgarap
Created May 20, 2016 05:59
Show Gist options
  • Save AFAgarap/921938815cf067d8d00c3ec0fd3a87fb to your computer and use it in GitHub Desktop.
Save AFAgarap/921938815cf067d8d00c3ec0fd3a87fb to your computer and use it in GitHub Desktop.
Maclaurin series for sin(x)
def main():
print("\t\t\t10th degree of Maclaurin series, sin(x)")
x = float(input("Enter value of x (in Radians): "))
answer = x; i = 1; j = 1
while(i < 10):
if(i == 1):
answer -= (x ** (j + 2)) / factorial(j + 2)
elif(i % 2 == 0):
answer += (x ** (j + 2)) / factorial(j + 2)
elif(i % 2 != 0):
answer -= (x ** (j + 2)) / factorial(j + 2)
i += 1; j += 2
print(answer)
def factorial(number):
return 1 if (number == 0) else (number * factorial(number - 1))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment