def plusThetaeigenket(theta):
return np.array([np.cos(theta/2),np.sin(theta/2)])
print("|+theta> = ",plusThetaeigenket,"\n")
def minusThetaeigenket(theta):
return np.array([-np.sin(theta/2),np.cos(theta/2)])
print("|-theta> = ",minusThetaeigenket,"\n")
Can you please help to solve where this python code went wrong for display the correct eigen ket value for theta? Thank you
Hello,
In function call we need to pass the arguments through which it
is calling
Since you have not passed any argument during the function call, It
is just printing the address of the function rather than calling
and processing it
In this
first you need to initiate or take input from the user
for now i am initiating the value by 30.5
t1=30.5
t2=30.5
import numpy as np
def plusThetaeigenket(theta):
return
np.array([np.cos(theta/2),np.sin(theta/2)])
print("|+theta> = ",plusThetaeigenket(t1),"\n")
def minusThetaeigenket(theta):
return
np.array([-np.sin(theta/2),np.cos(theta/2)])
print("|-theta> = ",minusThetaeigenket(t2),"\n")
You will get output:
('|+theta> = ', array([-0.89695484, 0.44212217]), '\n') ('|-theta> = ', array([-0.44212217, -0.89695484]), '\n')
Comment for any doubt
thanks
def plusThetaeigenket(theta): return np.array([np.cos(theta/2),np.sin(theta/2)]) print("|+theta> = ",plusThetaeigenket,"\n") def minusThetaeigenket(theta): return np.array([-np.sin(theta/2),np.cos(theta/2)]) print("|-theta> = ",minusThetaeigenket,"\
#Which function has the most parameters? def Menu(): print ("Your Name Main Menu") print("1. Sum") print("2. Product") print("3. information") print("4. Quit") def Sum(x): x= x* 2 y = 10 answer = x+y return x,y,answer def Product(w,z): answer = w*z print (answer) def Calc(a,b,c): return a*b*c Question options: Product Calc Menu Sum
Question 18 CLO3 Analyze the following code and answer the questions that follow def F(n): If n <= 1: return n else: return F(n-1)+F(n-2) for i in range (n) print (F(i)) Result: 0 1 1 2 3 5 8 13 a. Write number of operations as a function when the code is execute b If n 7, what is the total number of operations? c. What is the complexity of the algorithm behind the code? (2 Marks) (2 Marks) (1...
def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...
Consider the following Python program: def fun(x, y): return x + y # [2] # [1] a = fun(2, 3) b = fun("2", 3) print a, b What does it evaluate to? Replace the last statement print a, b with print a + b and explain the traceback. What's wrong? Now eliminate the line marked [1] and change line [2] to read return x + y. Run the program and explain the traceback. Consider the following definition: def fun(n, m):...
Programming Exercise 11.6 Х + | Instructions fib.py >_ Terminal + iit B 1 def fib(n): 2 "*"Returns the nth Fibonacci number. " 3 if n < 3: lil 4 return 1 Modify the recursive Fibonacci function to employ the memoization technique discussed in this chapter. The function creates a dictionary and then defines a nested recursive helper function named memoizedFib You will need to create a dictionary to cache the sum of the fib function. The base case of...
Write a module of utility functions called util.py for manipulating 2-dimensional arrays of size 4x4. (These functions will be used in Question 3.) The functions you need to write are as follows: def create_grid(grid): """create a 4x4 array of zeroes within grid""" def print_grid (grid): """print out a 4x4 grid in 5-width columns within a box""" def check_lost (grid): """return True if there are no 0 values and there are no adjacent values that are equal; otherwise False""" def check_won...
What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...
1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...
using this code to complete. it python 3.#Display Program Purpose print("The program will show how much money you will make working a job that gives a inputted percentage increase each year") #Declaration and Initialization of Variables userName = "" #Variable to hold user's name currentYear = 0 #Variable to hold current year input birthYear = 0 #Variable to hold birth year input startingSalary = 0 #Variable to hold starting salary input retirementAge = 0 #Variable to hold retirement age input...