swtbutta33
2008-09-06 08:40:07 UTC
def rootsearch(f,a,b,dx):
x1= a; f1 = f(a)
x2 = a+dx; f2 = f(x2)
while f1*f2 > 0.0:
if x1 >= b: return None,None
x1= x2; f1 = f2
x2 = x1 + dx; f2 = f(x2)
else:
return x1,x2
When I try to run the code for any formula i get rootsearch(x**2, -1, 2, .5):
Traceback (most recent call last):
File "
rootsearch(x**2, -1, 2, .5)
NameError: name 'x' is not defined
Appreciate any help.