-
Notifications
You must be signed in to change notification settings - Fork 0
/
Comp.py
181 lines (162 loc) · 4.37 KB
/
Comp.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import math
import Base as Bas;
def SumV(Data1,Data2):
res=[]
if len(Data1)==len(Data2):
for i in range(len(Data1)):
res.append(Bas.sum(Data1[i],Data2[i]))
return res
else: return res
def InvV(Data1):
res=[]
for i in range(len(Data1)):
res.append(Bas.pro(Data1[i],(-1,0)))
return res
def eVec(Escalar,Data1):
res=[]
for i in range(len(Data1)):
res.append(Bas.pro(Data1[i],Escalar))
return res
def SumM(Data1,Data2):
res=[]
if len(Data1)==len(Data2) and len(Data1[0])==len(Data2[0]):
for i in range(len(Data1)):
columna=[]
for j in range(len(Data1[i])):
columna.append(Bas.sum(Data1[i][j],Data2[i][j]))
res.append(columna)
return res
else: return res
def ResM(Data1,Data2):
res=[]
if len(Data1)==len(Data2) and len(Data1[0])==len(Data2[0]):
for i in range(len(Data1)):
columna=[]
for j in range(len(Data1[i])):
columna.append(Bas.res(Data1[i][j],Data2[i][j]))
res.append(columna)
return res
else: return res
def InvM(Data1):
res=[]
for i in range(len(Data1)):
columna=[]
for j in range(len(Data1[i])):
columna.append(Bas.pro(Data1[i][j],(-1,0)))
res.append(columna)
return res
def eMat(Escalar,Data1):
res=[]
for i in range(len(Data1)):
columna=[]
for j in range(len(Data1[i])):
columna.append(Bas.pro(Data1[i][j],Escalar))
res.append(columna)
return res
def Tra(Data1):
res=[]
for i in range(len(Data1)):
columna=[]
for j in range(len(Data1[i])):
columna.append(Data1[j][i])
res.append(columna)
return res
def ConjM(Data1):
res=[]
for i in range(len(Data1)):
columna=[]
for j in range(len(Data1[i])):
columna.append(Bas.conj(Data1[i][j]))
res.append(columna)
return res
def AdjM(Data1):
res = []
for i in range(len(Data1)):
columna = []
for j in range(len(Data1[i])):
columna.append(Bas.conj(Data1[j][i]))
res.append(columna)
return res
def AdjV(Data1):
res = []
for i in range(len(Data1)):
res.append(Bas.conj(Data1[i]))
return res
def MulM(Data1,Data2):
Matriz = []
for i in range(len(Data1)):
Fila = []
for j in range(len(Data2[0])):
Rp = 0
Ip = 0
for k in range(len(Data1[0])):
Rp += Bas.pro(Data1[i][k],Data2[k][j])[0]
Ip += Bas.pro(Data1[i][k],Data2[k][j])[1]
Fila.append((Rp,Ip))
Matriz.append(Fila)
return Matriz
def AcMV(Data1,Data2):
res=[]
for i in range(len(Data1)):
Rp = 0
Ip = 0
for k in range(len(Data2)):
Rp += Bas.pro(Data1[i][k],Data2[k])[0]
Ip += Bas.pro(Data1[i][k],Data2[k])[1]
res.append((Rp,Ip))
return res
def PriV(Data1,Data2):
Data1 = AdjV(Data1)
Rp = 0
Ip = 0
for i in range(len(Data1)):
Rp += Bas.pro(Data1[i],Data2[i])[0]
Ip += Bas.pro(Data1[i],Data2[i])[1]
return (Rp,Ip)
def NorV(Data1):
res=0
for i in range(len(Data1)):
res += Data1[i][0]**2+Data1[i][1]**2
return math.sqrt(res)
def DisV(Data1,Data2):
res = []
for i in range(len(Data1)):
res.append(Bas.res(Data1[i],Data2[i]))
d = 0
for j in range(len(res)):
d += Bas.mod(res[j])
return d
def Unit(Data1):
res = AdjM(Data1)
Un = []
for i in range(len(Data1)):
col1 = []
for j in range (len(Data1[i])):
if i == j:
col1.append((1,0))
else:
col1.append((0,0))
Un.append(col1)
res = MulM(res,Data1)
if res == Un:return True
else:return False
def Herm(Data1):
res = AdjM(Data1)
if(res==Data1):return True
else:return False
def Prot(Data1,Data2):
res=[]
if(type(Data1[0])==list):
for i in Data1:
for j in i:
if (type(Data2[0])==list):
res.append(eMat(j,Data2))
else:
res.append(eVec(j,Data2))
else:
for i in Data1:
if (type(Data2[0])==list):
res.append(eMat(i,Data2))
else:
res.append(eVec(i,Data2))
return res