import math as m

def cargar_matriz_coeficientes():
    a = [[0, 0], [0, 0]]
    #for f in range(len(a)):
    #    for c in range(len(a[0])):
    #        a[f][c] = float(input('Ingrese el coheficiente a' + str(f+1) + str(c+1)))
    a[0][0] = 1
    a[0][1] = 0.3159
    a[1][0] = 1
    a[1][1] = 0.5091
    return a

def cargar_arreglo_constantes():
    c = [0, 0]
    #for i in range(len(c)):
    #    c[i] = float(input('Ingrese la constante c' + str(i+1)))
    c[0] = 8.1347
    c[1] = 9.7618   
    return c

def error(k1, k1_ant, k2, k2_ant):
 return m.sqrt(m.pow(k1-k1_ant,2) + m.pow(k2-k2_ant,2)) / m.sqrt(m.pow(k1,2)+m.pow(k2,2))*100

a = cargar_matriz_coeficientes()
print('Matriz coeficientes: ')
print(a)
c = cargar_arreglo_constantes()
print('Arreglo constantes: ')
print(c)
k = [0, 0]
# Error
es = float(input('Ingrese el error: '))
i = 1
ea=es + 1
while (es <= ea):
    k1= (c[0]-a[0][1]* k[1])/a[0][0]
    k2= (c[1]-a[1][0]* k1)/a[1][1]
    i+=1
    if (i >= 2):
        ea = error(k1,k[0],k2,k[1])
    k[0]=k1
    k[1]=k2

print ('Contante k1: ' + str(k1))
print ('Contante k2: ' + str(k2))
print ('Iteraciones: ' + str(i)) 
print('Error: ' + str(ea))


