The length of an arrow in the Bloch sphere
up vote
1
down vote
favorite
I'm trying to build something called bloch sphere. This represents a state of a quantum bits in the form of an arrow in a sphere, whose radius is 1.0.
I wrote the codes below.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations
print("Put angle theta and phi, 0≤theta≤180, 0≤phi≤360")
theta = input("theta:")
phi = input("phi:")
theta = float(theta)
phi = float(phi)
X = np.sin(phi)
Y = np.sin(theta)
Z = np.cos(theta)
class quantum_gates:
def __init__(self,X,Y,Z):
self.X = float(X)
self.Y = float(Y)
self.Z = float(Z)
if theta <0 or theta >180 or phi < 0 or phi >360:
print("Put the value of angles again")
else:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('y')
ax.set_ylabel('x')
ax.set_zlabel('z')
ax.plot_wireframe(y, x, z, color="black")
ax.quiver(0,0,0,Y,X,Z,color="red",length=1.0)
When I put (theta, phi) = (30,0), the tip of the arrow reaches the surface of the sphere. However, when I put (theta,phi) = (30,30), the tip of the arrow goes outside of the sphere.
You can see the image of the current situation from the link below.
python-3.x quantum-computing
add a comment |
up vote
1
down vote
favorite
I'm trying to build something called bloch sphere. This represents a state of a quantum bits in the form of an arrow in a sphere, whose radius is 1.0.
I wrote the codes below.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations
print("Put angle theta and phi, 0≤theta≤180, 0≤phi≤360")
theta = input("theta:")
phi = input("phi:")
theta = float(theta)
phi = float(phi)
X = np.sin(phi)
Y = np.sin(theta)
Z = np.cos(theta)
class quantum_gates:
def __init__(self,X,Y,Z):
self.X = float(X)
self.Y = float(Y)
self.Z = float(Z)
if theta <0 or theta >180 or phi < 0 or phi >360:
print("Put the value of angles again")
else:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('y')
ax.set_ylabel('x')
ax.set_zlabel('z')
ax.plot_wireframe(y, x, z, color="black")
ax.quiver(0,0,0,Y,X,Z,color="red",length=1.0)
When I put (theta, phi) = (30,0), the tip of the arrow reaches the surface of the sphere. However, when I put (theta,phi) = (30,30), the tip of the arrow goes outside of the sphere.
You can see the image of the current situation from the link below.
python-3.x quantum-computing
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to build something called bloch sphere. This represents a state of a quantum bits in the form of an arrow in a sphere, whose radius is 1.0.
I wrote the codes below.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations
print("Put angle theta and phi, 0≤theta≤180, 0≤phi≤360")
theta = input("theta:")
phi = input("phi:")
theta = float(theta)
phi = float(phi)
X = np.sin(phi)
Y = np.sin(theta)
Z = np.cos(theta)
class quantum_gates:
def __init__(self,X,Y,Z):
self.X = float(X)
self.Y = float(Y)
self.Z = float(Z)
if theta <0 or theta >180 or phi < 0 or phi >360:
print("Put the value of angles again")
else:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('y')
ax.set_ylabel('x')
ax.set_zlabel('z')
ax.plot_wireframe(y, x, z, color="black")
ax.quiver(0,0,0,Y,X,Z,color="red",length=1.0)
When I put (theta, phi) = (30,0), the tip of the arrow reaches the surface of the sphere. However, when I put (theta,phi) = (30,30), the tip of the arrow goes outside of the sphere.
You can see the image of the current situation from the link below.
python-3.x quantum-computing
I'm trying to build something called bloch sphere. This represents a state of a quantum bits in the form of an arrow in a sphere, whose radius is 1.0.
I wrote the codes below.
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations
print("Put angle theta and phi, 0≤theta≤180, 0≤phi≤360")
theta = input("theta:")
phi = input("phi:")
theta = float(theta)
phi = float(phi)
X = np.sin(phi)
Y = np.sin(theta)
Z = np.cos(theta)
class quantum_gates:
def __init__(self,X,Y,Z):
self.X = float(X)
self.Y = float(Y)
self.Z = float(Z)
if theta <0 or theta >180 or phi < 0 or phi >360:
print("Put the value of angles again")
else:
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")
u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]
x = np.cos(u)*np.sin(v)
y = np.sin(u)*np.sin(v)
z = np.cos(v)
ax.set_xlabel('y')
ax.set_ylabel('x')
ax.set_zlabel('z')
ax.plot_wireframe(y, x, z, color="black")
ax.quiver(0,0,0,Y,X,Z,color="red",length=1.0)
When I put (theta, phi) = (30,0), the tip of the arrow reaches the surface of the sphere. However, when I put (theta,phi) = (30,30), the tip of the arrow goes outside of the sphere.
You can see the image of the current situation from the link below.
python-3.x quantum-computing
python-3.x quantum-computing
edited 17 hours ago
Mad Physicist
31.8k156491
31.8k156491
asked yesterday
Makoto Nakai
122
122
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
I guess you perform transformation between coordinates in a wrong way. X
, Y
, and Z
should be calculated as follows (wikipedia link):
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)
Also, numpy trigonometric functions accept values in radians. So, theta should be in the range [0, pi], phi should be in the range [0, 2 * pi). To convert degrees to radians you may use numpy.radians()
.
Thank you so much for answering my question. I just realized that I should have used radian, but I didn't know the correct way to calculate X,Y,Z.
– Makoto Nakai
17 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
I guess you perform transformation between coordinates in a wrong way. X
, Y
, and Z
should be calculated as follows (wikipedia link):
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)
Also, numpy trigonometric functions accept values in radians. So, theta should be in the range [0, pi], phi should be in the range [0, 2 * pi). To convert degrees to radians you may use numpy.radians()
.
Thank you so much for answering my question. I just realized that I should have used radian, but I didn't know the correct way to calculate X,Y,Z.
– Makoto Nakai
17 hours ago
add a comment |
up vote
1
down vote
I guess you perform transformation between coordinates in a wrong way. X
, Y
, and Z
should be calculated as follows (wikipedia link):
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)
Also, numpy trigonometric functions accept values in radians. So, theta should be in the range [0, pi], phi should be in the range [0, 2 * pi). To convert degrees to radians you may use numpy.radians()
.
Thank you so much for answering my question. I just realized that I should have used radian, but I didn't know the correct way to calculate X,Y,Z.
– Makoto Nakai
17 hours ago
add a comment |
up vote
1
down vote
up vote
1
down vote
I guess you perform transformation between coordinates in a wrong way. X
, Y
, and Z
should be calculated as follows (wikipedia link):
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)
Also, numpy trigonometric functions accept values in radians. So, theta should be in the range [0, pi], phi should be in the range [0, 2 * pi). To convert degrees to radians you may use numpy.radians()
.
I guess you perform transformation between coordinates in a wrong way. X
, Y
, and Z
should be calculated as follows (wikipedia link):
X = np.sin(theta) * np.cos(phi)
Y = np.sin(theta) * np.sin(phi)
Z = np.cos(theta)
Also, numpy trigonometric functions accept values in radians. So, theta should be in the range [0, pi], phi should be in the range [0, 2 * pi). To convert degrees to radians you may use numpy.radians()
.
edited 17 hours ago
answered 21 hours ago
Poolka
84428
84428
Thank you so much for answering my question. I just realized that I should have used radian, but I didn't know the correct way to calculate X,Y,Z.
– Makoto Nakai
17 hours ago
add a comment |
Thank you so much for answering my question. I just realized that I should have used radian, but I didn't know the correct way to calculate X,Y,Z.
– Makoto Nakai
17 hours ago
Thank you so much for answering my question. I just realized that I should have used radian, but I didn't know the correct way to calculate X,Y,Z.
– Makoto Nakai
17 hours ago
Thank you so much for answering my question. I just realized that I should have used radian, but I didn't know the correct way to calculate X,Y,Z.
– Makoto Nakai
17 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203197%2fthe-length-of-an-arrow-in-the-bloch-sphere%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password