First off this is for a homework assignment and I am new to python. I have attempted to tweak an example of how to make a table from another post on this forum but with no luck. Here are my problems:
1) my range is small (0, 1, 0.1)
This is my error:
Warning (from warnings module):
File "C:/Users/Will/Documents/Python Codes/Sin", line 25
for x in range(0., 1., 0.1):
DeprecationWarning: integer argument expected, got float
Traceback (most recent call last):
File "C:/Users/Will/Documents/Python Codes/Sin", line 25, in <module>
for x in range(0., 1., 0.1):
ValueError: range() step argument must not be zero
I appreciate any help. My thoughts are that my range increments (0.1) are returning 0 and I am unsure as to how I can fix that.
import math
# I am defining a function for Sin(x)
def function_sin(x):
n = 0.
top = 1.
bottom = 1.
eps = 10**(-8)
total = 0.
#This is my formula to approximate Sin(x)
while abs(top/bottom) > eps:
n = n + 1
top = ((-1.)**(n-1.))*(x**(2.*n-1))
bottom = math.factorial(2.*n-1.)
total = total + top / bottom
return total
# this is where I make the table using the function
print
print " A table of results for varies values of X in the function Sin(x) "
#the range is from 0 to 1 in incriments of 0.1
for x in range(0., 1., 0.1):
print "%3.3f x-value = %3.3f output" % ( x ,function_sin(x) )