Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

Approximation of Sin(x) using taylor series in PYTHON

$
0
0

I need to get the approximation of sin(x) using Taylor expansion:

Taylor Expansion Image

Here is the Code:

def factorial(number):    # Factorial Function    s = 1    for k in range(1, number):        s *= k    return sceta = eval(input("Enter angle of sin: "))x = (ceta * 3.14) / 360  # Change from degree to radiann = 15sin = xmult = -1for i in range(3, n+1, 2):   # The 2 step will skip from 3 to 5 to 7 and so on until 15.    sin += (x ** i) / factorial(i) * mult    mult = mult * -1print("sin of", ceta, "is", sin)

The factorial function works fine, the problem is in the for loop, but I cannot find it.

I entered sin( 30 ) in the RUN, but it gives me 0.258 instead of 0.5


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>