-
Notifications
You must be signed in to change notification settings - Fork 0
/
mudaBase.py
91 lines (80 loc) · 2.61 KB
/
mudaBase.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
83
84
85
86
87
88
89
90
import numpy as np
from funcoes import base
def mudancaBase(A, B, n):
matriz = []
valida = base(A, B, n)
if valida == True:
if n == 2:
a = [[B[0][0], B[1][0]], [B[0][1], B[1][1]]]
b = A[0]
sistema_linear = np.linalg.solve(a, b)
x1 = sistema_linear[0]
y1 = sistema_linear[1]
a = [[B[0][0], B[1][0]], [B[0][1], B[1][1]]]
b = A[1]
sistema_linear = np.linalg.solve(a, b)
x2 = sistema_linear[0]
y2 = sistema_linear[1]
matriz = [[x1, x2], [y1, y2]]
return matriz
if n == 3:
a = [[B[0][0], B[1][0], B[2][0]], [B[0][1], B[1][1], B[2][1]], [B[0][2], B[1][2], B[2][2]]]
for x in range(n):
b = A[x]
sistema_linear = list(np.linalg.solve(a, b))
matriz.append(sistema_linear[:])
sistema_linear.clear()
return matriz
if n == 4:
a = [[B[0][0], B[1][0], B[2][0], B[3][0]], [B[0][1], B[1][1], B[2][1], B[3][1]],
[B[0][2], B[1][2], B[2][2], B[3][2]], [B[0][3], B[1][3], B[2][3], B[3][3]]]
for x in range(n):
b = A[x]
sistema_linear = list(np.linalg.solve(a, b))
matriz.append(sistema_linear[:])
sistema_linear.clear()
return matriz
else:
return print("As bases apresentadas não são validas")
# def mudaBase2(A, B):
# a = [[B[0][0]], B[1][0], [B[0][1], B[1][1]]]
# b = A[0]
#
# sistema_linear = np.linalg.solve(a, b)
# x1 = sistema_linear[0]
# y1 = sistema_linear[1]
#
# a = [[B[0][0], B[1][0]], [B[0][1], B[1][1]]]
# b = A[1]
#
# sistema_linear = np.linalg.solve(a, b)
# x2 = sistema_linear[0]
# y2 = sistema_linear[1]
#
# matriz = [[x1, x2], [y1, y2]]
# return matriz
#
#
# def mudaBase3(A, B):
# matriz = []
# a = [[B[0][0], B[1][0], B[2][0]], [B[0][1], B[1][1], B[2][1]], [B[0][2], B[1][2], B[2][2]]]
#
# for x in range(3):
# b = A[x]
# sistema_linear = list(np.linalg.solve(a, b))
# matriz.append(sistema_linear[:])
# sistema_linear.clear()
# return matriz
#
#
# def mudaBase4(A, B):
# matriz = []
# a = [[B[0][0], B[1][0], B[2][0], B[3][0]], [B[0][1], B[1][1], B[2][1], B[3][1]],
# [B[0][2], B[1][2], B[2][2], B[3][2]], [B[0][3], B[1][3], B[2][3], B[3][3]]]
#
# for x in range(4):
# b = A[x]
# sistema_linear = list(np.linalg.solve(a, b))
# matriz.append(sistema_linear[:])
# sistema_linear.clear()
# return matriz