Write a recursive function that sums up the first n terms of
Write a recursive function that sums up the first n terms of the Taylor series for cos x. Def rcos(j, x, n): # Note, j keeps track of where you are in the recursion. x and n never change throughout the recursion. if j==0: return # Here you put a number. else: return # Here we put the recursive call. rcos(, pi/4., ) # Test your function. You should be able to get something very close to 1/squareroot (2)
Solution
ANS:
import math
print(\"This is taylor series\")
print(\"the series of x^0 / 0!, -x^2 / 2!,\")
n = eval(input(\"please enter number of terms \"))
x = eval(input(\"please enter x value \"))
s = 1
d = 1
e = 1
j=n
value = 0
rcos(j,x,n)#this is calling function
def rcos(j,x,n):#this is called function
value = value + s + (x*e / math.factorial(d))
s = s * 1
e = e + 2
d = d + 2
if i==0:#here check condition
return value
else
res=rcos(--i,x,n) #recursive function
print res
