Question

Project1(1) (1) (1) x S ㄨ scipyintegrate.odeint--Sc | + jupyter Project1(1) ()(1r File Edit View Insert Cell Kernel Widgets H

Sipyintegrate.odeint- ScV JupyterProjecti(I) (1) (1) (uns-ved changes) File Edit View Insert Cell Kernel Widgets Logout Trust

哂E | Project1(1) (1) (1) ×1Sscipyintegrateodeint-Sc|+v ← →。 | O localhost 8888/notebo(M ☆|延久 upyter Project1(1)() () File Edt

€| 哂 ← → Project1(1) (1) (1) × ⑥scipyi l+﹀ 左久 integrate.odeint-Sc | D localhost:8888/noteborn ☆ jupyter Project1(1) (1) (1) d

I'm trying to use the odeint function or the quad function to integrate my integrand in my calc_Hmatrix function. however I am not sure what my y0 or my t would need to be in order to get the code to run properly. please help, if more information is needed I can update this post

Project1(1) (1) (1) x S ㄨ scipyintegrate.odeint--Sc | + jupyter Project1(1) ()(1r File Edit View Insert Cell Kernel Widgets Help +x4r,수+H.CCode Trusted Python 3 O In [63]: Xmatplotlib inline from pylab import from scipy.integrate import quad import time import math fron scipy.fftpack İmport fft import numpy.linalg as la from numpy.random import uniform from scipy.integrate inport odeint Quantum Mechanics Project 1 Goal: Solve the energy eigenvalue equation We will use the matrix method by the following recipe 1 Identity basis tunctons lb-ers) We will choose the basis functions are also restricting ourselves to the computabonal domain 0 s xs L 2. Calculate matrix elements of Hamiltonian 1. Find the eigenvalues E, and eigenvectors IE) of tnat matrix H 2. Then, since E)- ) in the position representation we have In [87]: # Define constants here hbar, 1.e m-1 # special units # special units.. This ce # corresponding to the chosen basis functions L defines the "basts pht function, In [65J # NOTE: This function is only a "good" basis function return sgrt(a ari)sin(j'pi x/L) This cetl def ines the "dzpht funcrion def basis phij. x) 433 AM /22/2019 In [78): ates the second derivative of the basii e which colcul ns PgDn PgUp Home
Sipyintegrate.odeint- ScV JupyterProjecti(I) (1) (1) (uns-ved changes) File Edit View Insert Cell Kernel Widgets Logout Trusted Python 3 O . Help In [87]: : # Define constants here hbar- 1.0 # special units. # special units jmax ·20 In [65]: # This cell defines the -basis-phi-function, # corresponding to the chosen basis functions # NOTE: This function is only a "good" basis function def basis phi(j, x): return sqrt (2.8/L) sin(j'pi x/L) In [78]: # This cell defines the "d2phi" function, # which calculates the second derivative of the basis, phi function. Needed Later! def d2phi(j, x): return -((sqrt(2.0)"(pi". 2)"U".2)"sin((pi*).x)/L)/L"(5.e/2A)) In [67]: # This cell defines the potential energy V(x) # This will be "customized" for individual exercises. def V(x): return e # This then corresponds to the infinite square well in the cell below, you will want to program carefulty the integrand that appears in the matrix elements Then, you will be ready to use that function to later pertorm the integration needed for the matix eiements of H In t74]; # This celL defines the "integrand, that is needed to later calculate the matrix elements of H def Iategrand, , 1): basis phi(i,x)*(-(hbar*hbar)/()*(d2phi (j.x))-vox) "basis,phid.x)) return I In [148]: # This cell defines the function, that will # construct the matrix H # input parameter: jMax. rhe maximum number of basis functions to include # . For performing the integrals needed for the matrix e.enents. e you may use guadlt or other integration functions vou know The indtces i and d run Frow I to jmax for our mathenaticat formulation remember that the Python array index counting goes from 0 toinasal def calc Hmatrix(jMax) H zeros ((jmax, jeax)) " The index count ing set up bel ow is to "help a ad just for the diffarence between the math indices 435 AM /22/2019 几ー
哂E | Project1(1) (1) (1) ×1Sscipyintegrateodeint-Sc|+v ← →。 | O localhost 8888/notebo(M ☆|延久 upyter Project1(1)() () File Edt View Insert Cell Kenel Widgets Help unseved changes) Logout | Python 3 0 Trusted eiements 01 H In [741: i # This cell defines the *integrand", that is needed to later # Calculate the matrix elements of H def Integrand(x, i, j): I basis phi(i,x)'((C-(hban*hbar))/(2"m)) (d2phi (j.x))+V(x) basis phi(j,x)) return I In [148]: : # This cell defines the function, that will # construct the matrix H. # Input parameter: jMax. The maximum number of basis functions to include # For performing the integrals needed for the matrix elements, # you may use-quad. or other integration functions you know. # . The indices and j run from 1 to jmax for our mathematical formulation; # remember that the python array index counting goes from e to jmax-1! def calc Hmatrix (jMax): H - zeros ((jmax, jmax)) # The index counting set up below is to "help" # adjust for the difference between the moth indices # and the python array indices for i in range(1, jmax+1): for j in range(1, jmax+1): q Integrand(x,i,j) After the H matrix is built with the calc _Hmatrix turnction, you can simply use the eig Python function to obtain the eigenvalues En and eigenvectors Cia E)C with these cn coefficients obtained from the eigenvectors of the H matrix, you can build the jMax In [141]: # This celt defines the function that "builds" the # eigenfunctions, out of thejust-found coefficients ejn # and the basis functions .. basis-pet def eigenfunction(x, n. cin): · efunc 8.e for j in range(i, jnax 1): efunc t- op.linalg,eig(H) 0u T00O! print (efunc) return efunc 4:35 AM /22/2019 ns
€| 哂 ← → Project1(1) (1) (1) × ⑥scipyi l+﹀ 左久 integrate.odeint-Sc | D localhost:8888/noteborn ☆ jupyter Project1(1) (1) (1) de File Edit View Insert C Kernel Widgets Help Logout | Trusted , 1 Python 3。 with these cn coefficients obtained from the eigenvectors of the H matrix, you can build the jMar In [141]: # This cell defines the function that -builds" the # eigenfunctions, out of the just-found coefficients cJn # and the basis functions ,basis-phi" def eigenfunction(x, n, c jn): efunc 6.0 for j in range(1, jmax 1): efunc print return efunc +-np. linalg.eįg(H) (efunc) ### TODO! In [142]: x linspace (e,L,100) h calc Hmatrix(28.e) if-eigenfunction(x,e.c_jn) plot(x, Hf) İlaw TypeError 2 linspace(&L,100) calc Hmatrix(29.0) h “ 4 Wf eigenfunction(x,e,c in) s plot(x,Wf) cipython input-148-4e173e8536ba> in calc Hmatrix(jMax) for j in range(1, jnax 1): q-Integrand(x,i,j) 14 15 --> 16 17 Typetrror: odeint () missing 2 required positional arguments; Tye and 't Exercises 1. Complete the functions above, anywhere marked TODO For the cases below, you shoui . Lisl the lirst several allowed energies r Make an "energy level diagrarit (for exampe, using the hlines Python function) Pot the first several energy eigentunctions () as functions of a - Bonus chalienge To explore the numerical aspect of this method, you can also prepare plots hal demonstrate Bhiat as you increase jMax in the calculations. you shokt get increasinghy 4:35 AM 3/22/2019
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CO Y-o有2- IU dn2 k2-).gne 方2. |ら.th . Should be au0咇do to -00 2- egen vecmyсу Becouuse enす2. dク2

Add a comment
Know the answer?
Add Answer to:
I'm trying to use the odeint function or the quad function to integrate my integrand in my calc_H...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q10 The Hamiltonian of a two-state system is given by H E ( i)- I02)(2 |...

    Q10 The Hamiltonian of a two-state system is given by H E ( i)- I02)(2 | -i | ¢1)(2 | +i | ¢2) (¢1 1) where , p2) form a complete and orthonormal basis; E is a real constant having the dimensions of energy (a) Is H Hermitian? Calculate the trace of H (b) Find the matrix representing H in the | øı), | 42) basis and calculate the eigenvalues and the eigenvectors of the matrix. Calculate the trace of...

  • The way I understand it is i'm trying to link a list that I read into...

    The way I understand it is i'm trying to link a list that I read into python from a cvs file to json and xml and pass the doctest. Please refere the lines where I show what I did below. home / study / engineering / computer science / questions and answers / """this script converts a csv file with headers ... Question: """This script converts a CSV file with headers to... Bookmark """This script converts a CSV file with...

  • Consider the finite difference matrix operator for the 1D model problem u(/d2- f(x) on domain [0,...

    Consider the finite difference matrix operator for the 1D model problem u(/d2- f(x) on domain [0, 1] with boundary conditions u(0) = 0 and u(1) = 0, given by [-2 1 1-2 1 E RnXn h2 1 -2 1 This matrix can be considered a discrete version of the continuous operator d/da2 that acts upon a function(r). (a) Show that the n eigenvectors of A are given by the vectors ) (p-1,... , n) with components and with eigenvalues h2...

  • Write a function that flips a coin; it returns heads or tails. Use that function to...

    Write a function that flips a coin; it returns heads or tails. Use that function to write a GetHeadsInARow functions that accepts the number of heads to roll in a row before you return with total rolls it took to get that number of heads in a row. Please Code in Python3 my attempt below will not print out the answer and I do not know why def HeadTails(): from random import randrange """Will simulate the flip of a coin."""...

  • using python with only using import math and copy no other powerful functions. Write a function...

    using python with only using import math and copy no other powerful functions. Write a function defined as: def GaussSeidel(Aaug, x, Niter = 15): Purpose: use the Gauss-Seidel method to estimate the solution to a set of N linear equations expressed in matrix form as Ax = b. Both A and b are contained in the function argument – Aaug. Aaug: an augmented matrix containing [A | b ] having N rows and N+1 columns, where N is the number...

  • I'm being asked to compute the probablity density at (0,0) using the above KDE function. i finish...

    I'm being asked to compute the probablity density at (0,0) using the above KDE function. i finished the previous related part. Not entirely sure of the syntax needed to enter the equation using NumPy. Code for previous related part for reference: Exercise 3 Based on the KDE function: Compute the probablity density at [e,e], i.e., f((0, 0)). This should return a scalar value. (2 points) : def compute (data, h): ##CODE HERE## return x i We turn our attention to...

  • I'm working on the following: Write a python program: 1. Write the definition of the function...

    I'm working on the following: Write a python program: 1. Write the definition of the function displaySubMenu that displays the following menu; this function doesn't collect the user's input; only display the following menu.: [S]top – Press 'S' to stop. 2. Write the definition of the function setNextGenList that creates a pattern of next generation (tempGen) based on the current generation (currentGen); modify the tempGen based on the currentGen by applying the rules of Game of Life. Conway's Game of...

  • 1. Write a MATLAB function that takes a matrix, a row number and a scalar as...

    1. Write a MATLAB function that takes a matrix, a row number and a scalar as arguments and multiplies each element of the row of the matrix by the scalar returning the updated matrix. 2. Write a MATLAB function that takes a matrix, two row numbers and a scalar as arguments and returns a matrix with a linear combination of the rows. For example, if the rows passed to the function were i and j and the scalar was m,...

  • please use python thanks will rate!! x + Run C Code Validate Implement the function step_random_walk_20(x_coords,...

    please use python thanks will rate!! x + Run C Code Validate Implement the function step_random_walk_20(x_coords, Y_coords) below, which should take two arrays of equal length containing the x-andy- coordinates for some number of particles. We'll use a very simple random walk algorithm • For each particle, choose a random angle between 0 and 2 • The particle moves by 1 unit of distance in the direction given by d.o. It is displaced by (Ax, Ay) (cos, sino). We'll do...

  • I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to...

    I'm trying to sort a list of students from a text file in python(3.7) with three separate sorting functions (Bubble, selection, insert) I'm not sure to why as its not working I'm going to guess its because I'm not using the swap function I built. Every time I run it though I get an error that says the following Traceback (most recent call last): File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 146, in <module> main() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py", line 122, in main studentArray.gpaSort() File "C:/Users/tkoto/Desktop/SearchAndSortLab.py",...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT