def start(): if testing: pass else: n = input("Enter the length of the state vector ") X = mat.init_matrix(1,n) print ("Enter the wiring of the system ") M = mat.init_matrix(n,n) for i in range(n): for j in range(n): print("Probability of " + str(i) + " changing to " + str(j) + " ") a = input("real part : ") b = input("imaginary part : ") M[i][j] = (round(a,3), round(b,3)) print M print ("Enter inital state") X = mat.populate_matrix(X) print ("INITIAL") print X for i in range(10): print i X = mat.matrix_multiply(X,M) print X M_i = M for i in range(10): print i M_i = mat.matrix_multiply(M,M_i) print M_i
def start(): if testing: ket = x n = len(x[0]) else: print("Let's calculate some probabilities in a simple quantum system") n = input("Enter the number of states in a system :") ket = mat.init_matrix(1,n) print("Enter a (ket) state vector") mat.populate_matrix(ket) print(ket) p = get_probabilities(ket) print("--------------------------------------------------") print("Norm of ket " + str(round(norm(ket),4))) for i in range(n): print("The probability of finding particle at state " + str(i) + " is " + str(round(p[0][i],4))) print("--------------------------------------------------") answer = raw_input("Calculate transition amplitude leading to ket? (Hit 'y' to continue) : ") if answer != 'y': print("Bye") return bra = mat.init_matrix(1,n) print("Enter another (bra) state vector") mat.populate_matrix(bra) print("--------------------------------------------------") print("Norm of bra " + str(round(norm(bra),4))) trans = get_transition_amplitude(bra,ket) print("Transition amplitude <bra|ket> is " + ar.format(trans))
def start(): if testing: V1 = [[(0.0, 0.707), (-0.707, 0.0)]] V2 = [[(0.707, 0.0), (0.0, 0.707)]] else: print( "Let's calculate things based on inner product of two complex vectors." ) n = input("Length of the vectors ") V1 = mat.init_matrix(1, n) V2 = mat.init_matrix(1, n) print("Enter first vector") V1 = mat.populate_matrix(V1) print("Enter second vector") V2 = mat.populate_matrix(V2) print(V1) print("Length : " + str(length(V1))) print(V2) print("Length : " + str(length(V2))) inner = inner_product(V1, V2) print("-------------------- ") print("Inner product ") print(ar.format(inner)) print("-------------------- ") print("Distance") print(distance(V1, V2))
def normalize(psi): n = len(psi[0]) res = mat.init_matrix(1,n) norm_psi = norm(psi) for i in range(n): res[0][i] = ar.scalar_multiply(1/norm_psi,psi[0][i]) return res
def get_probabilities(psi): n = len(psi[0]) res = mat.init_matrix(1,n) #result is a vector containing probabilities psi_normalized = normalize(psi) for i in range(n): res[0][i] = ar.modulus_squared(psi_normalized[0][i]) return res
def start(): if testing: A = testM else: print "Test if a complex nxn-matrix is hermitian or unitary" n = input("Enter dimension n : ") A = mat.init_matrix(n, n) A = mat.populate_matrix(A) print(A) print("Is this matrix hermitian : " + str(is_hermitian(A))) print("Is this matrix unitary : " + str(is_unitary(A)))