def solve_ode(self, l): """Solves the Schrodinger equation for a given l value using the Numerov method in the ode module. Arguments: l: angular momentum number Returns: points: set of points containing the solution to the Schrodinger equation """ if self.verbose: print("Calculating points...") # Set up initial conditions # We can't start at r=0, because the centrifugal term will diverge. Instead, # we use the central difference formula for the second derivative and X(0)=0 # to write an (worse) approximation for the third point. points = np.zeros_like(self.rgrid) points[1] = 1/self.stepsize # This is an arbitrary -- it sets the normalization. points[2] = points[1] * (2 - self.schrod_eqn(self.rgrid[1],l)*(self.stepsize**2)) points = ode.numerov(self.schrod_eqn, x_grid = self.rgrid, y_grid=points, start_index=1, end_index = self.xn, verbose=self.verbose, l=l) return points
def solve_ode(self, l): """Solves the Schrodinger equation for a given l value using the Numerov method in the ode module. Arguments: l: angular momentum number Returns: points: set of points containing the solution to the Schrodinger equation """ if self.verbose: print("Calculating points...") # Set up initial conditions # We can't start at r=0, because the centrifugal term will diverge. Instead, # we use the central difference formula for the second derivative and X(0)=0 # to write an (worse) approximation for the third point. points = np.zeros_like(self.rgrid) points[ 1] = 1 / self.stepsize # This is an arbitrary -- it sets the normalization. points[2] = points[1] * (2 - self.schrod_eqn(self.rgrid[1], l) * (self.stepsize**2)) points = ode.numerov(self.schrod_eqn, x_grid=self.rgrid, y_grid=points, start_index=1, end_index=self.xn, verbose=self.verbose, l=l) return points
def solve_ode(self, E, direction=None, endpoint=None): """Solves the Schrodinger equation using the Numerov method. Arguments: E: energy direction: which way the solver works endpoint: sets a particular stopping point Returns: points: solution to differential equation """ if endpoint is None: endpoint = self.turnpoint_index if direction is None: # If a direction isn't specified, recurse downward and integrate # left and right sides. l_points = self.solve_ode(E, direction='right', endpoint=endpoint) r_points = self.solve_ode(E, direction='left', endpoint=endpoint) points = np.zeros_like(self.xgrid) points[:endpoint] = l_points[:endpoint] points[endpoint:] = r_points[endpoint:] * (l_points[endpoint] / r_points[endpoint]) points = self.normalize(points) return points if self.verbose: print("Calculating points...") points = ode.numerov(self.schrod_eqn, i0=0, i_slope=-1, x_grid=self.xgrid, direction=direction, end_index=endpoint, verbose=self.verbose, E=E) # Convert back from y(x) to chi(x) return points * np.sqrt(self.rgrid)
def solve_ode(self, E, direction=None, endpoint=None): """Solves the Schrodinger equation using the Numerov method. Arguments: E: energy direction: which way the solver works endpoint: sets a particular stopping point Returns: points: solution to differential equation """ if endpoint is None: endpoint = self.turnpoint_index if direction is None: # If a direction isn't specified, recurse downward and integrate # left and right sides. l_points = self.solve_ode(E, direction='right', endpoint=endpoint) r_points = self.solve_ode(E, direction='left', endpoint=endpoint) points = np.zeros_like(self.xgrid) points[:endpoint] = l_points[:endpoint] points[endpoint:] = r_points[endpoint:] * (l_points[endpoint]/r_points[endpoint]) points = self.normalize(points) return points if self.verbose: print("Calculating points...") points = ode.numerov(self.schrod_eqn, i0 = 0, i_slope = -1, x_grid = self.xgrid, direction = direction, end_index = endpoint,verbose=self.verbose, E=E) # Convert back from y(x) to chi(x) return points*np.sqrt(self.rgrid)
import ode import numpy as np import matplotlib.pylab as pylab grid = np.linspace(0,2*np.pi,100) def g(x): return np.ones_like(x) res = ode.numerov(g,0.,1.,grid,end_index=50) pylab.plot(grid,res) #pylab.plot(grid,np.sin(grid)) #pylab.show() res = ode.numerov(g,0.,1.,grid,end_index=50,direction='left') pylab.plot(grid,res) #pylab.plot(grid,np.sin(grid)) pylab.show()
def wf(M, xm): # find w.f. and deriv at xm c = (h*h)/6. wfup, nup = ode.numerov(f, [0,.1], M, xL, h) # 1 step past xm dup = ((1+c*f(xm+h))*wfup[-1] - (1+c*f(xm-h))*wfup[-3])/(h+h) return wfup, dup/wfup[-2]
def wf(M, xm): # find w.f. and deriv at xm c = (h * h) / 6. wfup, nup = ode.numerov(f, [0, .1], M, xL, h) # 1 step past xm dup = ((1 + c * f(xm + h)) * wfup[-1] - (1 + c * f(xm - h)) * wfup[-3]) / (h + h) return wfup, dup / wfup[-2]
import ode import numpy as np import matplotlib.pylab as pylab grid = np.linspace(0, 2 * np.pi, 100) def g(x): return np.ones_like(x) res = ode.numerov(g, 0., 1., grid, end_index=50) pylab.plot(grid, res) #pylab.plot(grid,np.sin(grid)) #pylab.show() res = ode.numerov(g, 0., 1., grid, end_index=50, direction='left') pylab.plot(grid, res) #pylab.plot(grid,np.sin(grid)) pylab.show()
import ode import numpy as np import matplotlib.pylab as pylab grid = np.linspace(1,10,100) def g(x): return 1/x res = ode.numerov(g,0.,1.,grid) pylab.plot(grid,res) #pylab.plot(grid,np.sin(grid)) #pylab.show() res = ode.numerov(g,-1.62827,-0.319947,grid,direction='left') pylab.plot(grid,res) #pylab.plot(grid,np.sin(grid)) pylab.show()
import ode import numpy as np import matplotlib.pylab as pylab grid = np.linspace(1, 10, 100) def g(x): return 1 / x res = ode.numerov(g, 0., 1., grid) pylab.plot(grid, res) #pylab.plot(grid,np.sin(grid)) #pylab.show() res = ode.numerov(g, -1.62827, -0.319947, grid, direction='left') pylab.plot(grid, res) #pylab.plot(grid,np.sin(grid)) pylab.show()