numerical solution of two-point boundary value...

36
Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis by Gabriella Sebesty´ en Mathematics B.S.c., Mathematical Analyst Supervisor: Istv´ an Farag´ o Professor at the Department of Applied Analysis and Computational Mathematics otv¨ os Lor´ and University Budapest 2011 1

Upload: others

Post on 19-Jun-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

Numerical Solution of Two-PointBoundary Value Problems

B.S.c. Thesis

by

Gabriella Sebestyen

Mathematics B.S.c., Mathematical Analyst

Supervisor:

Istvan Farago

Professor at the

Department of Applied Analysis and Computational Mathematics

Eotvos Lorand University

Budapest

2011

1

Page 2: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

Contents

1 Introduction 3

2 Solvability of Boundary Value Problems 5

3 Shooting Method 73.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Intervallum-Bisection Method . . . . . . . . . . . . . . . . . . . . 73.3 Chord Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.4 Newton Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4 Finite Difference Schemes 114.1 Finite Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.2 Solution with Finite Differences Method . . . . . . . . . . . . . . 124.3 The Solution of Linear Boundary Value Problems with Finite

Differences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

5 Numerical solution with MATLAB 255.1 Why MATLAB? . . . . . . . . . . . . . . . . . . . . . . . . . . . 255.2 Solving the example with MATLAB . . . . . . . . . . . . . . . . 25

5.2.1 Finite Differences Method . . . . . . . . . . . . . . . . . . 255.2.2 Shooting Method . . . . . . . . . . . . . . . . . . . . . . . 28

6 Summary 32

2

Page 3: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

1 Introduction

The object of my dissertation is to present the numerical solution of two-pointboundary value problems.In some cases, we do not know the initial conditions for derivatives of a certainorder. Instead, we know initial and final values for the unknown derivatives ofsome order. These type of problems are called boundary-value problems.Most physical phenomenas are modeled by systems of ordinary or partial dif-ferential equations. Usually, the exact solution of the boundary value problemsare too difficult, so we have to apply numerical methods.

We used different numerical methods for determining the numerical solutionsof Cauchy-problem. One of them is the Explicit Euler method, which is thesimplest scheme.

The Improved Euler method is the simplest of a family of similar predictor-corrector methods following the form of a single predictor step and one or morecorrector steps. One subgroup of this family are the Runge-Kutta methodswhich use a fixed number of corrector steps. The Improved Euler method is thesimplest of this subgroup.

All the methods given can be applied to higher of ordinary differential equa-tions, provided it is possible to write an explicit expression for the highest orderderivative and the system has a complete set of initial conditions.

Motivation

The following example describes a physical task what we can use in practiceand it originates from a two-point boundary value problem.

Shooting Problem

We launch a cannonball from a fixed place. Let y(t) be the height of the can-nonball and x(t) the distance from the fixed place at t ≥ 0 moment.Moreover we suppose that the horizontal speed is constant, the vertical distancedepends only on the gravitation, so we dispense with the drag co-efficient.The goal is to determine the angle of the launch, if the cannonball is located inplace x = L!

The continous mathematical model of the problem is the following:

x′(t) = v, y′′(t) = −g,x(0) = 0, y(0) = 0.

(1)

The solution of the second equation with the initial condition is:

3

Page 4: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

x(t) = vt,which means that

t = xv .

Let us introduce a new function Y (x) as follows:

y(t) = y(xv ) = Y (x).

Then, using the chain rule, we get

y′(t) =dY

dx

dx

dt=dY

dxv,

y′′(t) = vd2Y

dx2v = v2

d2Y

dx2.

(2)

Hence, we obtain the problem:

Y ′′(x) = − g

v2, x ∈ (0, L),

Y (0) = 0, Y (L) = 0.(3)

This problem can be easily solved and the solution is:

Y (x) =gx

2v2(L− x). (4)

Then we can determine the angle of the launch from the following relation:

tan(α) = Y ′(0) =gL

2v2. (5)

Summarize the shooting problem, according to (5) the solution always exists.It means we can lauch the cannonball to every distance. But it is a paradox inthe reality.

4

Page 5: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

2 Solvability of Boundary Value Problems

In this section, we appoit the two-point boundary value problem generally.

Definition 1 Let f : R3 → R given function and α, β are given numbers. Theproblem

u′′ = f(t, u, u′), t ∈ (a, b), (6)

u(a) = α, u(b) = β (7)

is called two-point boundary value problem.

When we analyze the Cauchy problem for the ordinary differential equation offirst order in the form

u′(t) = g(t, u), (8)

u(t0) = u0. (9)

we have seen that the solvability depends only on the function f . The followingtheorem gives sufficient condition of the existance. The theorem connect to thisproblem:

Theorem 1 Suppose g : [t0 − α, t0 + α] × B(a, β) → R is continous andbounded by M. Suppose, furthermore, that g(t, ·) is Lipschitz countinous withLipschitz constant L for every t ∈ [t0 − α, t0 + α] . Then the problem (8), (9)

has a unique solution u(t) defined on [t0 − b, t0 + b], where b = min{α, βM

}.

If we analyze boundary value problems (6), (7) the situation is different. Aswe will see, both the function f and the boundary value determine the resulttogether.

Example

Let f(t, u, u′) = 1− u, hence the equation (6) has the form

u′′ + u = 1.

The arbitrary solution of this differental equation is u(t) = c1 cos t+ c2 sin t+ 1,where c1, c2 are constants. We analyze different boundary conditions in (7),which should define these constans.

5

Page 6: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

• Firstly, let us put a = π4 , α = 2, b = π, β = 2. The solution is unique:

c1 = −1, c2 =√

2 + 1.Hence, the unique solution is u(t) = −1 cos t+ (

√2 + 1) sin t+ 1.

• If we put a = π4 , α = 2, b = 5π

4 , β = 2, then the problem has no solution,because do not exist such constants c1, c2 for which the boundary value istrue.

The following theorem gives sufficient condition.

Theorem 2 Suppose that, T = (t1, s1, s2) : t ∈ [a, b], s1, s2,∈ R and f : R3 →R is a given function with the properties

• f ∈ C(T ),

• ∂1f, ∂2f ∈ C(T ),

• ∂2f > 0 on T,

• there exists a nonnegative constant M such that |∂3f | ≤M on T.

Under these conditions the two-point boundary value problem (6), (7) has uniquesolution.

Corollary

Let us consider the special case when f is linear,

u′′ = f(t, u, u′) = p(t)u′ + q(t)u+ r(t), t ∈ (a, b),u(a) = α, u(b) = β

where p, q, r ∈ C[a, b] are continous functions. If q(t) > 0 for all t ∈ [a, b], thenthe linear boundary value problem has a unique solution, because the conditonsof Theorem 2 mean the following

• p(t)s1 + q(t)s2 + r(t) ∈ C(T ),

• ∂1f = r(t), ∂2f = q(t) ∈ C(T ),

• ∂2f = q(t) > 0,

• ∂3f = p(t), i.e |p(t)| is bounded.

Obviously, tehere conditons are sutisfied.

6

Page 7: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

3 Shooting Method

3.1 Introduction

Consider this two-point boundary value problem:

u′′ = f(t, u, u′), t ∈ [a, b] (10)

u(a) = α, u(b) = β.

When we use the Shooting Method, we transform (10) into the Cauchy-problemof the form

u′′ = f(t, u, u′) (11)

u(a) = α, u′(a) = c. (12)

where c is an unknown number.

Obviously, the solution of the problem (11), (12) depends on the choice of theunknown parameter c. Therefore we use the notation u(t, c) for the solution ofthis problem. Our aim is to define c such that u(b, c) = β.

Let G : R → R function, defined as G(c) = u(b, c)− β.

Hence, we search for c∗ defined as:

G(c∗) = 0. (13)

Therefore, the realization of the Shooting Method needs the solution of some(usually nonlinear) equation. Finding the root needs to apply some numericalmethod. Its realization can be in different ways.

3.2 Intervallum-Bisection Method

The Intervallum-Bisection Method is one of the best simple method. We searchfor two values c1 and c2 such that G(c1)G(c2) < 0, so we can determine the rootby we consecutive halving the intervallum.

The Shooting Method Intervallum-Bisection’s algorithm

1. We fix any value, c.

2. We solve an initial value problem with (3), (4) some known numericalmethod an the interval [a, b].

7

Page 8: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

3. In the first step we search for two c values, for which the t = b point valueswill be different signs. These values are notated as c1 and c2.

4. Execute second step with c = 0.5(c1 + c2).

5. We define the sign of G(c).

6. We reselect new c1 or c2 value and contiunue the method.

7. When the two end points between the distance is less then ε > 0 value,we stop the iteration.

3.3 Chord Method

The Shooting Chord Method’s algorithm

1. Let c(0) and c(1) be any two given values.

2. We solve the initial value problem (3), with a numerical method on inter-val [a, b] with c(0) and c(1), respectivelly.

3. Hence G(c(0)) = u(b, c(0)) and G(c(1)) = u(b, c(1)).

4. We use linear interpolation between the points (c(0), G(c(0))) and (c(1), G(c(1))),in order to determine the point c(2), where this approximation turns intozero:

c(2) = c(1) −(

c(1) − c(0)

G(c1)−G(c(0))

)G(c(1))

5. We define G(c(2)).

6. For any steps, we use the iteration:

c(k) = c(k−1) −(

c(k−1) − c(k−2)

G(ck−1)−G(c(k−2))

)G(c(k−1)), k = 2, 3...

8

Page 9: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

and after that, we determine G(c(k)) value.

7. When∣∣G(c(k))

∣∣ is less then some fixed ε > 0 value, we stop the iteration.

3.4 Newton Method

The Newton Method for the solution of the nonlinear equation has the form.We assume that G is differentiable and G′ 6= 0. Then

cn+1 = cn −G(cn)

G′(cn), n = 0, 1, 2, ...

Problem: how to define the derivative G′(u)?

Let u = u(t, c) the solution. Then from (10) we have

u′′(t, c) = f(t, u(t, c), u′(t, c))), t ∈ (a, b) (14)

u(a, c) = α, u′(a, c) = c. (15)

Let us define the derivative of (14), (15) with respect to the paratmeter c.

∂u′′

∂c(t, c) = ∂2f(t, u(t, c), u′(t, c))

∂u

∂c(t, c) + ∂3f(t, u(t, c), u′(t, c))

∂u′

∂c(t, c) (16)

∂u(a, c)

∂c= 0,

∂u′(a, c)

∂c= 1.

If we define the new function:

w(t) =∂u

∂c(t, c), (17)

then we obtain

w′′(t) = ∂2f(t, u(t, c), u′(t, c))w(t) + ∂3f(t, u(t, c), u′(t, c))w′(t), (18)

w(a) = 0, w′(a) = 1.

The problem (18) is a Cauchy problem, which can be solved numerically bysome standard method.Hence G′(c) = w(b), therefore it will be the solution of the task.

9

Page 10: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

We summarize the Newton Method’s algorithm

1. Let c ∈ R .

2. We solve the u′′ = f(t, u, u′), u(a) = α, u′(a) = cn.

3. We determine the solution of this differential equation:

w′′ = ∂2f(t, u, u′)w + ∂3f(t, u, u′)w′

w(a) = 0, w′(a) = 1.

4. If |u(b)− β| < ε → stop.

If |u(b)− β| ≥ ε, then cn+1 = cn −u(b)− βw(b)

and we continue from the

step 2 by putting c = cn+1.

Summary

As we can see a large variety of different methods can be used to solve two-pointboundary value problems. The intervallum-bisection method and chord-methodare of first oreder method.

The chord-method’s advantage in front of the intervallum-bisection method. Wedo not search two initial points, where values will have different signs. We canstart with any given c(0) and c(1) values. On the other hand, the convergenceof the method can not be provided.

The Newton-method is second order method. Hence, it is more efficient, thanintervallum-bisection method and chord-method. Otherwise, the Newton-methodis needed to calculate the derivative. If the root is too far from the initial value,the Newton method does not converge.

For this reason, in most practical applications we determine the maximum num-ber of the iterations.

In some cases, the numerical problems can be badly conditioned. It is not pos-sible to solve these with standard shooting method, so we have to use multipleshooting-methods. (We suggest to read more about book [3].)

10

Page 11: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

4 Finite Difference Schemes

As we have seen in the last section, the use of the shooting method is demand-ing.

In the this section, we describe the numerical solutions of two-point boundaryvalue problems by using finite difference method.

The finite difference techniques are based upon the approximations that allowto replace the differential equations by finite difference equations. These finitedifference approximations are in algebraic form, and the unknowns solutionsare related to grid points. Thus, the finite difference solution basically involvesthree steps:

1. We define the sequence of the meshes on the solution domain [a, b].

2. We approximate the given differential equation by the system off differenceequations that relates the solutions to grid points.

3. We solve the above algebraic system of the equations.

4.1 Finite Differences

Henceforward, we use these relations:

u′(t) =u(t+ h)− u(t)

h− 1

2hu′′(ξ1) (19)

u′(t) =u(t)− u(t− h)

h+

1

2hu′′(ξ2) (20)

u′(t) =u(t+ h)− u(t− h)

2h− 1

6h2u′′′(ξ3) (21)

u′′(t) =u(t+ h)− 2u(t) + u(t− h)

h2− 1

12h2u(4)(ξ4) (22)

where ξi ∈ (t, t+ h)(i = 1, 2, 3, 4) are fixed numbers.These relations can be verified easily by use of the Taylor expansion with re-mainder in Lagrange form.

If the function u(t) is smooth enough, we can approximate function u(t) in somefixed point t∗.

This gives the idea to approximate the derivative of u(t)(smooth enough) func-tion in a fixed point t∗ as follows

11

Page 12: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

u′(t∗) ∼=u(t∗ + h)− u(t∗)

h, u′(t∗) ∼=

u(t∗)− u(t∗ − h)

h, (23)

u′(t∗) ∼=u(t∗ + h)− u(t∗ − h)

2h, u′′(t∗) ∼=

u(t∗ + h)− 2u(t∗) + u(t∗ − h)

h2

4.2 Solution with Finite Differences Method

Let

ωh =

{ti = a+ ih, i = 0, 1, ...., N + 1, h =

b− aN + 1

}(24)

be an equisdistante mesh, where N ∈ Rh is the step-size of mesh, i.e, .

Let ωh denote the inside points of the mesh,

ωh =

{ti = a+ ih, i = 1, ...., N, h =

b− aN + 1

}, (25)

finally γh is the boundary-points of the mesh:

γh = {t0 = a, tN+1 = b} . (26)

Assume that, (9),(10) has unique solution, that is there exists a function u(t) ∈C2[a, b] such that

u′′(t) = f(t, u(t), u′(t)), t ∈ (a, b), (27)

u(a) = α, u(b) = β.

Hence, substituting the mesh-points ti ∈ ωh into (27), we obtain the relation:

u′′(ti) = f(ti, u(ti), u′(ti)), i = 1, 2, ..., N, (28)

u(t0) = α, u(tN+1) = β.

When f is some given smooth function, for it’s derivatives we will use theforward-difference, backward-difference, and central-difference formulas respec-tively.

The forward-difference formula, which is based on (19) is the following:

yx,i = yi+1−yih .

The backward-difference formula, which is based on (20) is the following:

yx,i = yi−yi−1

h .

The central-difference formula, which is based on (21) is the following:

yx◦,i = yi+1−yi−1

2h .

12

Page 13: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

If we use these relations we get

yxx,i = f(ti, yi, yx,i), i = 1, 2, ..., N, (29)

y0 = α, yN+1 = β.

yxx,i = f(ti, yi, yx,i), i = 1, 2, ..., N, (30)

y0 = α, yN+1 = β.

yxx,i = f(ti, yi, yx◦,i), i = 1, 2, ..., N, (31)

y0 = α, yN+1 = β.

This picture shows the numerical derivatives to the function f at the pointP, with different formulas: forward, backward, and central differences. Theforward-difference and backward-difference are first order, the central-differenceis second order approximations for the first derivative in x0 point.

If we use this relation for the derivatives, we will have equations for theunknown value yi as follows from the (29) relation:

f(ti, yi,yi+1 − yi

h) =

yi+1 − 2yi + yi−1h2

, i = 1, 2, ..., N, (32)

13

Page 14: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

y0 = α, yN+1 = β.

We can solve simultaneously these equations, where y0, y1, ..., yN+1 are the un-konown values.

But, we do not know the answer for the following questions:

• Does an unique solution exist for the system (32)?

• How can we provide a solution for the system efficiently?

• Is the approximation yi far from the exact solution u(ti)?

4.3 The Solution of Linear Boundary Value Problems withFinite Differences

In this section we apply the difference method to find the solution of linearboundary value problems of the form:

u′′ = p(t)u′ + q(t)u+ r(t), t ∈ [a, b], (33)

u(a) = α, u(b) = β.

We have seen in the chapter 2, that this problem has a unique solution when:p, q, r ∈ C[a, b] and q(t) > 0 at intervall [a, b].

Let us denote by pi = p(ti), qi = q(ti) and ri = r(ti).

Theorem 3 The finite difference discretization of the linear boundary valueprobelm (33) results in a system of linear algebraic equations of the form

aiyi−1 + diyi + ciyi+1 = −ri, i = 1, 2, ..., N (34)

y0 = α, yN+1 = β

where the coefficients have

|di| − |ai| − |ci| = qi > 0. (35)

Proof

The discretization for the (31) problem is:

yi+1 − 2yi + yi−1h2

= piyi+1 − yi

h+ qiyi + ri, i = 1, 2, ...., N, (36)

y0 = α, yN+1 = β.

14

Page 15: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

It is a linear system of equations.

If we choose:

ai = − 1

h2, di =

2

h2+ qi −

1

hpi, ci = − 1

h2+

1

hpi, (37)

we will get the (34) task.

When h is small enough:

|di| − |ai| − |ci| =1

h2((2 + h2qi − hpi)− 1− (1− hpi)) = qi. (38)

If we use the discretization (30), we will be able to determine ai, di, ci easily:

ai = − 1

h2− 1

hpi, di =

2

h2+ qi +

1

hpi, ci = − 1

h2. (39)

We can get another relations, when we use the discretization (29):

ai =−1

h2− 1

2hpi, di =

2

h2+ qi, ci =

−1

h2+

1

2hpi. (40)

Let ei be the difference between the exact and the approximate values at thepoint t = ti. It means: ei = ui − yi.Then we introcude the error function as follows:

eh(ti) = ei

Definition 2 A numerical method is called convergent, if the error functiontends to zero, when h→ 0, that is:

limh→0

eh = 0. (41)

If eh = O(hp), we call the numerical method of pth-order method.

Theorem 4 The (37), (39), (40) finite differenc method is convergent of theform to the solution of the linear boundary value problems,

1. the method of (40) is second-order,

2. the (37) and (39) are first-order methods.

15

Page 16: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

Proof

1., Firstly we prove the second statement.If we use (21) and (22) relation in t = ti point:

ui+1 − 2ui + ui−1h2

− 1

12h2u(4)(ξ

(i)4 ) = pi

(ui+1 − ui−1

2h− 1

6h2u′′′(ξ

(i)3 )

)+qiui+ri.

(42)From the last relation we get:(− 1

h2+pi2h

)ui+1 +

(2

h2+ qi

)ui +

(− 1

h2− pi

2h

)ui−1 = −ri − h2gi, (43)

where

gi =1

12u(4)

(ξ(i)4

)− pi

6u′′′(ξ

(i)3 ). (44)

Hence we can write as

aiui−1 + diui + ciui+1 = −ri − h2gi. (45)

If we use the relation (32), we will get a linear system of equations:

aiei−1 + diei + ciei+1 = −h2gi, i = 1, 2, ..., N, e0 = eN+1 = 0 (46)

The ith equation of (46) can be writtem as

diei = −aiei−1 − ciei+1 − h2gi. (47)

We estimate (46) in the absolult value

|di||ei| ≤ |ai||ei−1|+ |ci||ei−1|+ h2|gi| ≤ (|ai|+ |ci|)||eh||∞ + h2||g||∞ (48)

Let i0 be the index, for which ||eh||∞ = |ei0 |. Since this statement is true forall i = 1, 2, ..., N , we have

|di0 |||eh||∞ ≤ (|ai0 |+ ci0)||eh||∞ + h2||g||∞ (49)

We can get from (49)

(|di0 | − |ai0 | − |ci0 |)||eh||∞ ≤ h2||g||∞ (50)

If we use the property (35)

qi0 ||eh||∞ ≤ h2||g||∞ (51)

Use the qmin ≥ 0 relation, we get:

||eh||∞ ≤ h2||g||∞qmin

≤ Ch2, (52)

16

Page 17: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

where

C =

(M4

12+pmaxM3

6

)/qmin, Mj = max|u(j)|, pmax = max|p|.

It means, that in case h→ 0, the method have second-order convergence.

Now we prove the first statementIf we use (19) and (22) relations in the point t = ti:

ui+1 − 2ui + ui−1h2

− 1

12h2u(4)(ξ

(i)4 ) = pi

(ui+1 − ui

h− 1

2hu′′(ξ

(i)1 )

)+ qiui + ri.

(53)We get from the last relation:(− 1

h2+pih

)ui+1 +

(2

h2+ qi −

1

hpi

)ui +

(− 1

h2

)ui−1 = −ri − hgi, (54)

where

gi = − 1

12u(4)(ξ

(i)4 ) +

pi2u′′(ξ

(i)1 ). (55)

Hence we can write with another notation as follows

aiui−1 + diui + ciui+1 = −ri − hgi. (56)

If we use the relation (32), we will get a system of linear algebraic equations:

aiei−1 + diei + ciei+1 = −hgi, i = 1, 2, ..., N, e0 = eN+1 = 0. (57)

The ith equation of (57) is

diei = −aiei−1 − ciei+1 − hgi. (58)

We estimate in absolult value this expression:

|di||ei| ≤ |ai||ei−1|+ |ci||ei − 1|+ h|gi| ≤ (|ai|+ |ci|)||eh||∞ + h||g||∞ (59)

Let i0 be an index, for which is ||eh||∞ = |ei0 |. Since, ∀i = 1, 2, ..., N true the(58) statement, hence

|di0 |||eh||∞ ≤ (|ai0 |+ ci0)||eh||∞ + h||g||∞ (60)

We can get from (58)

(|di0 | − |ai0 | − |ci0 |)||eh||∞ ≤ h||g||∞ (61)

If we use (35)qi0 ||eh||∞ ≤ h||g||∞ (62)

17

Page 18: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

Use the qmin ≥ 0 condition:

||eh||∞ ≤ h||g||∞qmin

≤ Ch, (63)

where

C =

(M4

12+pmaxM2

2

)/qmin, Mj = max|u(j)|, pmax = max|p| (64)

It means, if h→ 0, the method will be first-rate.

18

Page 19: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

This table shows the order of the finite different approximations.Now the ∇x means h.

Now we exlude the q(t) ≥ 0 conditon and use the case, where p(t) = 0. Letus consider the following boundary-value problem:

u′′ = r(t), t ∈ [a, b], (65)

u(a) = α, u(b) = β.

19

Page 20: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

We use the uniform mesh of the form

ωh = ti = ih, i = 0, 1, ..., N + 1, h =b− aN + 1

(66)

Using approximation for the second derivative, we obtaion for the parameterthe following

ai = − 1

h2, di =

2

h2, ci = − 1

h2. (67)

Hence, the task is to solve the system linear of algebraic equation of the form

Ahyh = bh, (68)

Where Ah ∈ RN×N is given matrix in the form

Ah =1

h2

2 −1 0 . . . 0 0 0 0−1 2 −1 . . . 0 0 0 0. . . . . . . . . . . . . . . . . . . . . . . .0 0 0 . . . 0 −1 2 −10 0 0 . . . 0 0 −1 2

and bh ∈ RN is a vector of the form

bh =

−r(t1) + αh2

−r(ti), i = 2, 3, ..., N − 1

−r(tN ) + βh2

Firstly, we show that this discretization is correct.

Theorem 5 The problem (68) has unique solution, for every h > 0.

Proof

We have to show that the matrix Ah is regular, hence the λ = 0 is not itseigenvalue. Let us determine the eigenvalues of the Ah matrix. Since the Ahmatrix is symmetric, the eigenvalues are real and hence Ahvk = λkvk.Hence, v0 = vN+1 = 0 and the vi co-ordinate of the vi eigenvalue:

−vi−1 + 2vi − vi+1

h2= λvi, i = 1, 2, ..., N (69)

We get this task:

vi−1 − 2(1− 0.5λh2)vi + vi+1 = 0, i = 1, 2, ..., N, (70)

v0 = 0, vN+1 = 0.

20

Page 21: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

We search for the solution of (68) in the form

vi = sin(pti), i = 0, 1, ..., N + 1, (71)

where, p ∈ R are some unknown numbers.

Subsituting in (71) into (69), we get:

sin(p(ti − h))− 2(1− 0.5λh2) sin(pti) + sin(p(ti + h)) = 0, i = 1, 2, ..., N (72)

Using these relationsin(p(ti − h)) + sin(p(ti + h)) = 2 sin(pti) cos(ph) for (69), we obtain

2 sin(pti) cos(ph)− 2(1− 0.5λh2) sin(pti) = 0, i = 1, 2, ..., N (73)

We can rewrite the last result in the form

(2 cos(ph)− 2(1− 0.5λhr)) sin(pti) = 0, i = 1, 2, ..., N (74)

Since, sin(pti) = vi and the eigenvalue v is not zero, at least for one index i wehave: vi 6= 0. Hence,

2 cos(ph)− 2(1− 0.5λh2) = 0. (75)

From the relation (75) we have

λ =2

h2(1− cos(ph)) =

4

h2sin2 ph

2. (76)

From (70) and (71) we get v0 = sin(p · 0) = 0, vN+1 = sin(p · l) = 0 coherenceswil be true. Because of this, pl = kπ therefore p = kπ

l .Using this relation in (76), we get the eigenvalues of matrix Ah :

λk =4

h2sin2 khπ

2l, k = 1, 2, ..., N. (77)

Otherwise, we can write the vk eigenvector from (71)

vk =

(sin

kπih

l

)Ni=1

, k = 1, 2, ..., N. (78)

Since, λk depends on h, we use the notation λk = λk(h)!Obviously, λk(h) > 0 for every k = 1, 2, ..., N , so we can determine the leasteigenvalue as

minλk(h) = λ1(h) =4

h2sin2

πh

2l. (79)

Let s denote a new variable:

s =πh

2l. (80)

21

Page 22: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

Since h ≤ l/2, we can write this relation for the least eigenvalue in the form

λ1(s) =π2

l2(sin s/s)2, s ∈

(0,π

4

](81)

The function sinxx is monoton decreasing at intervall (0, π4 ], so

infλ1(h) = λ1

(l

2

)=

16

l2sin2

π

4=

8

l2. (82)

Hence, for all l : λ1(h) ≥ 8l2 > 0. Therefore λ = 0 is not an eigenvalue.

Example

In the following example we show the numerical solution of boundary valueproblems by use of finite differences.

u′′(t) = 6t, (83)

su(0) = 0, u(2) = 8.

We use the uniform mesh with N = 4,

ωh ={ti = ih, i = 0, 1, 2, 3, 4, 5, h = 2

4+1 = 0, 4}.

Hence, the mesh points are

t0 = 0, t1 = 0.4, t2 = 0.8, t3 = 1.2, t4 = 1.6, t5 = 2.

By subsituting the last values, the matrix Ah has the form

Ah =

12.5 −6.25 0 0−6.25 12.5 −6.25 0

0 −6.25 12.5 −6.250 0 −6.25 12.5

and the vector bh is

bh =

−2.4−4.8−7.240.4

22

Page 23: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

We solve these system Ahyh = bh. Hence

yh =

0.0640.5121.7284.096

The exact solution at these points are:0.0640.5121.7284.096

The solution of the problem (83) is the function u(t) = t3.Therefore M4 = max

∣∣u4(t)∣∣ = 0. Since for this problem p(t) = 0, therefore

C = 0 in (64). The results in that the finite difference method is exact for thisproblem (83).

This example shows tha case, where M4 = max∣∣u4(t)

∣∣ 6= 0 and the result is notexact for this problem.

u′′(t) = 24t2,u(0) = 0, u(2) = 32.

We use the uniform mesh with N=4,

ωh ={ti = ih, i = 0, 1, 2, 3, 4, 5, h = 2

4+1 = 0, 4}.

Hence, the mesh points are

t0 = 0, t1 = 0.4, t2 = 0.8, t3 = 1.2, t4 = 1.6, t5 = 2.

By subsituting the last values, the matrix Ah has the form

Ah =

12.5 −6.25 0 0−6.25 12.5 −6.25 0

0 −6.25 12.5 −6.250 0 −6.25 12.5

and the vector bh is

bh =

−3.84−15.36−34.56138.56

23

Page 24: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

We solve these system Ahyh = bh.

Hence

yh =

0.25601.12644.454413.3120

The exact solution at these points are:

0.05120.81924.147213.1072

24

Page 25: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

5 Numerical solution with MATLAB

5.1 Why MATLAB?

In the following section we use MATLAB to solve boundary value-problems.We have seen the theory of the numerical solution.

Having a closer look on the numerical example we can see that by increasingthe number of the grid points the size of the equation system increasing rapidly.Unfortunatelly, - as the most of the mathematical problems - it very soon sur-pass the limit what can be managed by hand. This is the main reason why Ihave used MATLAB.

MATLAB is - coming from MATrix LABoratory - very effective, interactivesystem, what was developed for technological calculation and visual display ofcalculation results. It contains tools which make capable to solve the most com-mon tasks of numerical analysis, matrix algebra, signal processing and graphycalimagery.

One of it’s greatest benefit is in MATLAB the matrix is basic data structure.With MATLAB we can solve complex numerical problems by describing theproblem as we would do in math. Because of these we can determine the solu-tions very quickly and in a very effective way.

5.2 Solving the example with MATLAB

5.2.1 Finite Differences Method

The example is the same as in the section 4. It shows how to use MATLABto solve boundary value probelems with finite difference method. Firstly, wedefine the golobal values: α, β, h, l. Afther that, we make the vector b and thematrix A. In he last step we solve this equation system: Ahyh = bh.The h value shows the size of the step. If we increase the numbers of h, we willget better approximation.

% F i n i t e D i f f e r e n c e Method% u”( t)=r ( t ) , r ( t )=6 t% u(0)= a l f a , u ( l )=beta

% The d e f i n a t e o f the g l o b a l va lue sg l o b a l a l f a beta h l ;a l f a = 0 ;beta = 8 ;l = 2 ;n = 4 ;h = l /(n+1);

25

Page 26: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

% Making o f the vec to r bb = ze ro s (n , 1 ) ;b (1 ) = −6∗1∗h + ( a l f a /h ˆ 2 ) ;b (n) = −6∗n∗h + ( beta /h ˆ 2 ) ;f o r i = 2 : n−1

b( i ) = −6∗ i ∗h ;end

% Making o f the matrix AA = ze ro s (n , n ) ;A(1 , 1) = 2 ; A(1 , 2) = −1;A(n , n−1) = −1; A(n , n) = 2 ;f o r i = 2 : n−1

A( i , i −1) = −1;A( i , i ) = 2 ;A( i , i +1) = −1;

end

A = (1/hˆ2) ∗ A;

% The s o l u t i o n o f the systemy = A\b ;ym = l i n s p a c e (0 , 8 , n+2);ym( 2 : n+1) = y ;

% The c o r r e c t so lu t i on ’ s presentment% u( t ) = t ˆ3d e l t a = l i n s p a c e (0 , 2 , 1 0 0 ) ;u = d e l t a . ˆ 3 ;p = p lo t ( de l ta , u , ’ k ’ ) ;x l a b e l ( ’ i n t e r v a l l (0 , 2 ) ’ )t i t l e ( ’ Function approximation with F i n i t e D i f f e r e n c e s

Method (h =0.4) ’ )s e t (p , ’ Color ’ , ’ red ’ , ’ LineWidth ’ , 2)hold on ;

% Presentment o f the approximationi n t e r v a l l = l i n s p a c e (0 , 2 , n+2);p l o t ( i n t e r v a l l , ym, ’ k+ ’ , ’ LineWidth ’ , 2 ) ;

26

Page 27: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

The picture shows the correct and the approximation solutions with h = 0.4.

The picture shows the correct and the approximation solutions with h = 0.04.

27

Page 28: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

5.2.2 Shooting Method

The example is the same as in the section 3. It shows how to use MATLAB tosolve boundary value probelems with shooting method.

% Shooting Method f o r% u ’ ’ ( t ) = (u( t ) )ˆ3 on i n t e r v a l [ 1 , 2 ]% u( a ) = alpha = s q r t ( 2 ) , u (b) = beta = s q r t (2)/2% boundary value problem

alpha = s q r t ( 2 ) ;beta = 0.5∗ s q r t ( 2 ) ;i n t e r v a l = [ 1 , 2 ] ;e p s i l o n = 1e−6;h = 0 . 0 0 1 ;e r r o r = I n f ;i = 0 ;c = 0 ;

% f i n d i n g the c value , s e e s e c t i o n 3 .whi l e ( ( e r r o r > e p s i l o n ) && ( i < 10))

U = [ ] ;ode1 = @( t , u ) ( u ( 2 ) ) ;ode2 = @( t , u ) ( u ( 1 ) ˆ 3 ) ;[ t , U] = EulerMethod ( ode1 , ode2 , i n t e r v a l , [ alpha , c ] ,

U, h , ’ System ’ ) ;ode3 = @( t , z ) ( z ( 2 ) ) ;ode4 = @( t , z ) (3∗ z ( 1 ) ) ;[ t , Z ] = EulerMethod ( ode3 , ode4 , i n t e r v a l , [ 0 , 1 ] ,

U( : , 1 ) , h , ’ Der ivat ive ’ ) ;p l o t ( t ,U( : , 1 ) , ’ k : ’ ) ;hold on ;F = U( end , 1) − beta ;e r r o r = abs (F ) ;c = c − F/Z( end , 1 ) ;i = i + 1 ;

end

i ;U1 = U( : , 1 ) ;Y = s q r t (2)∗ ones ( l ength ( t ) , 1 ) . / t ;

p l o t ( t ,Y, ’ k ’ ) ;t i t l e ( ’ Shooting Method ’ ) ;

28

Page 29: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

t ex t ( 1 . 8 5 , 3 . 4 , ’ c ( 0 ) ’ ) ;t ex t ( 1 . 9 , 1 . 6 , ’ c ( 1 ) ’ ) ;t ex t ( 1 . 8 5 , 1 , ’ c ( 2 ) ’ ) ;t ex t ( 1 . 8 , 0 . 6 5 , ’ c (3)− c ( 5 ) ’ ) ; \ \ [ 2 0 pt ]% Euler Methodfunc t i on [ t Y] = EulerMethod ( ode1 , ode2 , i n t e r v a l , Y0 ,

U, h , Function )

% n : number o f the i n t e v a l p a r t i t i o n s% t : the i n t e r v a l devided to n+1 p a r t i t o n s% k : the s o l u t i o n o f the ode in the i . s t ep% Y: the vec to r o f the s o l u t i o nn = ( i n t e r v a l (2)− i n t e r v a l ( 1 ) ) / h ;t = l i n s p a c e ( i n t e r v a l ( 1 ) , i n t e r v a l ( 2 ) , n+1) ’ ;k = ze ro s (1 , 2 ) ;Y = Y0 ;

% c a l c u l a t i n g the Y vecto r − the s o l u t i o n o f the% d i f f e r e n t i a l systemf o r i =1:n

i f strcmp ( ’ System ’ , Function ) == 1s o l u t i o n 1 = f e v a l ( ode1 , t ( i ) , Y( i , : ) ) ;s o l u t i o n 2 = f e v a l ( ode2 , t ( i ) , Y( i , : ) ) ;k (1 , : ) = [ so lu t i on1 , s o l u t i o n 2 ] ;Y( i +1, : ) = Y( i , : ) + h∗k (1 , : ) ;

e l s es o l u t i o n 1 = f e v a l ( ode1 , t ( i ) , Y( i , : ) ) ;s o l u t i o n 2 = f e v a l ( ode2 , t ( i ) , Y( i , : ) ) ;k (1 , : ) = [ so lu t i on1 , s o l u t i o n 2 ∗(U( i , 1 ) ) ˆ 2 ] ;Y( i +1, : ) = Y( i , : ) + h∗k (1 , : ) ;

endend

29

Page 30: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

These pictures show the solutions. The continous line is the correct solution,the dotted lines are the approximation solutions. We can see the approximatonsconverge to the correct solutions.

The picture shows the correct and the approximation solutions with h = 0.1.

The picture shows the correct and the approximation solutions with h = 0.01.

30

Page 31: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

The picture shows the correct and the approximation solutions with h =0.001.

31

Page 32: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

6 Summary

In my dissertation I have showed the numerical solutions of two-point boundaryvalue problems. The ordinary differential equations are widely used in morepart of the life, for example mathematics, physics, economy, industry. Most ofthem are too diffucult, so we have to use numerical solutions.

As we have seen there are methods to determine the solution of the Cauchy-problem. (The Euler Method and the Improved Euler Method are one of thesimplest schemes.)In the boundary value problems there are given function f and the boundaryvalues, hence

u′′ = f(t, u, u′), t ∈ (a, b)u(a) = α, u(b) = β

We have seen two types of numerical solutions, the Shooting Method and theFinite Differences Scheme.When we use the Shooting Method, we transform the boundary value prob-lem into a Cauchy-problem. Therefore, we need to solve an algebraic equation(usually a nonlinear one). The realization can be done in different ways. Theintervallum-bisection method and chord-method are the simpliest, but they arefirst-rate. The chord-method’s advantage: we do not need to search for twoinitial points, where the values will have different signs. We can start with anygiven c(0) and c(1) values. On the other hand, the convergence of the methodcan not be provided.

The Newton-method is second order. Hence, it is more efficient than theintervallum-bisection method and the chord-method. Otherwise, the Newton-method is needed to calculate the derivative. If the root is too far from theinitial value, the Newton method does not converge.

The other chance to solve boundary value probelmes is the Finite DifferenceScheme. The finite difference techniques are based upon the approximationsthat allow to replace the differential equations by finite difference equations.These finite difference approximations are in algebraic form, and the unknownsolutions are related to grid points. Usually, we use these different formulas:forward, backward, and central differences. The forward-difference and thebackward-difference are first-rate, and the central-difference is a second-rate ap-proximation.

It is true for almost all of the numerical problems that, to solve them we haveto use computer resources because by hand only small problems can be solvedacceptable time. As we can see, MATLAB is one of the best choices to solvebigger tasks. With it I could declare and solve easily two-point boundary valueproblems. Beside the graphical capabilities MATLAB provides a simple inter-face for them, so the result of the tasks could be visualised in a quick and simpleway.

32

Page 33: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

All in all, the two-point boundary value problems are difficult, but with thenumerical solutions and an appropriate computer framework they can be solvedin effective way.

33

Page 34: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

References

[1] Istvan Farago, Robert Horvath: Numerikus modszerek, Typotex, 2011.

[2] Stoyan Gisbert: MATLAB, Typotex, 2005.

[3] R. Kress: Numerical analysis, Springer, 1998.

[4] C. F. Gerald, P. O. Wheatley, Addision: Applied Numerical Analysis, Addi-sion Wesley Longman, Inc., 1997.

34

Page 35: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

Acknowledgement

I would like to thank heartly all my teachers who have thought me.I am thankful for my thesis supervisor Istvan Farago support me to develop andunderstanding of the subject.This thesis wouldn’t have been accomplished without the help of my parentsand my fiance: Viktor Svantner.

35

Page 36: Numerical Solution of Two-Point Boundary Value Problemsweb.cs.elte.hu/blobs/diplomamunkak/bsc_matelem/... · Numerical Solution of Two-Point Boundary Value Problems B.S.c. Thesis

Nyilatkozat

Nev:

ELTE Termeszettudomanyi Kar, szak:

ETR azonosıto:

Szakdolgozat cıme:

A szakdolgozat szerzojekent fegyelmi felelossegem tudataban kijelentem, hogya dolgozatom onallo munkam eredmenye, sajat szellemi termekem, abban a hi-vatkozasok es idezesek standard szabalyait kovetkezetesen alkalmaztam, masokaltal ırt reszeket a megfelelo idezes nelkul nem hasznaltam fel.

Budapest, 20

a hallgato alaırasa

36