```python
from sympy import *
```


```python
def halleys_method(function, initial, precision):
    x = Symbol('x')
    iters = 0
    
    lfunction = lambdify(x, function, 'numpy')
    
    dfunction = function.diff(x)
    ldfunction = lambdify(x, dfunction, 'numpy')
    
    d2function = dfunction.diff(x)
    ld2function = lambdify(x, d2function, 'numpy')
    
    while abs(lfunction(initial)) > precision:
        t = - lfunction(initial)/ldfunction(initial)
        r = ld2function(initial)*t**2/ldfunction(initial)
        initial = initial + t**2/(t + 0.5*r)
        iters += 1
    
    residual = lfunction(initial)
    return {'root': initial, 'iterations': iters, 'residual': residual}
```


```python
x = Symbol('x')
func = poly(x**3 + 6*x**2 + 9*x - 4).as_expr()
halleys_method(func, 3.6, 0.001)
```




    {'root': 0.3553270038206912,
     'iterations': 3,
     'residual': 0.00034933313787899323}



395e6c19537a6a767a23325438a0a6b34ec6445f
ipynb
Jupyter Notebook
Numerical-Methods/Halley's-Method/halley's method.ipynb
cmlimm/uni-projects
b63ac71cc0b971c7f035096a6bd15b0cbb5bb9f6
MIT
Numerical-Methods/Halley's-Method/halley's method.ipynb
cmlimm/uni-projects
b63ac71cc0b971c7f035096a6bd15b0cbb5bb9f6
MIT
Numerical-Methods/Halley's-Method/halley's method.ipynb
cmlimm/uni-projects
b63ac71cc0b971c7f035096a6bd15b0cbb5bb9f6
MIT
2020-10-29T18:31:32.000Z
2020-10-29T18:31:32.000Z
Qwen/Qwen-72B
1. YES
2. YES