-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfuncao.py
83 lines (62 loc) · 1.67 KB
/
funcao.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
71
72
73
74
75
76
77
78
79
80
81
82
import numpy as np
from codificar import fill_matrix_with_primes
def lu_decomposition(A):
n = len(A)
L = np.zeros((n, n))
U = np.zeros((n, n))
Li = np.zeros((n, n))
Ui = np.zeros((n, n))
for i in range(n):
L[i, i] = 1.0
for j in range(i, n):
U[i, j] = A[i, j] - np.dot(L[i, :i], U[:i, j])
for j in range(i + 1, n):
L[j, i] = (A[j, i] - np.dot(L[j, :i], U[:i, i])) / U[i, i]
return L, U
def lu_solve(L, U, b):
n = len(L)
# Resolve Ly = b
y = np.zeros(n)
for i in range(n):
y[i] = b[i] - np.dot(L[i, :i], y[:i])
y[i] /= L[i, i]
# Resolve Ux = y
x = np.zeros(n)
for i in range(n - 1, -1, -1):
x[i] = y[i] - np.dot(U[i, i+1:], x[i+1:])
x[i] /= U[i, i]
return x
def binario_para_decimal(lista_binaria):
decimais = []
for binario in lista_binaria:
decimal = int(binario, 2)
decimais.append(decimal)
return decimais
def separar_numeros(input_str):
resultado = []
i = 0
while i < len(input_str):
tamanho = input_str[i:i+8]
numero = input_str[i+8:i+8+int(tamanho, 2)]
resultado.append(f'{numero}')
i += 8 + int(tamanho, 2)
return resultado
sequencia_binaria = return_data()
numero_decimal = separar_numeros(sequencia_binaria)
b= binario_para_decimal(numero_decimal)
print("sequencia binaria ja separada")
print(numero_decimal)
print()
print("binario para decimal")
print(b)
def result():
return x
A= fill_matrix_with_primes()
L, U = lu_decomposition(A)
x = lu_solve(L, U, b)
#print("Solucao x:")
#print(L)
#print()
#print(U)
#print()
#print(x)