def fvals_sqrt(x):
"""
Return f(x) and f'(x) for applying Newton to find a square root.
"""
f = x**2 - 4.
fp = 2.*x
return f, fp
def solve(fvals_sqrt, x0, debug_solve=True):
"""
Solves the sqrt function, using newtons methon.
"""
fvals_sqrt(x0)
x0 = x0 + (f/fp)
print x0
When I try to call the function solve, python returns:
NameError: global name 'f' is not defined
Obviously this is a scope issue, but how can I use f within my solve function?