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.



An arrow tip reaching outside of the sphere










share|improve this question




























    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.



    An arrow tip reaching outside of the sphere










    share|improve this question


























      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.



      An arrow tip reaching outside of the sphere










      share|improve this question















      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.



      An arrow tip reaching outside of the sphere







      python-3.x quantum-computing






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 17 hours ago









      Mad Physicist

      31.8k156491




      31.8k156491










      asked yesterday









      Makoto Nakai

      122




      122
























          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().






          share|improve this answer























          • 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











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          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
































          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().






          share|improve this answer























          • 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















          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().






          share|improve this answer























          • 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













          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().






          share|improve this answer














          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().







          share|improve this answer














          share|improve this answer



          share|improve this answer








          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


















          • 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


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          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




















































































          Popular posts from this blog

          Schultheiß

          Verwaltungsgliederung Dänemarks

          Liste der Kulturdenkmale in Wilsdruff