Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
complexNumbers/LibVectoresyMatricesComplejas.py at master · JCPosso/complexNumbers · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
JCPosso
complexNumbers
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
complexNumbers
/
LibVectoresyMatricesComplejas.py
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
187 lines (170 loc) · 7.9 KB
master
Breadcrumbs
complexNumbers
/
LibVectoresyMatricesComplejas.py
Copy path
Top
File metadata and controls
Code
Blame
187 lines (170 loc) · 7.9 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
182
183
184
185
186
187
#-*- coding: utf-8 -*-
import
matplotlib
.
pyplot
as
plt
import
math
;
from
LibreriaNumerosComplejos
import
*
"""Librería computación Cuántica: Números complejos
librería para hacer operaciones entre vectores y matrices de complejos.
@author (Juan Camilo Posso G.)
@version (1.0 or 16/01/2020)rr
"""
class
matriz
:
def
__init__
(
self
,
c
):
self
.
c
=
c
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
if
(
not
(
isinstance
(
self
.
c
[
j
][
k
],
complejo
))):
self
.
c
[
j
][
k
]
=
complejo
(
self
.
c
[
j
][
k
][
0
],
self
.
c
[
j
][
k
][
1
])
def
__eq__
(
self
,
other
):
"""Override"""
if
(
len
(
self
.
c
[
0
])
==
len
(
other
.
c
[
0
])
and
len
(
self
.
c
)
==
len
(
other
.
c
)):
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
if
isinstance
(
other
.
c
[
j
][
k
],
complejo
):
if
(
round
(
self
.
c
[
j
][
k
].
real
,
4
)
!=
round
(
other
.
c
[
j
][
k
].
real
,
4
)
or
round
(
self
.
c
[
j
][
k
].
img
,
4
)
!=
round
(
other
.
c
[
j
][
k
].
img
,
4
)):
return
False
return
True
return
False
def
iniciar
(
f
,
c
):
m
=
[]
for
i
in
range
(
f
):
m
.
append
([ [
0
,
0
] ]
*
c
)
return
matriz
(
m
)
def
unitaria
(
c
):
m
=
[]
temp
=
matriz
.
iniciar
(
c
,
c
)
for
i
in
range
(
c
):
temp
.
c
[
i
][
i
]
=
complejo
(
1
,
0
)
return
temp
def
trace
(
C
):
suma
=
complejo
(
0
,
0
)
for
j
in
range
(
len
(
C
.
c
[
0
])):
suma
=
suma
.
suma
(
C
.
c
[
j
][
j
])
return
suma
def
instanciar
(
self
):
v2
=
matriz
.
iniciar
(
len
(
self
.
c
),
len
(
self
.
c
[
0
]))
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
v2
.
c
[
j
][
k
]
=
self
.
c
[
j
][
k
]
return
v2
def
suma
(
self
,
W
):
m
=
len
(
self
.
c
);
n
=
len
(
self
.
c
[
0
]);
n2
=
len
(
W
.
c
);
p
=
len
(
W
.
c
[
0
])
if
(
m
!=
n2
or
n
!=
p
):
return
(
"Las matrices no tienen el tamaño apropiado"
)
res
=
matriz
.
iniciar
(
len
(
self
.
c
),
len
(
self
.
c
[
0
]))
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
res
.
c
[
j
][
k
]
=
(
self
.
c
[
j
][
k
]).
suma
(
W
.
c
[
j
][
k
])
return
res
def
inversa
(
self
):
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
self
.
c
[
j
][
k
]
=
(
self
.
c
[
j
][
k
]).
multiplica
(
complejo
(
-
1
,
0
))
return
self
def
multiplica
(
self
,
W
):
m
=
len
(
self
.
c
);
n
=
len
(
self
.
c
[
0
]);
n2
=
len
(
W
.
c
);
p
=
len
(
W
.
c
[
0
])
if
(
n
!=
n2
):
return
"Las matrices no tienen el tamaño apropiado"
res
=
matriz
.
iniciar
(
len
(
self
.
c
),
len
(
W
.
c
[
0
]))
for
j
in
range
(
m
):
for
k
in
range
(
p
):
cont
=
complejo
(
0
,
0
)
for
h
in
range
(
n
):
cont
=
cont
.
suma
( (
self
.
c
[
j
][
h
]).
multiplica
(
W
.
c
[
h
][
k
]) )
res
.
c
[
j
][
k
]
=
cont
return
res
def
multiplicaEscalar
(
self
,
e
):
if
(
isinstance
(
self
,
complejo
)):
temp
=
e
;
e
=
self
;
self
=
temp
res
=
matriz
.
iniciar
(
len
(
self
.
c
),
len
(
self
.
c
[
0
]))
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
res
.
c
[
j
][
k
]
=
(
self
.
c
[
j
][
k
]).
multiplica
(
e
)
return
res
def
transpuesta
(
self
):
m
=
matriz
.
iniciar
(
len
(
self
.
c
[
0
]),
len
(
self
.
c
))
for
j
in
range
(
len
(
self
.
c
[
0
])):
for
k
in
range
(
len
(
self
.
c
)):
m
.
c
[
j
][
k
]
=
self
.
c
[
k
][
j
]
self
.
c
=
m
.
c
return
self
def
conjugada
(
self
):
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
self
.
c
[
j
][
k
]
=
self
.
c
[
j
][
k
].
conjugado
()
return
self
def
adjunta
(
self
):
self
=
(
self
.
transpuesta
()).
conjugada
()
return
self
def
alcanceSobre
(
self
,
vector
):
if
(
len
(
vector
.
c
[
0
])
==
1
):
res
=
matriz
.
iniciar
(
len
(
vector
.
c
),
1
)
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
res
.
c
[
j
][
0
]
=
res
.
c
[
j
][
0
].
suma
(
self
.
c
[
j
][
k
].
multiplica
(
vector
.
c
[
k
][
0
]) )
return
res
return
"no ingresó un vector, intente nuevamente!"
def
productoInterno
(
self
,
W
):
producto
=
(
self
.
adjunta
() ).
multiplica
(
W
)
if
(
len
(
self
.
c
[
0
])
==
len
(
W
.
c
[
0
])
==
1
):
return
producto
return
producto
.
trace
()
def
isHermitian
(
self
):
n
=
matriz
.
instanciar
(
self
)
for
j
in
range
(
len
(
self
.
c
)):
for
k
in
range
(
len
(
self
.
c
[
0
])):
if
(
self
.
c
[
j
][
k
]
!=
n
.
c
[
k
][
j
].
conjugado
()):
return
False
return
True
def
isUnitary
(
self
):
n
=
matriz
.
instanciar
(
self
)
if
(
len
(
self
.
c
[
0
])
==
len
(
self
.
c
)):
if
(
self
.
multiplica
(
n
.
adjunta
())
==
(
self
.
adjunta
().
multiplica
(
n
) )):
return
True
return
False
def
norma
(
self
):
m
=
matriz
(
self
.
c
)
return
round
(
math
.
sqrt
(
int
(
str
(
self
.
productoInterno
(
m
)))),
2
)
def
distancia
(
self
,
v2
):
return
(
self
.
suma
(
v2
.
inversa
()).
norma
( ))
def
productoTensor
(
self
,
B
):
f
=
len
(
B
.
c
)
*
len
(
self
.
c
)
c
=
len
(
self
.
c
[
0
])
*
len
(
B
.
c
[
0
])
matrix
=
matriz
.
iniciar
(
f
,
c
)
o
=
0
;
p
=
0
for
j
in
range
(
len
(
matrix
.
c
)):
for
k
in
range
(
len
(
matrix
.
c
[
0
])):
matrix
.
c
[
j
][
k
]
=
self
.
c
[
j
//
len
(
B
.
c
)][
k
//
len
(
B
.
c
[
0
])].
multiplica
(
B
.
c
[
j
%
len
(
B
.
c
)][
k
%
len
(
B
.
c
[
0
])])
return
matrix
def
potencia
(
self
,
n
):
if
(
n
==
1
):
return
self
else
:
if
( (
n
%
2
)
==
0
):
return
(
self
.
potencia
(
n
//
2
)).
multiplica
(
self
.
potencia
(
n
//
2
))
else
:
return
(
self
.
potencia
(
n
//
2
).
multiplica
(
self
.
potencia
(
n
//
2
))).
multiplica
(
self
)
def
state
(
self
,
v
,
times
):
if
(
times
==
0
):
return
self
return
(
self
.
potencia
(
times
)).
alcanceSobre
(
v
)
def
combinar
(
m1
,
m2
,
v1
,
v2
,
n
):
if
(
n
==
0
):
e1
=
v1
e2
=
v2
else
:
e1
=
m1
.
potencia
(
n
).
multiplica
(
v1
)
e2
=
m2
.
potencia
(
n
).
multiplica
(
v2
)
return
e1
.
productoTensor
(
e2
)
def
cuadrada
(
self
):
return
len
(
self
.
c
)
==
len
(
self
.
c
[
0
])
def
n_BlancosOptimo
(
n
,
n2
):
return
n
+
( ((
n
//
2
)
+
1
)
*
(
n2
-
1
))
def
isDoublyStochastic
(
self
):
vPrueba
=
matriz
.
iniciar
(
len
(
self
.
c
),
1
)
for
i
in
range
(
len
(
self
.
c
)):
vPrueba
.
c
[
i
][
0
]
=
complejo
(
1
,
0
)
return
self
.
alcanceSobre
(
vPrueba
)
==
vPrueba
def
__str__
(
self
):
s
=
""
for
j
in
range
(
len
(
self
.
c
)):
s
+=
"[ "
for
k
in
range
(
len
(
self
.
c
[
0
])):
s
+=
str
(
self
.
c
[
j
][
k
])
+
" "
s
+=
']
\n
'
return
s
You can’t perform that action at this time.