Download as pdf or txt
Download as pdf or txt
You are on page 1of 66

MA 214: Introduction to numerical analysis

Lecture 28

Shripad M. Garge.
IIT Bombay

( shripad@math.iitb.ac.in )

2021-2022

1/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals

Improper integrals result when either the function is unbounded or


the interval is unbounded.

The latter case is where the interval is pa, 8q, p´8, bq or


p´8, 8q.

In either circumstance, the normal rules of integral approximation


must be modified.

We will first consider the situation when the integrand is


unbounded at the left endpoint of the interval of integration.

In this case we say that f has a singularity at the endpoint a.

In fact, other improper integrals can be reduced to problems of this


form so this is a general case.

2/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals

3/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals

Our calculus courses tell us that the improper integral with a


singularity at the left endpoint
żb
dx
a px ´ 1qp

converges if and only if 0 ă p ă 1, and in this case we define


żb ˇx“b
dx px ´ aq1´p ˇˇ pb ´ aq1´p
“ lim “ .
a px ´ aqp MÑa` 1´p ˇ
x“M 1´p
ż1
dx
For instance, the improper integral ? converges (to 2) but
0 x
ż1
dx
2
diverges.
0 x

4/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals
g pxq
If f pxq “ where 0 ă p ă 1 and g : ra, bs Ñ R is
px ´ aqp
continuous then the improper integral
żb
f pxqdx
a

exists.

We will approximate this integral using the composite Simpson’s


rule, provided that g is 5-times continuously differentiable on
ra, bs, to be able to use the fourth Taylor polynomial, P4 pxq, for g
about a:
g 2 paq g 3 paq g p4q paq
P4 pxq “ g paq ` g 1 paqpx ´ aq ` px ´ aq2 ` px ´ aq3 ` px ´ aq4 .
2 3! 4!

5/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals

We write
żb żb żb
g pxq ´ P4 pxq P4 pxq
f pxqdx “ dx ` dx.
a a px ´ aqp a px ´ aqp

The latter integral can be computed easily, as P4 is a polynomial,


which is
4 ż b pkq 4
ÿ g paq ÿ g pkq paq
px ´ aqk´p dx “ pb ´ aqk`1´p .
k“0 a
k! k“0
k!pk ` 1 ´ pq

This is generally the dominant portion of the approximation,


especially when the P4 pxq agrees closely with g pxq throughout the
interval ra, bs.

6/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals
żb
g pxq ´ P4 pxq
We now need to determine dx. We define
a px ´ aqp
#
g pxq´P4 pxq
px´aqp if a ă x ď b
G pxq “
0 if x “ a.

pkq
Since 0 ă p ă 1 and P4 paq agrees with g pkq paq for k “ 0, . . . , 4,
G is 4-times continuously differentiable on ra, bs.

Therefore composite Simpson’s rule can be applied to approximate


the integral of G on ra, bs.

Adding this approximation to the value obtained in the previous


slide gives an approximation to the improper integral of f on ra, bs,
within the accuracy of the composite Simpson’s rule.

7/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
An example
ż1
ex
Compute ? dx.
0 x
x2 x3 x4
Here P4 pxq “ 1 ` x ` ` ` , so
2 6 24
ż1 ż1ˆ ˙
P4 pxq ´1{2 1{2 1 3{2 1 5{2 1 7{2
? dx “ x `x ` x ` x ` x dx
0 x 0 2 6 24
„ 1
2 1 1 1 9{2
“ lim 2x ` x 3{2 ` x 5{2 ` x 7{2 `
1{2
x
MÑ0` 3 5 21 108 M
2 1 1 1
“ 2` ` ` `
3 5 21 108

« 2.92354497354.

8/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
The example, continued
ż1
Now we need to approximate G pxqdx where
0
#
?1 pe x ´ P4 pxqq if 0 ă x ď 1
G pxq “ x
0 if x “ 0.

Using composite Simpson’s rule, we get


ż1
p0.25q
G pxqdx « rG p0q ` 4G p0.25q ` 2G p0.5q ` 4G p0.75q ` G p1qs
0 3
p0.25q
“ r0 ` 4p0.0000170q ` 2p0.0004013q
3
`4p0.0026026q ` 0.0099485s “ 0.0017691.

Hence
ż1
ex
? dx « 2.9235450 ` 0.0017691 “ 2.9253141.
0 x
9/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Singularity at b

If the integrand has a singularity at the right endpoint, b, and not


at a, then we could develop a similar technique making appropriate
changes.

Alternatively, we can make the substitution z “ ´x, dz “ ´dx to


get
żb ż ´a
f pxqdx “ f p´zqdz
a ´b
which has a singularity at the left endpoint now.

Then we can apply the left endpoint singularity technique we have


already developed.

10/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals

11/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals

If the integrand f has singularities at both the end points or if it


has a singularity at c P pa, bq then we can write
żb żc żb
f pxqdx “ f pxqdx ` f pxqdx
a a c

and use the techniques developed above.

The other type of improper integral involves infinite limits of


integration.
ż8
1
The basic integral of this type has the form p
dx for p ą 1.
a x

We use the substitution

t “ x ´1 , dt “ ´x ´2 dx, so dx “ ´x 2 dt “ ´t ´2 dt.

12/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
Improper integrals

Then ż0 ż 1{a
tp
ż8
1 1
dx “ ´ 2 dt “ dt.
a xp 1{a t 0 t 2´p
Similarly, if f is defined on ra, 8q then we use the substitution
t “ x ´1 to obtain
ż8 ż 1{a ˆ ˙
´2 1
f pxqdx “ t f dt.
a 0 t

It can now be approximated by the techniques developed above.

If a “ 0 or if both the endpoints are infinite then we write


żb żc żb
f pxqdx “ f pxqdx ` f pxqdx
a a c

for a suitable a ă c ă b and apply the above substitutions.


13/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
The fourth theme is complete

This completes the fourth theme of our course:

Numerical Differentiation and Integration.

From our next lecture, we will begin the next theme:

Ordinary Differential Equations.

14/2
shripad@math.iitb.ac.in MA214 (2021-2022) L28
MA 214: Introduction to numerical analysis
Lecture 29

Shripad M. Garge.
IIT Bombay

( shripad@math.iitb.ac.in )

2021-2022

15/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Ordinary differential equations

Differential equations are used to model problems in science and


engineering that involve the change of some variable with respect
to another.

Most of these problems require the solution of an initial-value


problem, that is, the solution to a differential equation that
satisfies a given initial condition.

In common real-life situations, the differential equation that


models the problem is too complicated to solve exactly, and one of
two approaches is taken to approximate the solution.

The first approach is to modify the problem by simplifying the


differential equation to one that can be solved exactly and then use
the solution of the simplified equation to approximate the solution
to the original problem.

16/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Ordinary differential equations

The other approach, which we will examine here, uses methods for
approximating the solution of the original problem.

This is the approach that is most commonly taken because the


approximation methods give more accurate results and realistic
error information.

The methods that we consider here do not produce a continuous


approximation to the solution of the initial-value problem.

Rather, approximations are found at certain specified, and often


equally spaced, points.

17/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Some basic material

A function f pt, y q is said to satisfy a Lipschitz condition in the


variable y on a set D Ă R2 if a constant L ą 0 exists with

|f pt, y1 q ´ f pt, y2 q| ď L|y1 ´ y2 |

whenever pt, y1 q and pt, y2 q are in D. The constant L is called a


Lipschitz constant for f .
Theorem
Let D “ tpt, y q : a ď t ď b, ´8 ă y ă 8u and f pt, y q be
continuous on D. If f satisfies a Lipschitz condition on D in the
variable y , then the initial-value problem

y 1 ptq “ f pt, y q, y paq “ α

has a unique solution y ptq for t P ra, bs.

18/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Well-posed problems

Initial-value problems obtained by observing physical phenomena


generally only approximate the true situation, so we need to know
whether small changes in the statement of the problem introduce
correspondingly small changes in the solution.

This is also important because of the introduction of round-off


error when numerical methods are used.

We say that an initial-value problem is well-posed if


(i) it has a unique solution, and
(ii) an initial-value problem obtained by small perturbations also
has a unique solution.

We make the above part more precise.

19/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Well-posed problem

Consider the initial-value problem


dy
“ f pt, y q, a ď t ď b, y paq “ α.
dt
We say that this is a well-posed problem if
‚ a unique solution, y ptq, to the problem exists, and
‚ there are 0 ą 0, k ą 0 such that for any 0 ą  ą 0, whenever
δptq is continuous with |δptq| ă  over ra, bs and when δ0 ă , the
initial-value problem
dz
“ f pt, zq ` δptq, a ď t ď b, zpaq “ α ` δ0
dt
has a unique solution, zptq, that satisfies

|zptq ´ y ptq| ă k for all t P ra, bs.


20/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Perturbed problem

The problem specified above, whose solution is zptq, is called a


perturbed problem associated with the original problem.

It assumes the possibility of an error being introduced in the


statement of the differential equation, as well as an error δ0 being
present in the initial condition.

Numerical methods will always be concerned with solving a


perturbed problem because any round-off error introduced in the
representation perturbs the original problem.

Unless the original problem is well-posed, there is little reason to


expect that the numerical solution to a perturbed problem will
accurately approximate the solution to the original problem.

21/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Condition ensuring well-posed property

The following theorem specifies conditions that ensure that an


initial-value problem is well-posed.

Theorem
Suppose D “ tpt, y q|a ď t ď b, ´8 ă y ă 8u. If f is continuous
and satisfies a Lipschitz condition in the variable y on the set D,
then the initial-value problem
dy
“ f pt, y q, a ď t ď b, y paq “ α
dt
is well-posed.

Now, we study the numerical methods to solve the initial-value


problems.

22/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Euler’s method

Euler’s method is the most elementary approximation technique for


solving initial-value problems.

Although it is seldom used in practice, the simplicity of its


derivation can be used to illustrate the techniques involved in the
construction of some of the more advanced techniques.

The object of Euler’s method is to obtain approximations to the


well-posed initial-value problem
dy
“ f pt, y q, a ď t ď b, y paq “ α.
dt

We will not obtain a continuous solution but we generate


approximations to y at various values, called mesh points, in the
interval ra, bs.

23/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Euler’s method

Once the approximate solution is obtained at the points, the


approximate solution at other points in the interval can be found
by interpolation.

We select the mesh points ti “ a ` ih, for each i “ 0, 1, . . . , N for


a positive integer N.

The common distance between the points

h “ pb ´ aq{N “ ti`1 ´ ti

is called the step size.

We will use Taylor’s Theorem to derive Euler’s method.

24/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
Euler’s method

Suppose that y ptq, the unique solution to the problem, has two
continuous derivatives on ra, bs, so that for each i “ 0, . . . , N ´ 1,

pti`1 ´ ti q2 2
y pti`1 q “ y pti q ` pti`1 ´ ti qy 1 pti q ` y pξi q
2
h2 2
“ y pti q ` hy 1 pti q ` y pξi q
2
for some ξi P pti , ti`1 q. This then gives

h2 2
y pti`1 q “ y pti q ` h f pti , y pti qq ` y pξi q.
2
Euler’s method constructs wi « y pti q, for each i by deleting the
remainder term.

We take w0 “ α and wi`1 “ wi ` hf pti , wi q for i ě 0.


25/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
An example

We illustrate Euler’s method by means of an example.

Consider the initial-value problem

y 1 “ y ´ t 2 ` 1, 0 ď t ď 2, y p0q “ 0.5.

Let us suppose that we want to approximate y p2q.

We take h “ 0.5. Here f pt, y q “ y ´ t 2 ` 1. We have w0 “ 0.5,

w1 “ w0 ` p0.5qpw0 ´ p0.0q2 ` 1q “ 0.5 ` 0.5p1.5q “ 1.25,


w2 “ 2.25, w3 “ 3.375, and y p2q « w4 “ 4.4375.
Geometrically, when wi is a close approximation to y pti q, the
well-posed property implies that

f pti , wi q « f pti , y pti qq “ y 1 pti q.

26/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
The example, continued

We now take N “ 10 and compare the results with the actual


values given by
y ptq “ pt ` 1q2 ´ 0.5e t .
We then have h “ 0.2, ti “ p0.2qi, w0 “ 0.5 and

wi`1 “ wi ` hpwi ´ ti2 ` 1q


“ wi ` p0.2qrwi ´ 0.04i 2 ` 1s
“ 1.2wi ´ 0.008i 2 ` 0.2

for 0 ď i ď 9. This gives w1 “ 0.8, w2 “ 1.152 and so on.

We compare the approximate values and the actual values in a


table in the following slide.

27/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
The example, continued

28/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
The example, continued

When we had h “ 0.5, the approximate value for y p2q was 4.4375
whereas for h “ 0.2 it is 4.8657845, much closer to the actual
value.

Note that the error grows slightly as the value of t increases.

This controlled error growth is a consequence of the stability of


Euler’s method, which implies that the error is expected to grow in
no worse than a linear manner.

We will study the error analysis of Euler’s method in our next


lecture.

29/2
shripad@math.iitb.ac.in MA214 (2021-2022) L29
MA 214: Introduction to numerical analysis
Lecture 30

Shripad M. Garge.
IIT Bombay

( shripad@math.iitb.ac.in )

2021-2022

30/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Euler’s method

We consider an initial-value problem


dy
“ f pt, y q, a ď t ď b, y paq “ α
dt
and give an approximate solution at equally spaced nodes in ra, bs.

The method begins by choosing a positive integer N, letting


h “ b´a
N and taking the nodes, ti “ a ` ih for i “ 0, . . . , N.

We then define w0 “ α and wi`1 “ wi ` hf pti , wi q for i ě 0.

We did an example in the last lecture with two different values of


N.

Now, we study the error pattern in this method.

31/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Error in Euler’s method

Theorem
Suppose f is continuous and satisfies a Lipschitz condition with
the constant L on D “ ra, bs ˆ R.
Assume that the unique solution, y ptq, to the initial-value problem

dy
“ f pt, y q, a ď t ď b, y paq “ α
dt
satisfies |y 2 ptq| ď M.
If wi for i “ 0, . . . , N, are the Euler approximations to y pti q then

hM ” Lpti ´aq ı
|y pti q ´ wi | ď e ´1 .
2L

32/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Error in Euler’s method

The result is true if i “ 0. Let us denote y pti q by yi . Then

h2 2
yi`1 ´ wi`1 “ pyi ´ wi q ` hrf pti , yi q ´ f pti , wi qs ` y pξi q
2
and
h2 M
|yi`1 ´ wi`1 | ď p1 ` hLq|yi ´ wi | `
2
h2 M h2 M
ˆ ˙
ď p1 ` hLq p1 ` hLq|yi´1 ´ wi´1 | ` `
2 2
2 2
ˆ ˙
h M h M
ď e pi`1qhL |y0 ´ w0 | ` ´
2hL 2hL
hM ` pti`1 ´aqL ˘
ď e ´1 .
2L

33/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Error in Euler’s method

The weakness of the above theorem is that we need to know a


bound for y 2 ptq.

Although this condition often prohibits us from obtaining a realistic


error bound, it should be noted that if Bf {Bt and Bf {By both exist,
the chain rule gives

dy 1 df Bf Bf
y 2 ptq “ ptq “ pt, y ptqq “ pt, y ptqq` pt, y ptqq¨f pt, y ptqq.
dt dt Bt By

So it is, at times, possible to obtain an error bound for y 2 ptq


without explicitly knowing y ptq.

The principal importance of the error formula is that the bound


depends linearly on the step size h. Consequently, diminishing the
step size gives greater accuracy to the approximations.

34/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Error in Euler’s method

We did not consider the round-off error while deriving the above
formula.

As h becomes smaller, more calculations are necessary and more


round-off error is expected.

In actuality then, we do not use

w0 “ α, wi`1 “ wi ` hf pti , wi q

but
u0 “ α ` δ 0 , ui`1 “ ui ` hf pti , ui q ` δi`1
where δ0 , . . . are the round-off errors.

We now describe an error bound for Euler’s method taking the


round-off errors into account.

35/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Error in Euler’s method

Consider the initial-value problem


dy
“ f pt, y q, a ď t ď b, y paq “ α
dt
satisfying the hypothesis of the above theorem.

Let u0 , . . . be the approximations in the Euler’s method with


round-off errors δi and assume that |δi | ă δ for all i.

Then
ˆ ˙
1 hM δ
|y pti q ´ ui | ď ` re Lpti ´aq ´ 1s ` |δ0 |e Lpti ´aq
L 2 h

Note that this error bound is not linear in h. In fact, the error will
be expected to be large for small step size.
36/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Local truncation error

Since the object of a numerical technique is to determine accurate


approximations with minimal effort, we need a means for
comparing the efficiency of various approximation methods.

The first device we consider is called the local truncation error of


the method.

The local truncation error at a specified step measures the amount


by which the exact solution to the differential equation fails to
satisfy the difference equation being used for the approximation at
that step.

We want to know how well the approximations generated by the


method satisfy the differential equation, not the other way around.

However, we don’t know the exact solution so we cannot generally


determine this.
37/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Local truncation error

The local truncation serves quite well to determine not only the
local error of a method but also the actual approximation error.

Consider the initial-value problem

y 1 “ f pt, y q, a ď t ď b, y paq “ α.

The difference method w0 “ α, wi`1 “ wi ` hφpti , wi q for


i “ 0, . . . , N ´ 1, has local truncation error

yi`1 ´ pyi ` hφpti , yi qq yi`1 ´ yi


τi`1 phq “ “ ´ φpti , yi q.
h h
This error is a local error because it measures the accuracy of the
method at a specific step, assuming that the method was exact at
the previous step.

38/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Local truncation error

Consider Euler’s method, for instance, where the difference


equation is w0 “ α and wi`1 “ wi ` hf pti , wi q.

The local truncation error is


yi`1 ´ yi h
τi`1 phq “ ´ f pti , yi q “ y 2 pξi q.
h 2
If one knows that |y 2 ptq| ď M for some M then the local
hM
truncation error is bounded by .
2
So the local truncation error in Euler’s method is Ophq.

We select difference-equation methods for solving initial-value


problems in such a manner that their local truncation errors are
Ophp q for as large a value of p as possible, while keeping the
number and complexity of calculations within a reasonable bound.
39/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Higher order Taylor methods

Since Euler method used Taylor’s theorem, we try using Taylor’s


theorem for higher orders.

Consider the initial-value problem

y 1 “ f pt, y q, a ď t ď b, y paq “ α

with f being n-times continuously differentiable.

By Taylor’s theorem

hn pnq hpn`1q pn`1q


y pti`1 q “ y pti q ` hy 1 pti q ` ¨ ¨ ¨ ` y pti q ` y pξi q
n! pn ` 1q!

for some ξ P pti , ti`1 q.

We can compute the derivatives of y at ti using the function


f pt, y q.
40/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
Higher order Taylor methods

Successive differentiation of y ptq gives

y 1 ptq “ f pt, y ptqq, y 2 ptq “ f 1 pt, y ptqq, ¨ ¨ ¨ , y pn`1q ptq “ f pnq pt, y ptqq.

Putting this in the above formula, we get

hn pn´1q hpn`1q pnq


yi`1 “ yi ` hf pti , yi q ` ¨ ¨ ¨ ` f pti , yi q ` f pξi , y pξi qq.
n! pn ` 1q!

The Taylor method of order n is then w0 “ α and


hn pn´1q
wi`1 “ wi ` hf pti , wi q ` ¨ ¨ ¨ ` f pti , wi q.
n!
Euler’s method is Taylor method of order one.

41/2
shripad@math.iitb.ac.in MA214 (2021-2022) L30
MA 214: Introduction to numerical analysis
Lecture 31

Shripad M. Garge.
IIT Bombay

( shripad@math.iitb.ac.in )

2021-2022

42/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
Taylor method of order n

Consider the initial-value problem


dy
“ f pt, y q, a ď t ď b, y paq “ α.
dt
The Taylor method of order n gives an approximate solution to the
above problem at equally spaced nodes ti “ a ` ih where h “ b´a
N .

These solutions are w0 “ α and wi`1 “ wi ` hT pti , wi q where

h hn´1 pn´1q
T pti , wi q “ f pti , wi q ` f 1 pti , wi q ` ¨ ¨ ¨ ` f pti , wi q.
2 n!

Let us now do some examples.

43/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
An example

Let us apply Taylor’s method of order two with N “ 10 to solve

y 1 “ y ´ t 2 ` 1, 0 ď t ď 2, y p0q “ 0.5.

We will need to compute y 2 “ f 1 pt, y q:

d
f 1 pt, y ptqq “ py ´t 2 `1q “ y 1 ´2t “ py ´t 2 `1q´2t “ y ´t 2 ´2t`1.
dt
Then
h
T pti , wi q “ f pti , wi q ` f 1 pti , wi q
2
h
“ wi ´ ti ` 1 ` pwi ´ ti2 ´ 2ti ` 1q
2

ˆ ˙ 2
h
“ 1` pwi ´ ti2 ` 1q ´ hti .
2
44/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

Since N “ 10, we get that h “ 0.2 and ti “ 0.2i for i “ 0, . . . , 10.


Then the method gives w0 “ 0.5 and
„ˆ ˙ 
h
wi`1 “ wi ` h 1 ` pwi ´ ti2 ` 1q ´ hti
2
„ˆ ˙ 
0.2 2
“ wi ` p0.2q 1 ` pwi ´ 0.04i ` 1q ´ 0.04i
2
“ 1.22wi ´ 0.0088i 2 ´ 0.008i ` 0.22.

We have
y p0.2q « 0.83 and y p0.4q « 1.2158.
We now list the values and the errors in the following table.

45/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

Order 2 and N “ 10.

46/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
Another example

We now apply Taylor’s method of order 4 with N “ 10 to the same


problem

y 1 “ y ´ t 2 ` 1, 0 ď t ď 2, y p0q “ 0.5.

We compute

f 1 pt, y ptqq “ y ´ t 2 ´ 2t ` 1,
d
f 2 pt, y ptqq “ py ´ t 2 ´ 2t ` 1q “ y 1 ´ 2t ´ 2
dt
“ py ´ t 2 ` 1q ´ 2t ´ 2 “ y ´ t 2 ´ 2t ´ 1,
d
f 3 pt, y ptqq “ py ´ t 2 ´ 2t ´ 1q “ y 1 ´ 2t ´ 2
dt
“ y ´ t 2 ´ 2t ´ 1.

47/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

Then
h h2 h3
T pti , wi q “ f pti , wi q ` f 1 pti , wi q ` f 2 pti , wi q ` f 3 pti , wi q
2 6 24
2 h 2
“ pwi ´ ti ` 1q ` pwi ´ ti ´ 2ti ` 1q
2
h2 h3
` pwi ´ ti2 ´ 2ti ´ 1q ` pwi ´ ti2 ´ 2ti ´ 1q
ˆ6 24
h h2 h3 h h2
˙ ˆ ˙
2
“ 1` ` ` pwi ´ ti q ´ 1 ` ` phti q
2 6 24 3 12
h h2 h3
`1 ` ´ ´ .
2 6 24

48/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

The method then gives w0 “ 0.5 and

wi`1 “ wi ` hT pti , wi q
h h2 h3
„ˆ ˙
“ wi ` h 1 ` ` ` pwi ´ ti2 q
2 6 24
h h2 h h2 h3
ˆ ˙ 
´ 1` ` phti q ` 1 ` ´ ´
3 12 2 6 24

With N “ 10 and h “ 0.2, this becomes

wi`1 “ 1.2214 wi ´ 0.008856 i 2 ´ 0.00856 i ` 0.2186.

y p0.2q « 0.8293 and y p0.4q « 1.214091.


We note the results in the next table.

49/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

Order 4 and N “ 10.

50/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

Order 2 Order 4

51/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

Suppose now that with this data, we want to approximate the


value of y at some other point, say at y “ 1.25.

We then use interpolation.

If we use linear interpolation on the nodes 1.2 and 1.4 then we get
ˆ ˙ ˆ ˙
1.25 ´ 1.4 1.25 ´ 1.2
y p1.25q « 3.1799640 ` 3.7324321
1.2 ´ 1.4 1.4 ´ 1.2
“ 3.3180810.

The true value is y p1.25q “ 3.3173285, so the error of this


approximation is 0.0007525, about 30 times the average of the
errors at 1.2 and 1.4.

We can improve upon this by using cubic Hermite interpolation on


the nodes 1.2 and 1.4.
52/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

For that we will need to compute the values of y 1 at these two


nodes:
y 1 p1.2q “ y p1.2q ´ p1.2q2 ` 1 « 2.7399640
and
y 1 p1.4q “ y p1.4q ´ p1.4q2 ` 1 « 2.7724321.
The corresponding cubic Hermite polynomial is

3.1799640 ` pt ´ 1.2qp2.7399640q ` pt ´ 1.2q2 p0.1118825q

`pt ´ 1.2q2 pt ´ 1.4qp´0.3071225q


Then

y p1.25q « 3.1799640 ` 0.1369982 ` 0.0002797 ` 0.0001152


“ 3.3173571.

53/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
The example, continued

This value is accurate to within 0.0000286, which is about the


average of the errors at 1.2 and at 1.4, and only 4% of the error
obtained using linear interpolation.

This improvement in the accuracy certainly justifies the added


computations required for the Hermite method.

54/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
Error in Taylor’s method

Theorem
If Taylor’s method of order n is used to approximate the solution to

y 1 “ f pt, y q, a ď t ď b, y paq “ α

with step size h then the local truncation error is Ophn q.

There are, of course, limitations and draw backs to this method.

The number of calculations of various derivatives of f pt, y ptqq is a


bit of a concern, even if the error is Ophn q.

We would like to reduce the number of calculations while keeping


the error to the similar order.

55/2
shripad@math.iitb.ac.in MA214 (2021-2022) L31
MA 214: Introduction to numerical analysis
Lecture 32

Shripad M. Garge.
IIT Bombay

( shripad@math.iitb.ac.in )

2021-2022

56/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Taylor method of order n

The Taylor methods outlined in the previous lectures have the


desirable property of high-order local truncation error.

But they also have the disadvantage of requiring the computation


and evaluation of the derivatives of f pt, y q.

This is a complicated and time-consuming procedure for most


problems, so the Taylor methods are seldom used in practice.

We would like to learn approximation methods to solve the


initial-value problems which do not require as high computations
and evaluations but have the error to the similar order.

We will study the Runge-Kutta method but before that we will


need the statement of Taylor’s theorem in two variables.

57/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Taylor’s theorem in two variables

Theorem
Suppose that f pt, y q and all its partial derivatives of order less
than or equal to n ` 1 are continuous on

D “ tpt, y q : a ď t ď b, c ď y ď du,

and let pt0 , y0 q P D. For every pt, y q P D, there exists ξ between t


and t0 and µ between y and y0 with

f pt, y q “ Pn pt, y q ` Rn pt, y q

where Pn is called the n-th Taylor polynomial in two variables for


the function f about pt0 , y0 q, and Rn pt, y q is the remainder term
associated with Pn pt, y q.

The error term Rn pt, y q involves ξ and µ.


58/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Taylor’s theorem in two variables
„ 
Bf Bf
Pn pt, y q “ f pt0 , y0 q ` pt ´ t0 q pt0 , y0 q ` py ´ y0 q pt0 , y0 q
Bt By
2 2 B2f

pt ´ t0 q B f
` pt 0 , y 0 q ` pt ´ t0 qpy ´ y0 q pt0 , y0 q`
2 Bt 2 BtBy
py ´ y0 q2 B 2 f

pt ,
0 0 y q ` ¨¨¨
2 By 2
« ff
n ˆ ˙ nf
1 ÿ n B
` pt ´ t0 qn´j py ´ y0 qj n´j j pt0 , y0 q
n! j“0 j Bt By

and
n`1
1 ÿ ˆn ` 1˙ B n`1 f
Rn pt, y q “ pt´t0 qn`1´j py ´y0 qj n`1´j j pξ, µq.
pn ` 1q! j“0 j Bt By

59/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Runge-Kutta Methods of Order Two

The first step in deriving a Runge-Kutta method is to determine


values for a1 , α1 and β1 with the property that a1 f pt ` α1 , y ` β1 q
approximates
h
T pt, y q “ f pt, y q ` f 1 pt, y q
2
with error no greater than Oph2 q. Since

df Bf Bf
f 1 pt, y q “ pt, y q “ pt, y q ` pt, y q ¨ y 1 ptq
dt Bt By
Bf Bf
“ pt, y q ` pt, y q ¨ f pt, y q
Bt By
we get
h Bf h Bf
T pt, y q “ f pt, y q ` pt, y q ` pt, y q ¨ f pt, y q.
2 Bt 2 By

60/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Runge-Kutta Methods of Order Two

Using Taylor’s theorem of order 1 we get

a1 f pt ` α1 , y ` β1 q “ a1 f pt, y q
Bf Bf
`a1 α1 pt, y q ` a1 β1 pt, y q
Bt By
`a1 R1 pt ` α1 , y ` β1 q

where
α12 B 2 f B2f β12 B 2 f
R1 pt ` α1 , y ` β1 q “ pξ, µq ` α 1 β1 pξ, µq ` pξ, µq
2 Bt 2 BtBy 2 By 2
for some ξ between t and t ` α1 and µ between y and y ` β1 .

We now match the equations for T pt, y q and a1 f pt ` α1 , y ` β1 q


and get some equations.

61/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Runge-Kutta Methods of Order Two

These equations are


Bf h Bf h
f pt, y q : a1 “ 1, pt, y q : a1 α1 “ , pt, y q : a1 β1 “ f pt, y q.
Bt 2 By 2
We then conclude
h h
a1 “ 1, α1 “ , and β1 “ f pt, y q
2 2
and get
ˆ ˙ ˆ ˙
h h h h
T pt, y q “ f t ` , y ` f pt, y q ´ R1 t ` , y ` f pt, y q
2 2 2 2

where the error R1 can be written as follows:

62/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Runge-Kutta Methods of Order Two

h2 B 2 f
ˆ ˙
h h
R1 t ` , y ` f pt, y q “ pξ, µq
2 2 8 Bt 2
h2 B2f
` f pt, y q pξ, µq
4 BtBy
h2 B 2 f
` pξ, µq
8 By 2
If all the second-order partial derivatives of f are bounded, then
ˆ ˙
h h
R1 t ` , y ` f pt, y q
2 2

is of Oph2 q. As a consequence, the order of error for this method is


the same as that of the Taylor method of order two.

63/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
Runge-Kutta Methods of Order Two

The difference-equation method resulting from replacing T pt, y q in


Taylor’s method of order two by
ˆ ˙
h h
f t ` , y ` f pt, y q
2 2

is a specific Runge-Kutta method known as the Midpoint-method.

It gives w0 “ α and
ˆ ˙
h h
wi`1 “ wi ` hf ti ` , wi ` f pti , wi q
2 2

for i “ 0, . . . , N ´ 1.

We do an example now.

64/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
An example

Use the Midpoint method with N “ 10, h “ 0.2, ti “ 0.2i, and


w0 “ 0.5 to approximate the solution to our usual example

y 1 “ y ´ t 2 ` 1, 0 ď t ď 2, y p0q “ 0.5.

The difference formula is

wi`1 “ 1.22wi ´ 0.0088i 2 ´ 0.008i ` 0.218.

for each i “ 0, . . . , 9.

The first two steps of these methods give

w1 “ 0.828, and w2 “ 1.21136.

The table is given on the next slide.

65/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32
The example, continued

66/2
shripad@math.iitb.ac.in MA214 (2021-2022) L32

You might also like