-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrthonormal Basis Using Python2.py
More file actions
63 lines (49 loc) · 1.2 KB
/
Orthonormal Basis Using Python2.py
File metadata and controls
63 lines (49 loc) · 1.2 KB
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
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 2 14:36:08 2019
@author: domin
"""
from numpy import sin, cos
import numpy as np
import matplotlib.pyplot as plt
import random
def unitvec():
u1=random.random()
u1a=u1*u1
u2=np.sqrt(1-u1a)
return u1, u2
u1,u2=unitvec()
S1=u1*u1
S2=u2*u2
q1,q2 =unitvec()
#print(u1,u2)
#print(S1+S2)
#print()
def basisvec(u1,u2):
x1=1/np.sqrt(np.square(-u1/u2) +1)
x2=-(u1/u2)*x1
return x1, x2
x1,x2=basisvec(u1,u2)
R1=x1*x1
R2=x2*x2
#print(x1,x2)
#print(R1+R2)
Qstate=np.array([[q1],[q2]])
print(Qstate)
originx=0
originy=0
basis1 = np.array([[originx, originy, u1, u2]])
basis2 = np.array([[originx, originy, x1, x2]])
Qubit1 = np.array([[originx, originy, q1, q2]])
X, Y, U, V = zip(*basis1)
X2, Y2, U2, V2 = zip(*basis2)
X3, Y3, U3, V3 = zip(*Qubit1)
plt.figure(figsize=(10,10))
ax = plt.gca()
ax.quiver(X, Y, U, V, angles='xy', scale_units='xy', scale=1, color='k')
ax.quiver(X2, Y2, U2, V2, angles='xy', scale_units='xy', scale=1, color='k')
ax.quiver(X3, Y3, U3, V3, angles='xy', scale_units='xy', scale=1, color='r')
ax.set_xlim([-1, 1])
ax.set_ylim([-1, 1])
plt.draw()
plt.show()