I am a technical person but new to python. I like math, science and coding. So here I wrote a small python code to define sine function as a series. (For mathematical definition go here)
Also it gives errors for very high value of x, I'm not sure it's mathematical or a coding issue.
Many Thanks!
#To find sine of any angle in radians from the series expansion of sine function # n indicates the number of terms used from the series expansion for calculation import math def sine(x,n): pmax=2*n+2 #max exponent ans=0 # variable to hold the final answer for i in range(1,pmax,2): if(i%4==1): sign=1 else: sign=-1 ans+=sign*x**i/math.factorial(i) return ans #demo print(sine(6,25))How do you find this code? Can I improve it in any way or is it fine?
Also it gives errors for very high value of x, I'm not sure it's mathematical or a coding issue.
Many Thanks!