import numpy as np
# Put cursor in this cell and hit SHIFT+ENTER
A = np.array([[1, 2]])
B = np.array([[3], [5]])
print(A)
print(B)
print(A @ B)
[[1 2]]
[[3]
[5]]
[[13]]
# Solution
print(A.T, B.T)
print(B.T@A.T)
print(A.T@B.T)
[[1]
[2]] [[3 5]]
[[13]]
[[ 3 5]
[ 6 10]]
# Solution
print(1j*1j)
print((1+3j)*(3-7j))
C = 3 + 4j
print(C*np.conj(C))
(-1+0j)
(24+2j)
(25+0j)
z_plus_bra = np.array([[1,0]])
z_minus_bra = np.array([[0,1]])
z_plus_ket = z_plus_bra.T
z_minus_ket = z_minus_bra.T
x_plus_bra = 1/np.sqrt(2)*np.array([[1,1]])
x_minus_bra = 1/np.sqrt(2)*np.array([[1,-1]])
x_plus_ket = x_plus_bra.T
x_minus_ket = x_minus_bra.T
y_plus_bra = 1/np.sqrt(2)*np.array([[1, 1j]])
y_minus_bra = 1/np.sqrt(2)*np.array([[1, -1j]])
y_plus_ket = np.conj(y_plus_bra.T)
y_minus_ket = np.conj(y_minus_bra.T)
# z-axis
print("+z|+z = ", z_plus_bra@z_plus_ket)
print("-z|-z = ", z_minus_bra@z_minus_ket)
print("+z|-z = ", z_plus_bra@z_minus_ket)
print("-z|+z = ", z_minus_bra@z_plus_ket)
# x-axis
print("+x|+x = ", x_plus_bra@x_plus_ket)
print("-x|-x = ",x_minus_bra@x_minus_ket)
print("+x|-x = ",x_plus_bra@x_minus_ket)
print("-x|+x = ",x_minus_bra@x_plus_ket)
# y-axis
print("+y|+y = ",y_plus_bra@y_plus_ket)
print("-y|-y = ",y_minus_bra@y_minus_ket)
print("+y|-y = ",y_plus_bra@y_minus_ket)
print("-y|+y = ",y_minus_bra@y_plus_ket)
+z|+z = [[1]]
-z|-z = [[1]]
+z|-z = [[0]]
-z|+z = [[0]]
+x|+x = [[1.]]
-x|-x = [[1.]]
+x|-x = [[-2.23711432e-17]]
-x|+x = [[-2.23711432e-17]]
+y|+y = [[1.+0.j]]
-y|-y = [[1.+0.j]]
+y|-y = [[0.+0.j]]
-y|+y = [[0.+0.j]]
xFromZ = x_plus_bra@z_plus_ket
print(xFromZ)
#this is probability amplitude
print(xFromZ*np.conj(xFromZ))
#this is the real probability
yFromX = x_plus_bra@y_plus_ket
#print(yFromX)
print(yFromX*np.conj(yFromX))
[[0.70710678]]
[[0.5]]
[[0.5+0.j]]
psi_ket = 1j/np.sqrt(3)*z_plus_ket + np.sqrt(2/3)*z_minus_ket #declaring variable for psi
print("psi ket is equal to: \n", psi_ket) #check if it works
#print(z_minus_bra @ psi_ket)
A = z_plus_bra@psi_ket #this is probability amplitude of <+z|psi>
B = z_minus_bra@psi_ket #probability amplitude of <-z|psi>
#print(A[0],B[0])
Sz_minus_prob = np.conj(A)*A #actual probability
Sz_plus_prob = np.conj(B)*B #actual probability
#print(Sz_plus_prob, Sz_minus_prob)
Sz_expect = Sz_plus_prob - Sz_minus_prob
#print("<S_z> = ", Sz_expect, "hbar/2")
Sz_sq_expect = Sz_plus_prob + Sz_minus_prob
print("Expected value: ")
print("<S_z^2> =", Sz_sq_expect, "hbar^2/4") #obviously our <sz^2>
print("<S_z>^2 = ", Sz_expect**2) #the <sz>^2
Delta_Sz = np.sqrt(Sz_sq_expect - Sz_expect**2)
print("Delta S_z = ", Delta_Sz, "hbar/2")
print("Now compared to homework answer for deltaSz:")
print("deltaSz code - deltaSz homework = ", Delta_Sz - 2*np.sqrt(2)/3)
psi ket is equal to:
[[0. +0.57735027j]
[0.81649658+0.j ]]
Expected value:
<S_z^2> = [[1.+0.j]] hbar^2/4
<S_z>^2 = [[0.11111111+0.j]]
Delta S_z = [[0.94280904+0.j]] hbar/2
Now compared to homework answer for deltaSz:
deltaSz code - deltaSz homework = [[-1.11022302e-16+0.j]]