<jupyter_start><jupyter_text>Método de NewtonJ.J---\begin{equation}x_{k+1} = x_{k} - \frac{f(x_{k})}{f'(x_{k})}\end{equation} Ejemplo: $f(x) = x^{2} + 3x +1$<jupyter_code>import numpy as np
from sympy import *
from sympy.utilities.lambdify import lambdify
import matplotlib.pyplot as plt
init_printing(use_unicode=True)
#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))
f = lambdify(x, funcion)
df = lambdify((x), dfuncion)
e = 0.0001 #error
maxit = 1000000 #iteraciones máximas
x0 = 2. #punto inicial
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
sol = NewtonR(x0)
print(sol)
X = np.linspace(-4, 2, 100)
plt.plot(X, f(X))
plt.plot(sol,f(sol),'ro')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17316017316017315, 'fraction_numerical': 0.03896103896103896, 'mean_word_length': 4.377906976744186, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '291669', 'license': 'MIT', 'n_tokens_mistral': 433, 'n_tokens_neox': 401, 'n_words': 97, 'path': 'Ec. No lineales/Metodo_Newton.ipynb', 'repo_name': 'JosueJuarez/M-todos-Num-ricos', 'size': '924'}