Numerical approximation of ODE II:
boundary value problems
Grado en Ing. Civil y Territorial
(Univ. Polit´ecnica de Madrid)
April 9, 2013
Outline
1 Boundary value problems
2 Finite differences
3 Convergence, stability and
consistency
4 Other boundary conditions
5 Eigenvalue problems
Modeling: Bending
EId 2z
dx2 =M(x)
or
d2 dx2(EI
d2z
dx2) =q(x), dM
dx =V(x), dV
dx =−q(x)
z(x) deflection of the neural axes
E(x) is the Young’s modulus
I(x) area moment of inertia
M(x) bending moment
q(x) load
V(x) shear force
Beam equation: Equilibrium of bending moment
Strain below neutral axis ε
ε= (ρ+y)dρdθθ−ρdθ = yρ
Stress σ (Hook’s law)
σ =Eε=Eyρ
Moment equilibrium
M(x) =RAyσdy =RAEyρ2 = EIρ
Curvature approximation
1 ρ =
z00(x)
√
1+|z0(x)|3/2 ∼z 00(x)
Beam equation
M(x) = EIρ =EIz00(x)
Modeling: Boundary conditions
Cantilever
EIddx2z2 =M(x)
z(0) =z0(0) = 0.
Simpel support
EIddx2z2 =M(x)
z(0) =z(L) = 0.
Boundary value problem
Consider the ODE
−y00+a(x)y=f(x), y(a) =ya, y(b) =yb.
Two methods:
1 Fourier method
2 finite differences
Fourier method (main idea)
Consider the boundary value problem
−y00−y =f(x), y(0) =y(1) = 0.
Introduce the associated eigenvalue problem
−ϕ00−λϕ= 0, ϕ(0) =ϕ(1) = 0.
λk =k2π2, ϕk = sin(kπx), k = 1,2,3, ...
RemarkAll the eigenfunctions are solutions of
−ϕ00k −ϕk =(λk−1)ϕk(x),
ϕk(0) =ϕk(1) = 0.
Main idea: writef(x) as a linear combination of eigenfunctions
Fourier method in practice
Boundary value problem
−y00−y=f(x), y(0) =y(1) = 0. 1 Writey(x) andf(x) in Fourier Series
y(x) =
∞ X
k=1
aksin(kπx), f(x) = ∞ X
k=1
cksin(kπx)
2 Substitute in the differential equation ∞
X
k=1
(akk2π2−ak) sin(kπx) = ∞ X
k=1
cksin(kπx)
3 Identify coefficients
akk2π2−ak =ck, → ak =
ck
k2π2−1, k = 1,2, ...
4 Approximate the solution by truncating the series
y(x)∼ K
X
k=1
aksin(kπx).
Fourier method: example
−y00−y =(1−26e5x)(1−x) + 10e5x,
y(0) =y(1) = 0.
Approximate solution
f =
K
X
k=1
cksin(kπx), → yap(x) =
K
X
k=1
aksin(kπx)
ak = k2πck2−1, k= 1,2, .... Green: exact, blue: K=3, red K=5
Matlab code
f =
K
X
k=1
cksin(kπx), → yap(x) =
K
X
k=1
aksin(kπx)
K=5;% number of Four. coef.
N=1000; h=1/N; x=0:h:1;% space discret.
f=(1-26*exp(5*x)).*(1-x)+10*exp(5*x);% f(x)
sol=0;% aproximaci´on
for k=1:K
p= sin(k∗pi∗x);% autofunci´on
c=trapz(x,f.*p)/trapz(x,p.*p); a=c/(k∧2*pi∧2-1);
sol=sol+a*p; end
plot(x,sol)
Boundary value problem: finite differerences
Consider the ODE
−y00+a(x)y=f(x), y(a) =ya, y(b) =yb.
Main idea: Approximatey00(x) by afinite difference of neighbors
Finite difference method
Take a partition of [a,b]
y0(xn) =
y(xn+1)−y(xn)
h +O(h), y
0(x
n−1) =
y(xn)−y(xn−1)
h +O(h)
y00(xn) =
y(xn−1)−2y(xn) +y(xn+1)
h2 +O(h
2)
whereh=tn+1−tn is the mesh size.
Finite difference approximation
Continuous
−y00+a(x)y=f(x), y(a) =ya, y(b) =yb.
Discrete
yn∼y(xn), an=a(xn), fn=f(xn),
−yn−1+2yn−yn+1
h2 +anyn=fn, n= 1, ...,N−1
y0 =ya, yN =yb.
Matrix formulation
( ˜K + ˜A) ˜Y = ˜F,
where
˜
K = 1
h2
h2 0 0 0 0 ... 0
−1 2 −1 0 0 ... 0
0 −1 2 −1 0 ... 0
... ... ... ... ... ... ...
0 0 0 0 0 ... h2
, Y˜ =
y0 y1 ... yN−1 yN ˜ A=
0 0 0 0
0 a1 0 0
... ... ... ...
0 0 aN 0
0 0 0 0
, F˜=
ya f1 ... fN−1 yb
Linear system to be solved
(K +A)Y =F,
where
K = 1
h2
2 −1 0 0 ... 0 0
−1 2 −1 0 ... 0 0
... ... ... ... ... ... ...
0 0 0 0 ... −1 2
, Y =
y1 y2 ... yN−1
A=
a1 0 0 0
0 a2 0 0
... ... ... ...
0 0 0 aN−1
, F =
f1+ya/h2
f1 ...
fN−1+yb/h2
Solving the linear system
K+Amust be invertible. Sufficient conditions:
Maximum rank condition: Rank (K +A) =N−1.
K +Ais definite positive (K +A)ξ·ξ >0 for all nonzero
ξ ∈RN−1
K +Ais symmetric with positive eigenvalues
K +Ais diagonal dominant and strictly in at least one row.
Ex:
K = 1
h2
2 −1 0 0 ... 0 0
−1 2 −1 0 ... 0 0
... ... ... ... ... ... ...
0 0 0 0 ... −1 2
,
Numerical methods for linear system
The size of the linear system depends on the number of equations
we solve and the number of interior nodesN.
For relevant 3-d problems the size can be of the order of 107 and
larger. Efficient numerical methods are essential
1 Direct methods (small scale problems): LU decomposition,
Cholesky, etc.
2 Iterative methods (large scale problems): Jacobi,
Gauss-Seidel, etc.
Convergence
Definition
A numerical scheme is said to be convergent if the solutionyn
satisfies
lim
h→0+n=1max,...,Nen,h= limh→0+n=1max,...,N|y(xn)−yn|= 0.
Two main ingredients for convergence:
1 Small local error: consistency
−y(xn−1) + 2y(xn)−y(xn+1)
h2 −a(xn)y(xn)−f(xn)
=y00(xn)−a(xn)y(xn)−f(xn) +O(h2) =O(h2)
Second order accurate.
2 Global estimate of the discrete solution ash →0 (via
maximum principle): Stability
Matlab code
Consider the following ODE inx ∈[0,1],
−y00= 1,
y(0) =y(1) = 0.
a=0; b=1; ya=0; yb=0; N=40; h=(b-a)/N;
K=2*diag(ones(1,N-1))-diag(ones(1,N-2),1)-diag(ones(1,N-2),-1); K=1/h2*K;
F=ones(N-1,1); Y =K\F; y=[ya;Y;yb]; x=a:h:b; plot(x,y,’x’);
Remark
Numerical solutions of ODE:
1 Initial value problems are reduced to algebraic systems that
are solved by time advancing methods: Euler, Trapezoidal, Runge-Kutta,...
2 Boundary value problems are reduced to a (big) linear system
of equations. This is usually more expensive in terms of computational time.
Finite difference approximation of a mixed problem
Continuous
−y00+a(x)y =f(x), y(a) =ya, y0(b) =yb.
Discrete
yn∼y(xn), an=a(xn), fn=f(xn),
( −y
n−1+2yn−yn+1
h2 +anyn=fn, n = 1, ...,N−1
y0 =ya, yN
−yN−1 h =yb.
Matrix formulation
( ˜K + ˜A) ˜Y = ˜F,
where
˜
K = 1
h2
h2 0 0 0 0 ... 0
−1 2 −1 0 0 ... 0
0 −1 2 −1 0 ... 0
... ... ... ... ... ... ...
0 0 0 0 0 −h h
, Y˜ =
y0 y1 ... yN−1 yN ˜ A=
0 0 0 0
0 a1 0 0
... ... ... ...
0 0 aN 0
0 0 0 0
, F˜=
ya f1 ... fN−1 yb
Linear system to be solved
(K +A)Y =F,
where
K = 1
h2
2 −1 0 0 ... 0 0 0
−1 2 −1 0 ... 0 0 0
... ... ... ... ... ... ... ...
0 0 0 0 ... −1 2 −1
0 0 0 0 ... ... −h h
, Y =
y1 y2 ... yN A=
a1 0 0 0
0 a2 0 0
... ... ... ...
0 0 aN−1 0
0 0 0 0
, F =
f1+ya/h2
f1 ... fN−1 yb
Example
Consider the following ODE inx ∈[0, π/4],
−y00−4y = 0,
y(0) = 2, y0(π/4) =−2.
There is no solution of the continuous system. Numerical approximation:
Remarks:
1 The linear system associated to the approximate system has a
solution even if the matrix is not definite positive.
2 The numerical method is consistent. It is 1st order accurate.
3 However, there is no stability. The solution becomes larger as
h →0 and it does not converge to anything. This is due to
the fact that the continuous problem has no solution.
Concluding remark
Two methods to solve boundary value problems:
1 Finite differences. Reduce the problem to a linear system of
equations. Can be applied to any boundary value problem.
2 Fourier method. Reduce the problem to compute Fourier
coefficients. Few Fourier coefficients provide a good approximation. But it requires to know the eigenfunctions!
Modeling: Buckling
Consider a column with a loadP. The load provokes a momentum
which depends on the deflectionM(x) =−Py(x). Substituting in the beam equation,
(
EIddx2y2 =−Py
y(0) =y(L) = 0
The column is stable while the only possible deflection isy(x) = 0 everywhere. This corresponds to
P < the first eigenvalue =Pcr
If the column is homogeneous (E =cte) and of constant section,
then
Pcr
EI =
π2
L , Pcr =
π2EI
L =
π2EI
L ,(Euler formula)
Eigenvalue problems
Continuous problem. Findλsuch that there exists a solution
of
−y00 =λy, y(0) =y(1) = 0.
Discrete problem. Find λh such that there exists a vector
Y ∈RN−1 solution of
KY =λY.