-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBairstow.py
70 lines (57 loc) · 1.53 KB
/
Bairstow.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Alexis Mendoza Valencia
# Estudiante Tecnológico de Monterrey, campus guadalajara
# Metodo_Bairstow
"""
Este metodo nos dice que cualquier funcion de de orden n
puede desomponerse en (x^2 + rx + s)(x^n-2 + x^n-3 + ... + x^0)
para obtener sus valores.
"""
#f(x) = x^5 - 3.5x^4 + 2.75x^3 + 2.125x^2 - 3.875x + 1.25
coeficientes = [1.25, -3.875, 2.125, 2.75, -3.5, 1]
def bn(coeficientes):
return coeficientes[-1];
"""En esta funcion tenemos que:
a: Lista de coeficientes
b: bn(a)
r y s: son valores cualquiera que permiten acercarse al valor final
"""
def bn1(a, b, r):
return coeficientes[-2]+r*b;
def bi(i, a, r, s, b):
return a[i] + r*b[0] + s*b[1];
def cn(b):
return bn(b);
def cn1(b, c, r):
return bn1(b,c,r);
def ci(i, b, r, s, c):
return bi(i, b, r, s, c);
r = -1
s = -1
b = []
raices = []
for i in range(100):
b = []
b.insert(0, bn(coeficientes))
b.insert(0, bn1(coeficientes, b[0], r))
print(b)
for i in reversed(range(0,4)):
b.insert(0, bi(i, coeficientes, r, s, b))
print(b)
c = []
c.append(cn(b));
c.insert(0, cn1(b, c[0], r))
for i in reversed(range(0,4)):
c.insert(0, ci(i, b, r, s, c));
print(c)
def deltaS(b, c):
return (-1*b[1]/c[2] + b[0]/c[1]) / (c[3]/c[2] - c[2]/c[1])
def deltaR(b, c, dS):
return (-1*b[0]/c[1]) - ((c[2]/c[1])*dS)
dS = deltaS(b, c)
dR = deltaR(b, c, dS)
print("dS = ", dS)
print("dR = ", dR)
if(abs(dS) < 0.01 and abs(dR) < 0.01):
break;
r += dR
s += dS