%run qlatvia.py

draw_qubit()

draw_quantum_state(3/5,4/5,"|v>")

%run qlatvia.py

draw_qubit()

draw_quantum_state(3/5,4/5,"|v>")

from matplotlib.pyplot import arrow, text, gca

# the projection on |0>-axis
arrow(0,0,3/5,0,color="blue",linewidth=1.5)
arrow(0,4/5,3/5,0,color="blue",linestyle='dotted')
text(0.1,-0.1,"cos(a)=3/5")

# the projection on |1>-axis
arrow(0,0,0,4/5,color="blue",linewidth=1.5)
arrow(3/5,0,0,4/5,color="blue",linestyle='dotted')
text(-0.1,0.55,"sin(a)=4/5",rotation="90")

# drawing the angle with |0>-axis
from matplotlib.patches import Arc
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=0,theta2=53) )
text(0.08,0.05,'.',fontsize=30)
text(0.21,0.09,'a')

%run qlatvia.py

draw_qubit()

from math import acos, pi

#
# your solution is here
#
quantum_state = random_quantum_state()
# obtain the degree with x-axis
radian = acos(quantum_state[0])
# convert radians to degree
angle = 360 * radian/(2*pi)
print("angle: " + str(angle) + " degrees")
# verify by visualizing the quantum state
draw_quantum_state(quantum_state[0],quantum_state[1],"s0")

%run qlatvia.py

draw_qubit()

draw_quantum_state(3/5,4/5,"|v1>")
draw_quantum_state(3/5,-4/5,"|v2>")

from matplotlib.pyplot import arrow, text, gca

# the projection on |0>-axis
arrow(0,0,3/5,0,color="blue",linewidth=1.5)
arrow(0,0,3/5,0,color="blue",linewidth=1.5)
arrow(0,4/5,3/5,0,color="blue",linestyle='dotted')
arrow(0,-4/5,3/5,0,color="blue",linestyle='dotted')
text(0.36,0.05,"cos(a)=3/5")
text(0.36,-0.09,"cos($-$a)=3/5")


# the projection on |1>-axis
arrow(0,0,0,4/5,color="blue",linewidth=1.5)
arrow(0,0,0,-4/5,color="blue",linewidth=1.5)
arrow(3/5,0,0,4/5,color="blue",linestyle='dotted')
arrow(3/5,0,0,-4/5,color="blue",linestyle='dotted')
text(-0.1,0.55,"sin(a)=4/5",rotation="90")
text(-0.14,-0.2,"sin($-$a)=$-$4/5",rotation="270")

# drawing the angle with |0>-axis
from matplotlib.patches import Arc
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=0,theta2=53) )
text(0.08,0.05,'.',fontsize=30)
text(0.21,0.09,'a')
gca().add_patch( Arc((0,0),0.4,0.4,angle=0,theta1=-53,theta2=0) )
text(0.08,-0.07,'.',fontsize=30)
text(0.19,-0.12,'$-$a')

# set the angle

from random import randrange
myangle = randrange(361)

################################################

from matplotlib.pyplot import figure,gca
from matplotlib.patches import Arc
from math import sin,cos,pi

# draw a figure
figure(figsize=(6,6), dpi=60)

%run qlatvia.py

draw_axes()

print("the selected angle is",myangle,"degrees")

ratio_of_arc = ((1000*myangle/360)//1)/1000

print("it is",ratio_of_arc,"of a full circle")

print("its length is",ratio_of_arc,"x 2\u03C0","=",ratio_of_arc*2*pi)

myangle_in_radian = 2*pi*(myangle/360)

print("its radian value is",myangle_in_radian)

gca().add_patch( Arc((0,0),0.2,0.2,angle=0,theta1=0,theta2=myangle,color="red") )

gca().add_patch( Arc((0,0),2,2,angle=0,theta1=0,theta2=myangle,color="blue") )

x = cos(myangle_in_radian)
y = sin(myangle_in_radian)

draw_quantum_state(x,y,"|v>")

%run qlatvia.py

draw_qubit()

from math import acos, pi

#
# your solution is here
#
# get the random quantum state
quantum_state = random_quantum_state()
x, y = quantum_state[0], quantum_state[1]
# obtain the degree with x-axis
radian = acos(x)
# convert radians to degree
angle = 360 * radian/(2*pi)

print("the selected angle is",angle,"degrees")

ratio_of_arc = ((1000*myangle/360)//1)/1000

print("it is",ratio_of_arc,"of a full circle")

print("its length is",ratio_of_arc,"x 2\u03C0","=",ratio_of_arc*2*pi)

angle_in_radian = 2*pi*(angle/360)

print("its radian value is",angle_in_radian)

gca().add_patch( Arc((0,0),0.2,0.2,angle=0,theta1=0,theta2=angle,color="red") )

gca().add_patch( Arc((0,0),2,2,angle=0,theta1=0,theta2=angle,color="blue") )

x = cos(angle_in_radian)
y = sin(angle_in_radian)
# draw the axes
draw_axes()
draw_quantum_state(x,y,"|u>")