%matplotlib inline
from matplotlib import pyplot as plt
from matplotlib import style
import numpy as np
def grafica(x,y,x_n):
style.use("ggplot")
plt.title("Gafico funcion a integrar")
plt.ylabel("f(x)")
plt.xlabel("x")
plt.scatter(x_n,0,color='blue')
plt.plot(x,y, linestyle='solid')
plt.show()
def f(x):
return (x**(3.5))-80
x0 = 3.5
x_1 = 0
x_n = 0
es=0.1
ea = 1000
n = 1
x = np.linspace(0, 4, num = 100)
y = f(x)
print("")
print(f"{'Iteracion':>10s}{'Resultado':>20s}{'f(x)':>20s}{'Ea(%)':>20s}")
print("________________________________________________________________________")
while es<ea:
x_n = x0 - ((f(x0) * (x_1-x0)) / (f(x_1)-f(x0)))
if n > 1:
ea = abs((x_n-x0)/x_n)*100
print(f"{n:10d}{x_n:20.9f}{f(x_n):20.9f}{ea:20.9f}")
n += 1
x_1 = x0
x0 = x_n
print("________________________________________________________________________")
grafica(x,y,x_n)
print(f"Calculo mas sercano a la raiz es '{x0}'")
Iteracion Resultado f(x) Ea(%) ________________________________________________________________________ 1 3.490759078 -0.527007495 1000.000000000 2 3.497351006 -0.000499385 0.188483441 3 3.497357258 0.000001179 0.000178773 ________________________________________________________________________
Calculo mas sercano a la raiz es '3.4973572579110996'