Lecture 18_Chapter_24_boundaryvalue
Lecture 18_Chapter_24_boundaryvalue
with MATLAB®
for Engineers and Scientists
4th Edition
Steven C. Chapra
©McGraw-Hill Education. All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of McGraw-Hill Education.
• Chapter Objectives, 1
Understanding the difference between initial-value
and boundary-value problems.
Knowing how to express an nth order ODE as a
system of n first-order ODEs.
Knowing how Eigenvalue and Eigenvectors are
used to solve an ODE
©McGraw-Hill Education.
• Chapter Objectives, 2
Knowing how to solve nonlinear ODEs with the shooting
method by using root location to generate accurate
“shots.”
Knowing how to implement the finite-difference method.
Understanding how derivative boundary conditions are
incorporated into the finite-difference method.
Knowing how to solve nonlinear ODEs with the finite-
difference method by using root location methods for
systems of nonlinear algebraic equations.
Familiarizing yourself with the built-in MATLAB function
bvp4c for solving boundary-value ODEs.
©McGraw-Hill Education.
Differential Equations
and
EigenValues
ODE and Eigenvalue
So if we start with: dy
ky
dt
kt
We end with: y y0 e
ODE and Eigenvalue
dy/dt = Ay
y(t) = eλ t x
d (eλ t x) = A eλ t x λeλ t x = A eλ t x
dt
λx = Ax Eigenvalue problem
First order homogeneous linear
system of differential equations
x1’(t) = a11x1 (t) + a12 x2 (t) + … a1nxn (t)
x2’(t) = a21x1 (t) + a22 x2 (t) + … a2nxn (t)
…
xn ’(t) = an1x1 (t) + an2 x2 (t) + … annxn (t)
[] [ ]
x1’ (t) a11 a12 …. a12
x(t) = x2’ (t) A = a21 a 22 … a2n
…
du2 = u1 – 2u2
[ ]
A = -1 2
1 -2
dt
[]
Initial condition u(0) =
1
0
Step 1: find the eigenvalues and eigenvectors
Eigenvalues are: λ = 0, -3
For λ = 0 X1=
[]
2
1
For λ= -3 X2=
[]
1
-1
Solve the differential equations
Eigenvalues are: λ = 0, -3
[ ]
A = -1 2
1 -2
Solution: y = c1
[]
2
1 e 0t
+ c2
[]
1
-1
e -3 t
=
[]
y1
y2
©McGraw-Hill Education. All rights reserved. Authorized only for instructor use in the classroom. No reproduction or further distribution permitted without the prior written consent of McGraw-Hill Education.
• Boundary-Value Problems
Boundary-value problems
are those where conditions
are not known at a single
point but rather are given
at different values of the
independent variable.
©McGraw-Hill Education.
• Higher Order Systems
MATLAB’s ODE solvers are based on
solving first-order differential equations only.
To solve an nth order system (n > 1), the
system must be written as n first-order
equations:
dT
2 z
dT dx
h T
T 0
dT h
2
dx T T
dz
Each first-order equation needs an initial
value or boundary value to solve.
©McGraw-Hill Education.
• The Shooting Method
One method for solving boundary-value
problems - the shooting method - is
based on converting the boundary-value
problem into an equivalent initial-value
problem.
Generally, the equivalent system will not
have sufficient initial conditions and so a
guess is made for any undefined values.
The guesses are changed until the final
solution satisfies all the boundary
conditions.
For linear ODEs, only two “shots” are
required - the proper initial condition can
be obtained as a linear interpolation of
the two guesses.
©McGraw-Hill Education.
• Boundary Conditions
Dirichlet boundary conditions are those
where a fixed value of a variable is known at
a particular location.
Neumann boundary conditions are those
where a derivative is known at a particular
location.
Shooting methods can be used for either
kind of boundary condition.
©McGraw-Hill Education.
• Finite-Difference Methods
The most common alternatives to the
shooting method are finite-difference
approaches.
In these techniques, finite differences are
substituted for the derivatives in the original
equation, transforming a linear differential
equation into a set of simultaneous algebraic
equations.
©McGraw-Hill Education.
• Finite-Difference Example, 1
Convert:
©McGraw-Hill Education.
• Finite-Difference Example, 2
Since T0 and Tn are known, they will be on
the right-hand-side of the linear algebra
system (in this case, in the first and last
entries, respectively):
′
𝑇1 h ∆ 𝑥2𝑇 ∞+𝑇 0
[ 2+h′ ∆ 𝑥 2
−1
−1 ¿
2+h′ ∆ 𝑥2 ¿ ] { }{
¿ ⋱ ¿ ⋱ ¿ ⋱ ¿ −1 ¿ 2+h′ ∆ 𝑥 2 ¿
𝑇2
⋮
=
h′ ∆ 𝑥2𝑇 ∞
⋮
𝑇 𝑛−1 h′ ∆ 𝑥2𝑇 ∞+𝑇𝑛
}
©McGraw-Hill Education.
• Derivative Boundary Conditions
Neumann boundary conditions are resolved by solving the
centered difference equation at the point and rewriting the
system equation accordingly.
For example, if there is a Neumann condition at the T0 point,
©McGraw-Hill Education.
• MATLAB’s bvp4c Function
Solves ODE boundary-value problems by integrating a system
of ordinary differential equations of the form y' = f(x, y) on the
interval [a, b], subject to general two-point boundary
conditions. A simple representation of its syntax is
sol = bvp4c(odefun,bcfun,solinit)
where
sol = a structure containing the solution
odefun = the function that sets up the ODEs to be solved
bcfun = the function that computes the residuals in the
boundary conditions
solinit = a structure with fields holding an initial mesh
and initial guesses for the solution.
©McGraw-Hill Education.
• Supporting Functions for bvp4c
The general format of odefun is
dy = odefun(x,y)
where x = a scalar, y = a column vector holding the dependent
variables [y1; y2], and dy = a column vector holding the derivatives
[dy1; dy2].
The general format of bcfun is
res = bcfun(ya,yb)
where ya and yb = column vectors holding the values of the dependent
variables at the boundary values x = a and x = b, and res = a column
vector holding the residuals between the computed and the specified
boundary values.
The general format of solinit is
solinit = bvpinit(xmesh, yinit);
where bvpinit = a built-in MATLAB function that creates the guess
structure holding the initial mesh and solution guesses, xmesh = a vector
holding the ordered nodes of the initial mesh, and yinit = a vector holding
the initial guesses.
©McGraw-Hill Education.
• bvp4c Example
Solve:
subject to:
©McGraw-Hill Education.
• bvp4c Example
©McGraw-Hill Education.
• bvp4c Example
Assume:
ya(1) = {y(1) at x= a }
ya(2) = {y(2) at x= a }
yb(1) = {y(1) at x= b }
yb(2) = {y(2) at x= b }
©McGraw-Hill Education.
• bvp4c Example, 2
function dy = odes(x,y)
dy = [y(2); 1-y(1)];
function res = bcs(ya,yb)
res = [ya(1)-1; yb(1)];
clc
solinit = bvpinit(linspace(0,pi/2,10),[1,-1]);
sol = bvp4c(@odes,@bcs,solinit);
x = linspace(0,pi/2); 1
y = deval(sol,x); 0.9
0.8
plot(x,y(1,:)) 0.7
0.6
Solution 0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6
©McGraw-Hill Education.