-
Notifications
You must be signed in to change notification settings - Fork 0
/
horner.py
51 lines (46 loc) · 1.33 KB
/
horner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import numpy as np
coeficiente=[]
cifras=-1
ea=1000
valorDex=0
datos=[]
while cifras < 0:
cifras = int(input("Ingrese la cantidad de cifras"))
if cifras < 0:
print("No se puede efectuar")
else:
es = 0.5*(10**(2-cifras))
grado =int(input("ingrese el grado de polinomio deseado: " ))
x_Inicial=float(input("ingrese el valor inical deseado"))
for i in range(0,grado+1):
coeficiente.append(float((input(f"Escriba el coeficiente del grado {grado-i}: "))))
while ea > es:
restas=[]
factores=[]
coeficiente2=[]
restas2=[]
factores2=[]
factores.append(coeficiente[0])
restas.append(0)
for i in range(1,len(coeficiente)):
restas.append(factores[i-1]*x_Inicial)
factores.append(coeficiente[i]+restas[i])
R=factores[-1]
coeficiente2=factores
coeficiente2.remove(coeficiente2[-1])
factores2.append(coeficiente2[0])
restas2.append(0)
for i in range(1,len(coeficiente2)):
restas2.append(factores2[i-1]*x_Inicial)
factores2.append(coeficiente2[i]+restas2[i])
S=factores2[-1]
datos.append(R)
datos.append(S)
datos.append(x_Inicial)
valorDex=x_Inicial-R/S
ea=abs((valorDex-x_Inicial)/valorDex)*100
x_Inicial=valorDex
datos = np.array(datos)
np.savetxt("tablaDeIteraciones.csv",datos,delimiter=",")
print(valorDex)
print(ea)