I've defined the following function which takes x and n as arguments, using Taylor series summation to approximate arctan. I also embedded a conditional statement inside so the function works for all x. import math
import math
for x in range(1,10,1):
def arctan(x, n):
arctang=0
inv_x=1/x
for i in range(n):
sign=(-1)**i
arctang = arctang + ((inv_x**(2.0*i+1))/(2.0*i+1))*sign
if x>0:
arc_tan=(math.pi/2)-arctang
else:
arc_tan=-(math.pi/2)-arctang
return arc_tan
print(arctan(x,100))
this code prints the iterations:
0.7878981009052581
1.1071487177940906
1.2490457723982544
1.3258176636680326
1.3734007669450157
1.4056476493802696
1.4288992721907325
1.446441332248135
1.460139105621001
however I want to be able to store the x values into an array, and these iterations into another so I can generate a graph out of the arrays, ie: something along the lines x=[1,2,3,4,5,6,7,8,9] y=[iterations as listed]
How should I go about doing this?
thanks!