PHYS 305: Computational Physics II
Winter 2022


Shooting method 2 -- simple eigenvalue problem

Previous   Next

Equation and BCs:

Y'' = deriv2(x, Y, Y')  =  -E Y
Y(a) = ya,  Y(b) = yb

Strategy:

For linear system, can always scale Y to simplify the BC at a
           e.g.  Y(a) = 1  or  Y(a) = 0, Y'(a) = 1 
Call the unknown eigenvalue z
Bisect on z to satisfy the (scaled) BC at b

Code:

def deriv2(x, y):
    return -y[2]*y[0]				# y[2] is the eigenvalue z (= E)

def f(x, y):					# RHS of the system
    return np.array([y[1], deriv2(x, y), 0.0])	# z' = 0

def integrate(func, a, ya, ypa, z, b, dx):	# integrate a to b and return results
    x = a
    y = np.array([ya, ypa, z])			# y = [Y, Y', E]
    while x < b-0.5*dx:
        x, y = rk4_step(func, x, y, dx)
    return x, y
	      
def g(z):					# integrate and return error
    x, y = integrate(f, a, ya, 1.0, z, b, dx)
    return y[0] - yb				# want y[0] = yb