Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168694
Image: ubuntu2004
def newton_find_root(func, fprime, x0, num_iterations=10, full_output=True): """ Use Newton's method to find a root of ``func`` with initial guess x0 where ``func`` is a differentiable function in one variable with derivative ``fprime``. """ x0 = float(x0) for i in range (num_iterations): x0 = x0 - func(x0)/fprime(x0) if full_output == True: print float(x0) return x0
f(x) = x^2 - 2 fp = diff(f) newton_find_root(f, fp, 10)
5.1 2.74607843137 1.73719487438 1.44423809487 1.41452565515 1.4142135968 1.41421356237 1.41421356237 1.41421356237 1.41421356237 1.41421356237310
import scipy.optimize