Files
anum/Chapitre1-Newton.ipynb
2025-08-18 12:04:55 +02:00

23 KiB

In [1]:
import numpy as np
import matplotlib.pyplot as plt
In [4]:
def f(x):
    return x * np.e**x - 1

def fp(x):
    return np.e**x + x * np.e**x
In [5]:
def newton(x,f,fp,tol=1e-5):
    fx = f(x)
    while abs(fx) > tol:
        fx = f(x)
        fxp = fp(x)
        x = x - (fx/fxp)
    return x
In [10]:
xfs = np.arange(0,1.2,0.01)
yfs = np.array(f(xfs))
x = newton(1,f,fp,1e-10)
plt.plot(xfs,yfs,'r')
plt.plot(x,0,'.b')
Out[10]:
[<matplotlib.lines.Line2D at 0x1f1beb2ef50>]
No description has been provided for this image
In [ ]: