Skip to content

Instantly share code, notes, and snippets.

@AFAgarap
Created May 20, 2016 05:58
Show Gist options
  • Save AFAgarap/ad81096d309a3d316fbcd972a592ad09 to your computer and use it in GitHub Desktop.
Save AFAgarap/ad81096d309a3d316fbcd972a592ad09 to your computer and use it in GitHub Desktop.
Maclaurin series for cos(x)
def main():
print("\t\t\t10th degree of Maclaurin series, cos(x)")
x = float(input("Enter value of x (in Radians): "))
answer = 1; i = 1; j = 2
while(i < 10 and j <= 10):
if (i % 2 == 0):
answer += (x ** j) / factorial(j)
elif (i % 2 != 0):
answer -= (x ** j) /factorial(j)
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