Chapter 6:Particle in a box

Example no:1,Page no:202

In [31]:
#Variable declaration
L=1.0
x0=L/3.0 
x1=2*L/3.0   


#calculation
import math
from scipy import integrate
def f(x):
    w=math.sqrt(2/L)*math.sin(math.pi*x/L)
    return(w**2)
P=integrate.quad(f,x0,x1)

#Result
print"The required probability =",round(P[0],2)
The required probability = 0.61

Example no:2,Page no:202

In [66]:
#Variable declaration
L=1.0 
x0=0.0 
x1=L/3.0 
y0=0.0 
y1=L/3.0 

#Calculation
from scipy.integrate import dblquad
import numpy as np
def f(x,y):
#w=(2.0/L)*(np.sin(np.pi*x/L))*(np.sin(np.pi*y/L))
    return((1-np.cos(2*np.pi*x/L))*(1-np.cos(2*np.pi*y/L)))      

p=dblquad(f,x0,x1,lambda y:0,lambda y:L/3.0)

#Result
print"The required probability = ",round(p[0],3)
print"NOTE:Wrong answer in book"
The required probability =  0.038
NOTE:Wrong answer in book