# Método de Newton
J.J
---
\begin{equation}
x_{k+1} = x_{k} - \frac{f(x_{k})}{f'(x_{k})}
\end{equation}

Ejemplo: $f(x) = x^{2} + 3x +1$


```python
import numpy as np
from sympy import *
from sympy.utilities.lambdify import lambdify
import matplotlib.pyplot as plt
init_printing(use_unicode=True)
```


```python
#calcular la derivada de f
x = symbols('x')
funcion = 1 + 3*x + x**2 #escribir la función aqui
dfuncion = diff(funcion, x)
print(str(dfuncion))
```

    2*x + 3



```python
f = lambdify(x, funcion)
df = lambdify((x), dfuncion)
```


```python
e = 0.0001 #error
maxit = 1000000 #iteraciones máximas
x0 = 2. #punto inicial
```


```python
def NewtonR(x0, func = f, dfunc = df, error = e, iterations = maxit):
    it = 0
    while (abs(f(x0)) > e) and (it < maxit):
        it += 1
        x0 = x0 - f(x0)/df(x0)
    return x0
```


```python
sol = NewtonR(x0)
print(sol)
```

    -0.3819660098414816



```python
X = np.linspace(-4, 2, 100)
plt.plot(X, f(X))
plt.plot(sol,f(sol),'ro')
plt.show()
```


```python

```

ipynb
7ba9c1c1d5e87d53bdb97fcdc6ac51c7f802696f
Jupyter Notebook
8e328ef0f70519be57163b556db1fd27c3b04560
MIT
JosueJuarez/M-todos-Num-ricos
Ec. No lineales/Metodo_Newton.ipynb
8e328ef0f70519be57163b556db1fd27c3b04560
MIT
JosueJuarez/M-todos-Num-ricos
Ec. No lineales/Metodo_Newton.ipynb
8e328ef0f70519be57163b556db1fd27c3b04560
MIT
JosueJuarez/M-todos-Num-ricos
Ec. No lineales/Metodo_Newton.ipynb