In [35]:
from matplotlib import rcdefaults
rcdefaults()  # restore default matplotlib rc parameters
%config InlineBackend.figure_format='retina'   
import seaborn as sns  # wrapper for matplotlib that provides prettier styles and more
import matplotlib.pyplot as plt  # use matplotlib functionality directly
%matplotlib inline
#notebook  
sns.set()

ODE BVP by finite differences

In [25]:
import numpy as np
np.set_printoptions(linewidth=300)
In [26]:
def p(x): return 0*x
def q(x): return 100 + 0*x
def phi(x): return 0*x
alpha = 1
beta = 0
x0,x1 = 0,1
In [27]:
def f(x,Y):
    global p,q,phi
    y,yp = Y
    return np.array([ yp, phi(x) -p(x)*yp - q(x)*y ])
In [29]:
# sinusoidal y'' + y = 0

def p(x):   return 0*x
def q(x):   return 1 + 0*x
def phi(x): return 0*x 
x0,x1 = 0,3/2*np.pi
alpha = 0
beta = 1
sigmaguess = -1
In [30]:
# exponential y'' + y' = 0

def p(x):   return 1 + 0*x
def q(x):   return     0*x
def phi(x): return 0*x 
x0,x1 = 0,1
alpha = 2
beta = alpha+1
aa = 1/(1/np.exp(1)-1)
sigmaguess = -aa
In [31]:
# Golub and Ortega y'' - 100 y = 0   # tough for shooting

def p(x):   return     0*x
def q(x):   return -99 + 0*x
def phi(x): return 1 + 0*x 
x0,x1 = 0,1
alpha = 1
beta  = 0
sigmaguess = -11
In [ ]:
# wild

def p(x):   return 5*x**2
def q(x):   return 30+50*np.sin(30*x)
def phi(x): return 50*np.cosh(x)
x0,x1 = 0,1
alpha = 1
beta = 10
sigmaguess = -120