Acmefiles 08 BVP 2021 PDF
Acmefiles 08 BVP 2021 PDF
y 00 + y 0 + y = f (t)
y(a) = α
y 0 (a) = β
t ∈[a, b].
This problem gives a differential equation with initial conditions for y and y 0 .
Formulating and solving initial value problems is an important tool when solving many types of
problems. One simple example of an IVP would be a differential equation modeling the path of a ball
thrown in the air where the initial position (y(a)) and velocity (y 0 (a)) are known. These problems
can be tricky to solve by hand. Luckily, SciPy has great tools that help us solve initial value problems
for most systems of first order ODEs. We will be using solve_ivp from scipy.integrate.
Consider the following example
We begin by changing this second order ODE into a first order ODE system.
This formulation allows us to use solve_ivp. We need three code elements in order to implement
solve_ivp:
1
2 Lab 1. Intro to IVP and BVP
plt.plot(sol.t,sol.y[0])
plt.xlabel('t')
plt.ylabel('y(t)')
plt.show()
3
Problem 1. Use solve_ivp to solve for y in the equation y 00 −y = sin(t) with initial conditions
y(0) = − 21 , y 0 (0) = 0 and plot your solution on the interval [0, 5]. Compare this to the analytic
solution y = − 12 (e−t + sin(t)).
Note: Using max_step = 0.1 with give you the smoother graph seen in figure 1.2.
4 Lab 1. Intro to IVP and BVP
This formulation allows us to use solve_bvp. It is important to notice that there are several key
differences between solve_ivp and solve_bvp. We need four code elements in order to implement
solve_bvp:
Problem 2. Use solve_bvp to solve for y in the equation y 00 −y = sin(t) with initial conditions
y(0) = − 21 , y 0 (0) = 0 and plot your solution on the interval [0, 5]. Compare this to the analytic
solution y = − 12 (e−t + sin(t)).
Note: Using max_step = 0.1 with give you the smoother graph seen in figure 1.4.
7
One other useful function of solve_bvp: sol.sol creates a callable function, which is the
estimation of the boundary value problem. You can utilize it by plugging in any int or linspace
(sol.sol(np.linspace), sol.sol(int), sol.sol(list)), like a normal lambda function.
One of the common issues with solve_bvp is choosing a guess for the initial value. Often, small
changes in the guess can cause large changes in the final approximation. The next problem demon-
strates the huge difference that can be made between an initial guess of 10 and an initial guess of
9.99
Problem 3. Use solve_bvp to solve for y in the equation y 00 = (1 − y 0 ) ∗ 10y with boundary
conditions y(0) = −1 and y(1) = 23 and plot your solution on the interval [0, 1]. Use an initial
guess of 10. Compare this to the the same solution using an initial guess of 9.99.
The solution is found in figure 1.5.
8 Lab 1. Intro to IVP and BVP
Problem 4. Use solve_ivp to solve the Four-Wing Attractor as described in equations (1.2),
(1.3), and (1.4) where a = 0.2, b = 0.01, and c = −0.4. Try this with 3 different initial values
9