0% found this document useful (0 votes)
135 views

Makerere University: Chapter Four: Numerical Analysis

This document contains lecture notes on numerical analysis from Makerere University. It discusses numerical methods for finding roots of non-linear functions, including the bisection method and fixed point iteration. The bisection method involves repeatedly bisecting an interval and narrowing in on a root. Fixed point iteration rewrites a function in the form g(x)=0 and iteratively calculates xn+1=g(xn) to converge on a fixed point root of the function. Examples demonstrate applying each method to find specific roots.

Uploaded by

Dembeoscar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
135 views

Makerere University: Chapter Four: Numerical Analysis

This document contains lecture notes on numerical analysis from Makerere University. It discusses numerical methods for finding roots of non-linear functions, including the bisection method and fixed point iteration. The bisection method involves repeatedly bisecting an interval and narrowing in on a root. Fixed point iteration rewrites a function in the form g(x)=0 and iteratively calculates xn+1=g(xn) to converge on a fixed point root of the function. Examples demonstrate applying each method to find specific roots.

Uploaded by

Dembeoscar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

MAKERERE UNIVERSITY

COLLEGE OF ENGINEERING, DESIGN, ART AND TECHNOLOGY

SCHOOL OF ENGINEERING

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING

EMT 1201: ENGINEERING MATHEMATICS II LECTURE NOTES 2014/2015

CHAPTER FOUR: NUMERICAL ANALYSIS

Instructor: Thomas Makumbi


BSc. Eng. (MUK, Uganda)
MSc. RET (MUK, Uganda)
MSc. SEE (HIG, Sweden)

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


4. NUMERICAL ANALYSIS
Many of the problems that occur in engineering and physics have no analytical solution, and
even when one can be found it is frequently the case that the form in which it arises is difficult to
use directly if numerical results are required. There are many reasons for such limitations, some
typical ones being that the zeros of a function involved in the solution cannot be found
analytically, a definite integral that arises cannot be evaluated analytically, an analytical solution
of a nonlinear differential equation cannot be found, or a large system of linear simultaneous
equations must be solved. A situation of a different type arises when an analytical solution is
known, but its application in specific cases leads to a prohibitive amount of calculation, so a
more efficient numerical method becomes necessary.

4.1 Decimal places and significant figures

Most numerical results can only be approximate, such as calculations involving , e or π it is


necessary to have a simple way of indicating their accuracy. This is accomplished either by
stating that a result is accurate to n decimal places, or that it is accurate to a given number of
significant digits (figures). For example, when approximating a number such as 17.213622, to
three decimal places, the fourth digit after the decimal point is examined, and if the digit is 5 or
more the preceding digit is increased by one and the result truncated to three places after the
decimal point. However, if the fourth digit is 4 or less, the previous digit is left unchanged and
the result is truncated to the existing three digits that follow the decimal point. When this process
is applied to the above number to approximate it to an accuracy of three decimal places it
becomes 17.214, whereas if it is approximated to an accuracy of four decimal places it becomes
17.2136.

4.2 Roots of non – linear functions

Let f(x) be a real valued function on the interval . A number, , is called a root of the
function f(x) in this interval if and correspondingly a number, , is called a zero
of the function f(x).
The need to find roots of functions is fundamental to the development and application of
mathematics, and only in simple cases can the roots be determined analytically, so in all other
cases it is necessary to find them numerically.
Numerical determination of the roots of functions

4.2.1 The Bisection method


This method applies to roots of functions f (x) with the property that f (x) changes sign when x
crosses a root. This method can be easily programmed.

Consider a continuous function f(x) and numbers such that f(α) and f(β) have opposite
signs. Then by the intermediate value theorem, the function f(x) must varnish at least once (must
have at least one root, x0) in the interval as shown in the proceeding figures:

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Figure 4.1 Roots of a function y = f(x)

If f(α) and f(β), have the same sign, nothing can be deduced about the existence of a root in the
interval. Figs c – e illustrate situations in which there is a double root, two roots and no root
respectively.

Figure 4.2 Existence of a root(s) in the interval (α, β)

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Steps in the bisection method
 If the product f(α)f(β) is negative, it indicates that the function has opposite signs at the
extremes of the interval, but when the product is positive there is no such change
in sign.

 The first step in the bisection method involves dividing (bisecting) the interval,
into the subinterval and , where .

 If the product, the next subinterval to be considered in the proceeding step


is , obtained by replacing α by x1 because in this case, f (x) changes sign in the
subinterval so this interval must contain the root of f(x).

If the subinterval to be used in the next step is obtained by replacing β by x1


because in this case f(x) experiences a change of sign in the interval, and this
interval must contain the required root.
 The bisection method involves a repetition of this procedure each time using the smaller
subinterval found at the previous stage of the calculation, until a required degree of accuracy
is achieved.
Example 4.2.1

Use the bisection method to find the smallest root of the function correct
to 2 decimal places.
Solution
The function in question can be represented in the figure below:

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


From the figure it is clear that for values . Suitable values for α and β are
and because and .We wish to approximate
the root approximate to 2 dps hence our error should be within 0.005. xl and xr denote the x –
value at the extreme left and right of the given subinterval respectively.

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


n xl xr xn f(xl) f(xr) f(xl)f(xr) New interval

1 0.43 0.47 0.45 0.0405 0.0029 >0 0.45< x< 0.47


2 0.45 0.47 0.46 0.0029 -0.0157 <0 0.45<x<0.46 0.01
3 0.45 0.460 0.455 0.0029 -0.0064 <0 0.45<x<0.455 0.005
4 0.45 0.455 0.4525 0.0029 -0.0018 <0 0.45<x<0.4525 0.0025
Therefore, the root of the equation in question is 0.45 (2dps)

4.2.2 Fixed point iteration


This method is well suited to machine computation provided numerical values of the function
involved are easily calculated, and a good approximation to the root is used to start the iteration
process. The method involves first writing the given function f(x), in the form;

……………………………………………………………………….. (1)

Then if makes the expression on the right vanish, it follows that x0 is a root of f(x).
The expression of the function, f(x), is however, not unique because g(x) can be written in more
than one way.
If we now consider the function g(x) to map a point x into a point g(x), then a root x = x0 of
equation (1) has the property that g(x) maps the point x0 into itself, and for this reason x0 is called
a fixed point of the equation;

……………………………………………………………………………………… (2)
The fixed point iteration scheme follows from (2) by writing it as;

…………………………………………………………………………………. (3)
Example 4.2.2

Find a fixed point iteration scheme for determining when , and use it to determine
to an accuracy of six decimal places.
Solution

We need to determine x such that,

Therefore,

This can be written as, , dividing through by 2x we get;

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


So, in the notation of (2),
The fixed point iteration scheme is;

To compute , it is evident that, a = 2

For simplicity, we can take x0 = 1; then the results of the calculation are;

, , , , ,
.

Point x4 and x5 are identical and the difference , hence the required root is
1.414214 (correct to 6 dps)
Example 4.2.3
Devise fixed point iteration schemes to find the roots of the quadratic equation;
and test them numerically
Solution
The fixed iterative schemes of the equation can be obtained by either writing it in the forms;

or
Hence the two possible schemes are;

Scheme A: or

Scheme B:

Investigation of the quadratic shows that the quadratic has roots close to and
Using scheme A:
x0 = 10

x1 = 2.0417 x1 = 10.0417
x2 = 2.0557 x2 = 10.1113

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


x3 = 2.0605 .
x4 = 2.0621 .
x5 = 2.0627 x8 = 12.4801
x6 = 2.0630 x9 = 14.6877
. .
. .

Clearly scheme A is only partially successful, although when started at x0 = 2 it converges to a


zero close to 2 but it diverges when started at x0 = 10 and unsuccessful to determine the zero
close to 10.
Using Scheme B:

Here the scheme is also partially successful; although it can be successfully be used to determine
the zero close to 10, it can’t be used for that close to 2.
Convergence of a fixed point iterative scheme

Let g(x) be defined in the interval in which it has a fixed point x0, and let g(x) be
continuous throughout this interval with a continuous derivative, such that
. Then the equation has a unique fixed point x0 in the interval and if
the iterative scheme;

will converge to x0.

4.2.3 Newton’s method


The Newton’s method for determining the zero of the differentiable function f(x) = 0 is also
known as the Newton Raphson method. The method is commonly used because of its simplicity.

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


The idea in this method is that we approximate the graph of the function f by suitable tangents.
Consider Figure 4.3 below:

Figure 1.3 Newton's method

Using an approximate value x0 obtained from the graph of f, we let x1 be the point of intersection
of the x – axis and the tangent to the curve at x0, then;
f ( x0 ) f ( x0 )
tan   f ' ( x0 )  hence, x1  x0 
x0  x1 f ' ( x0 )
f ( x1 )
In the second step we compute x 2  x1  , in the third step we compute x3 from x2 using
f ' ( x1 )
f ( xn )
the same formula, so generally; xn 1  xn  .
f ' ( xn )
The following Algorithm therefore, describes the steps taken in finding the zero of the equation
f(x) = 0:
Newton Raphson Algorithm

INPUT: f, f’, initial approximation x0, tolerance (acceptable error), or maximum number of
iterations, N.

OUTPUT: Approximate solution, xn , or message of failure.


For n = 0, 1, 2, ……..N-1, the following is done:

1. Compute .

2. If, , then OUTPUT “Failure”. Stop. [Procedure completed unsuccessfully]


f ( xn )
3. Else compute, xn 1  x n  .
f ' ( xn )

4. If then OUTPUT . Stop.


Example 4.2.4

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Use Newton’s method to find the zeros of accurate to five decimal
places.
Solution
The function f(x) in question can be sketched as shown in the figure below:

The graph shows that the function has two zeros, one close to 0.5 and the other close to 1.6.

. Newton’s method becomes;

This problem requires determining the zero of the given function to 5 dps. Hence the tolerance,
of the problem is

For ;

n xn
0 0.500000
1 0.450200 0.0498
2 0.451541 0.001341
3 0.451542 0.000001
4 0.451542 0.000000
Hence the zero of the function close to 0.5 is 0.45154 (to 5 dps)

For

n xn

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


0 1.600000
1 1.552769 0.047231
2 1.549552 0.003231
3 1.549538 0.000014
4 1.549538 0.000000
Hence the zero of the function close to 1.60 is 1.54954 (to 5 decimal places)
This example illustrates how fast the Newton’s method can converge if a good initial
approximation is used.

4.2.4 The secant method


Newton’s method is very powerful but it has a disadvantage that it requires determination of the
derivative f’ that sometimes may be a far more difficult expression to determine and its
evaluation is therefore, computationally expensive. This situation suggests the idea of replacing
the derivative with the difference quotient;

Then instead of the Newton’s method formula, we have the popular secant method as;

Example 4.2.5

Find the positive solution of by the secant method, starting with x0 = 2 and
x1 = 1.9.
Solution
We have that;

Substituting numeric values, we get results in table below;

n xn-1 xn Nn Dn
1 2.000000 1.900000 -0.000740 -0.174005 0.004253
2 1.900000 1.895747 -0.000002 -0.0006986 0.000252
3 1.895747 1.895494 0 0 0
Hence the root is 1.895494 (correct to 6 Dps)

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Exercise 4.1
a) Use the bisection method to determine the required root:

-The root of close to

-The largest possible root of

-The root of
b) Use a fixed point iteration scheme to determine the required roots:

-Determine where and n is an integer. Check the result by finding

-Find the positive root of

-Find the roots of and check the results by using the quadratic formula.
c) Use Newton’s method to determine the required root:

-Find the root of

-Find the smallest root of

-Find the largest root of

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


4.3 Interpolation and extrapolation
Sometimes a function f (x) that is assumed to be smooth is only known in the form of a set of
discrete values at a set of arguments x1, x2,…..,xn such that .
When this occurs it often becomes necessary to estimate the value f (α) when α lies between two
of the known arguments xi . This process is called the interpolation of the function f (x) between
its known values.
Various interpolation methods exist with different errors committed in using each. Some of the
factors to be taken into account when choosing an interpolation method are whether f (x) appears
to be convex or concave for , whether it is oscillatory, and whether it exhibits sharp
curvature at a point or points belonging to the interval.
The estimation of f (α) when α lies outside the interval, either to the left of x1 or to the right of xn,
is called extrapolation of the function f (x), and as the process can be liable to considerable error
it should be used with care.

4.3.1 Linear interpolation

Let the data points belonging to an unknown smooth function


be plotted on a graph. Then the simplest way to estimate the value of y(x) when x lies
in the interval is to join the points and by a straight line and
then use the point on the line with argument x as the approximation of y(x). This process is called
linear interpolation and it is illustrated in Figure 4.4.

Figure 4.4 Linear interpolation

A simple calculation shows that the straight line segment representing the linear
interpolation function between the points and is given by;

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


If x is chosen so that either or , result (1) becomes a linear extrapolation formula
for outside the interval .
Result (1) is useful for interpolation when the variation of xi and yi between adjacent data points
is small, but as the formula introduces an error due to its failure to cater for the curvature of the
curve, the error can become large when the result is used for extrapolation.

4.3.2 Lagrange interpolation


Instead of using linear interpolation to join successive pairs of data points;
, it is possible that a better result can be obtained by constructing
a polynomial y = P(x) that passes through each data point. As a polynomial is a smooth curve, it
is to be hoped that it will take some account of the curvature of the function to which the data
points belong, as exhibited by a set of data points, and so provide a better interpolation formula.
The polynomial used in this equation is given by;
n
P( x)   Lk ( x) yk , where;
k 1

x  x1 x  x2 ....x  xk 1 x  xk 1 ....x  xn 


Lk ( x)  .......................................................(2)
xk  x1 xk  x2 ...xk  xk 1 xk  xk 1 ....xk  xn 
Therefore,

 For a curve that passes through the points, can be


approximated by the polynomial, . This can be re – written (using
result 2) as;

 For data 4 data points, , the Lagrange polynomial is


which can be obtained from result 2 as;

 Other higher order Lagrange polynomials for more than four data pairs are determined in a
similar way.
Note

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


(i) The polynomial has a highest degree of n -1, i.e. the degree of the polynomial has a degree
which is 1 less than the number of data points; 3 data points lead to a second degree
polynomial, 4 data points lead to a third degree polynomial, 5 data points lead to a forth
degree polynomial etc.
(ii) When n = 2, the result (2) reduces to a result of linear interpolation.

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Example 4.3.1
Given a certain unknown function, f(x), has the following values at the corresponding x – values:

x f(x)
1.5 0.405
2.1 0.742
3 1.099
Use Lagrange interpolation to find f(1.8).
Solution

From result,

Hence, (2 dps)
Example 4.3.2
Given a certain unknown function, f(x), has the following values at the cor-3.5responding x –
values:

x f(x)
1 0.368
1.2 0.301
1.3 0.273
1.5 0.223
Use Lagrange interpolation to find f(1.4).
Solution

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Another type of interpolation is the cubic spline interpolation method. You may read about this
method from reference books numbers 4 and 6.
Exercise 4.2

1. Graph the function in the interval . Select four points on the


graph and after constructing a polynomial that passes through each of the points graph the
polynomial and compare the result with the original graph.

2. Graph the function in the interval . Select five points on


the graph and after constructing a polynomial that passes through each of the points graph the
polynomial and compare the results with the original graph.

4.4 Numerical integration


The need for numerical integration, also called numerical quadrature, arises when either a
definite integral that is required cannot be evaluated analytically, or when special functions
involved in an analytical solution are too complicated to be of direct use. A typical definite
integral that can only be evaluated numerically is;
5
sin 3x

0 x2  x 1
dx , whose value can be determined to be 0.364873

4.4.1 The trapezoidal rule

The basis of this simple rule can be understood by Figure 4.5, in which the integral is
approximated by the area the trapezoid PQRS shown as the shaded area in the interval
.

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Figure4.2 The trapezoidal rule

Therefore, the approximation to the definite integral is;

……………………………………………………(1) In

this case,
If we denote the error in this approximation by E(h), then;

…………………………………………...(2)

A better estimate of the definite integral, can be obtained by dividing into


n subintervals, applying (1) to each of the n subintervals then summing the results. For
simplicity, it is important that all the subintervals have the same length, , where h is
usually called the step size. It is clear that the error drastically reduces when the number of
subintervals, n is made as big as possible and this is possibly done with the help of computer
programs e.g. a spread sheet can greatly help.

Setting for n =1, 2,3,…., we arrive at what is called the composite


trapezium rule;

Example 4.4.1

Use the composite trapezoidal rule with, n = 10, n = 30 and n = 50 subintervals to evaluate;
5
sin 3x
I  dx
0 x2  x 1

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Solution

For n = 10,

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


I xi f(xi) f(x0), f(xn) 2f(xi)
0 0 0.00000 0.00000

1 0.5 0.754035 1.50807

2 1 0.081476 0.162952

3 1.5 -0.44852 -0.89704

4 2 -0.10561 -0.21122

5 2.5 0.300400 0.6008

6 3 0.114301 0.228602

7 3.5 -0.21494 -0.42988

8 4 -0.11709 -0.23418

9 4.5 0.158398 0.316796

10 5 0.116795 0.116795
Sum 0.116795 1.0449
Therefore,
5
 0.5  0.116795  1.0449  0.29042
sin 3x 1

0 x  x 1
2
dx 
2

Repeating the procedure for n = 30 and n = 50, using a computer we get and
respectively.

4.4.2 Simpson’s rule

In the trapezoidal rule, we approximate the function for the interval by a


straight line segment. A more accurate result would be expected if a point on the curve
is chosen inside the interval and f(x) is approximated by a parabola that passes
through the two endpoints and the single internal point as shown in Figure 4.6.

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Figure4.3 Simpson’s rule

Setting , where h is the step size, and taking an additional point in the interval to be
such that it is midway between a and b, the parabola must pass through the three
consecutive points; , by the Lagrange
interpolation formula, this parabola is given by;

Integrating L(x) over the interval and simplifying the result gives;

………………………………………….(1)
Result (1) is known as the Simpson’s rule or the Simpson’s 1/3 rule. Equation (1) can also be re –
written in the form;

The accuracy of the Simpson’s rule can also be improved by increasing the number of
subintervals, but because the rule involves constructing parabolas through three consecutive
equidistant points, to use the rule for more than three points in the interval the number of points
chosen must be odd so the number of intervals must be even.

Dividing the interval into 2n equal subintervals each of length , and adding
the results gives the composite Simpson’s rule;

This expression can be easily remembered from;

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Where, h – step length i.e. the length of each strip
F+L – sum of the first and last ordinates
4E – 4 times the sum of the even positioned ordinates
2R – 2 times the sum of the remaining odd positioned ordinates.
Example 4.4.2
Use the composite Simpson’s rule with, n = 10, n = 30 and n = 50 subintervals to evaluate;
5
sin 3x
I  dx
0 x2  x 1
Solution
For n = 10

xi f(xi) F+L E R
0 0 0
0.5 0.754035 0.754035
1 0.081476 0.081476
1.5 -0.44852 -0.44852
2 -0.10561 -0.10561
2.5 0.3004 0.3004
3 0.114301 0.114301
3.5 -0.21494 -0.21494
4 -0.11709 -0.11709
4.5 0.158398 0.158398
5 0.116795 0.116795
Sum 0.116795 0.549369 -0.02692

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Repeating the procedure using a spread sheet (on a computer) for n = 30 and n = 50, the integral
is; and respectively.

4.4.3 Gaussian Quadrature

If when evaluating numerically an integral in the standard form, , the points xi at


which the values of the integrand f (x) are sampled are chosen in a special way, then when n
sample points are used the result can be made exact in the case that f (x) is an arbitrary
polynomial of degree 2n − 1 or less. Unlike Simpson’s rule, in this method the n sample points xi
are non – uniformly spaced throughout the interval of integration.
The sample points, or nodes as they are called, are chosen to get a formula that will integrate
exactly polynomials of as high degree as possible. It turns out that the n sample points are real
and lie in the open interval (−1, 1), and polynomials of degree 2n − 1 are integrated exactly.
Consider the simplest situation in which n = 2, so that only two sample points x 1 and x2 are
involved, with , the integration formula becomes;

At this stage the values of the samples x1 and x2 and those of the weights, of the integration
formula for the sample pints w1 and w2 are unknown. To determine the four numbers, we impose
the requirement that this formula is exact if f(x) is an arbitrary polynomial of degree .

Hence we let , in which c0, c1, c2, c3 are arbitrary.


Hence;

Evaluating the integral on the left, and equating the respective multipliers of the arbitrary
coefficients c0, c1, c2, and c3 to make this result an identity, leads to;

 Coefficient c0;

 Coefficient c1;

 Coefficient c2;

 Coefficient c3;

This set of equations has a solution of; .

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


So the extremely simple two-point integration formula that gives exact results when f (x) is a
polynomial of degree 3 or less is seen to be given by;

If this approach is extended to n points, an examination of the derivation of the formula shows
that for the sample points, are simply the n roots of the Legendre polynomial
of degree n with the corresponding weights wi given by; .
The general integration formula involving n sample points becomes;

Generally, these results are called Gaussian integration formulas or Gauss – Legendre
integration formulas.
Table 4.1 shows a list of Gaussian sampling points xi and their associated weights for n = 2, 3, 4,
5, 10, and 16.

If the integral involved is with then it is necessary to change the


variable, by;

This converts the integral into the form;

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Table 4.1 Gaussian sampling points and weights

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Example 4.4.3

Use the five – point Gaussian formula to determine, . Compare the result with
the analytical solution of the integral.
Solution

A change of variable maps the interval onto the interval .

After changing variables, then;

, setting and applying the five – point


Gaussian formula, gives;
ui f(ui) wi wif(ui)
-0.906180 0.250069 0.236927 0.059248
-0.538469 0.251681 0.478629 0.120462
0 0.258199 0.568889 0.146887
0.538469 0.270834 0.478629 0.129629
0.906180 0.284366 0.236927 0.067374
Sum 0.52360

Hence,

The analytical solution is;

This clearly shows a negligible difference between the result from the Gaussian method and the
analytical solution.
Exercise 4.3
1. Use the composite Simpson’s rule with step length h = 0.5 to determine;
and verify that the rule integrates cubics exactly.

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


2. Use the composite trapezoidal rule with step length h = 0.1 to determine; ,

compare your result with the exact value . Repeat the calculation with Simpson’s rule
with the same step length.
3. Use the composite trapezoidal and Simpson’s rule each of 10 subintervals to evaluate,

Compare your results with the exact solution . which is the more accurate rule
at computing the integral. Ans: Itrap = 1.849317 and Isimp = 1.851944
4. Use the 3 - , 5 - and 10 – point Gaussian formulas to compute the following integrals and
compare the results with the given exactvalue:

(i) . The exact value is,

(ii) . The exact value is,

4.5 Numerical solution of Differential equations


Most differential equations have no known analytical solution, and even when one can be found
it is often difficult to use. As a result, when solutions are required and an analytical solution
either is not known or is inconvenient to use, it becomes necessary to use methods that produce a
numerical solution directly. However, unlike the general analytical solution of an initial value
problem that can be adapted to any appropriate initial conditions, a numerical solution is the
solution of a specific initial value problem, so the calculation must be repeated if the initial
conditions are changed.

4.5.1 Euler’s method


The approximate numerical solution of the initial value problem;

subject to the initial condition generated by Euler’s method with step


size h is obtained from the algorithm ;

Where .
Example 4.5.1
Use the Euler algorithm with a step size h = 0.2 to find an approximate solution of the first order
initial value problem;

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


in the interval , and compare it with the exact solution;

Solution

Setting h = 0.2, n = 10, and in the Euler algorithm leads to the following
results; the column yexact contains the analytical solution.

The error between yn+1 and yexact can be reduced, but not limited, by choosing a smaller step size,
though for significantly greater accuracy it is necessary to make use of a different method.

4.5.2 Heun’s method: The modified Euler’s method


A source of error in Euler’s method is its failure to take account of the curvature of the solution
curve at a point (xi , yi ) when using the tangent line approximation to the curve to estimate yi+1.
An improvement can be obtained by using a two-stage process to arrive at a modified gradient
that can be used in Euler’s method in place of f (xi , yi ).
The first step when finding the modified gradient involves computing the gradient f (xi , yi ) and
then using it in Euler’s method to compute the gradient f (xi+1, yi+1) at the point (xi+1, yi+1). The
second and final step involves averaging these two gradients, to obtain the new gradient;

and then using in place of f (xi , yi ) in Euler’s method at (xi , yi ) to find an improved
estimate at the point (xi+1, yi+1).
The modified Euler algorithm
The approximate numerical solution of the initial value problem;

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


subject to the initial condition generated by the modified Euler’s
method with step size h is obtained from the algorithm ;

Where

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Example 4.5.2
Use the Heun’s algorithm with a step size h = 0.2 to find an approximate solution of the first
order initial value problem;

in the interval , and compare it with the exact solution;

and the results from Euler’s method.


Solution

Setting h = 0.2, n = 10, and in the Heun’s algorithm leads to the following
results;
yn+1 =
n xn yn f(xn,yn) a=xn+h b = yn + hf(xn,yn) f(a,b) yn+0.5h[f(xn,yn)+f(a,b)]
0 0 1 -1.000000 0.2 0.8000 -0.6013 0.8399
1 0.2 0.8399 -0.641198 0.4 0.7116 -0.3222 0.7435
2 0.4 0.7435 -0.354108 0.6 0.6727 -0.1081 0.6973
3 0.6 0.6973 -0.132667 0.8 0.6708 0.0466 0.6887
4 0.8 0.6887 0.028656 1.0 0.6944 0.1470 0.7063
5 1 0.7063 0.135201 1.2 0.7333 0.1987 0.7397
6 1.2 0.7397 0.192376 1.4 0.7781 0.2073 0.7796
7 1.4 0.7796 0.205818 1.6 0.8208 0.1788 0.8181
8 1.6 0.8181 0.181482 1.8 0.8544 0.1195 0.8482
9 1.8 0.8482 0.125662 2.0 0.8733 0.0360 0.8643
10 2 0.8643 0.044948 2.2 0.8733 -0.0648 0.8624
The comparisons of the Heun’s solution, yn(mod) with the Euler’s, yn(e) and exact, yexact solutions
are as shown below:

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


It is clear that there is an improvement in the accuracy when the modified Euler method is used.

4.5.3 The forth order Runge – Kutta method for a first order differential equation
This yet another modified method of determining the numerical solution of a first order
differential equation.
The approximate numerical solution of the initial value problem;

subject to the initial condition with step size h can obtained from the

following forth order Runge – Kutta algorithm, with and .


1. Calculate;

2. Calculate;

3. The numerical approximate yn+1 of the solution y = y(xn+1) is given by;

for n = 1,2,3…….

4.5.4 The Runge – Kutta algorithm for two first order simultaneous equations
The approximate numerical solution of the initial value problem for the simultaneous first order
initial value problem;

Subject to the initial conditions, genereted by the forth order Runge


– Kutta method with step size his obtained from the following algorithm in which ,
and .
1. Calculate the following order:

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


2. Calculate;

and

3. The numerical approximations of y = y(xn+1) and z = z(xn+1) are given by;

and
This forth order Runge – Kutta algorithm with step size h can be modified to find the solution of
the following initial value problem for the single variable second order differential equation
written in the standard form;

with

All that is necessary is to reduce the second order equation to a system of two simultaneous first
order equations, by setting;

and

Example 4.5.3
Use the forth order Runge – Kutta algorithm with step size h = 0.2 to solve the initial value
problem;

in the interval .

Example 4.5.4
Use the forth order Runge – Kutta algorithm with step size 0.1 to find a numerical solution of the
initial value problem;

with y(0) = 12 and y’(0) = 0 in the interval

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Solutions
Example 4.5.3

Setting h = 0.2 and , the results of the spread sheet computations are;
xn +
n xn Yn k1n (1/2)h yn+(1/2)k1n k2n yn+(1/2)k2n k3n xn+h yn+k3n k4n dn yn+1
0 0 1 -0.4 0.1 0.8 -0.2609 0.86955202 -0.28872 0.2 0.711283 -0.17158 -0.27847 0.721532
1 0.2 0.721532 -0.17568 0.3 0.63368955 -0.09681 0.67312641 -0.11259 0.4 0.608946 -0.05717 -0.10861 0.612924
2 0.4 0.612924 -0.05876 0.5 0.58354306 -0.03392 0.59596482 -0.03889 0.6 0.574037 -0.03485 -0.03987 0.573054
3 0.6 0.573054 -0.03445 0.7 0.55582826 -0.04969 0.54820966 -0.04664 0.8 0.526412 -0.07547 -0.05043 0.522623
4 0.8 0.522623 -0.07396 0.9 0.48564483 -0.10878 0.46823217 -0.10182 1 0.420806 -0.1401 -0.10588 0.416748
5 1 0.416748 -0.13848 1.1 0.34751014 -0.17055 0.33147108 -0.16414 1.2 0.25261 -0.18955 -0.16623 0.250514
6 1.2 0.250514 -0.18871 1.3 0.1561588 -0.20002 0.15050518 -0.19776 1.4 0.052758 -0.19542 -0.19661 0.053902
7 1.4 0.053902 -0.19588 1.5 -0.0440363 -0.17789 -0.0350442 -0.18149 1.6 -0.12759 -0.1482 -0.17714 -0.12324
8 1.6 -0.12324 -0.14994 1.7 -0.1982064 -0.10588 -0.1761776 -0.11469 1.8 -0.23793 -0.05938 -0.10841 -0.23165
9 1.8 -0.23165 -0.06189 1.9 -0.2625949 -0.0051 -0.2341976 -0.01646 2 -0.24811 0.043359 -0.01027 -0.24192
10 2 -0.24192 0.040886 2.1 -0.2214798 0.091955 -0.1959455 0.081741 2.2 -0.16018 0.126381 0.085776 -0.15615
11 2.2 -0.15615 0.124767 2.3 -0.093763 0.153193 -0.0795498 0.147508 2.4 -0.00864 0.162189 0.14806 -0.00809
12 2.4 -0.00809 0.161968 2.5 0.07289737 0.158441 0.07113375 0.159146 2.6 0.15106 0.139285 0.156071 0.147985

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Example 4.5.4

We set, , hence;

From

The initial conditions are, and , with h = 0.1, the following are the results of the computations obtained using
a spread sheet.
n xn yn zn k1n K1n k2n K2n k3n K3n k4n K4n dn Dn yn+1 zn+1
0 0.0 12.000 0.000 0.000 -9.600 -0.480 -9.648 -0.482 -9.456 -0.946 -9.403 -0.478 -9.535 11.522 -9.535
1 0.1 11.522 -9.535 -0.954 -9.408 -1.424 -9.263 -1.417 -9.073 -1.861 -8.828 -1.416 -9.151 10.106 -18.687
2 0.2 10.106 -18.687 -1.869 -8.832 -2.310 -8.492 -2.293 -8.307 -2.699 -7.870 -2.296 -8.383 7.810 -27.070
3 0.3 7.810 -27.070 -2.707 -7.872 -3.101 -7.335 -3.074 -7.159 -3.423 -6.527 -3.080 -7.231 4.730 -34.301
4 0.4 4.730 -34.301 -3.430 -6.528 -3.757 -5.793 -3.720 -5.629 -3.993 -4.801 -3.729 -5.696 1.001 -39.997
5 0.5 1.001 -39.997 -4.000 -4.800 -4.240 -3.864 -4.193 -3.717 -4.371 -2.692 -4.206 -3.776 -3.205 -43.773
6 0.6 -3.205 -43.773 -4.377 -2.688 -4.512 -1.550 -4.455 -1.422 -4.520 -0.199 -4.472 -1.472 -7.677 -45.245
7 0.7 -7.677 -45.245 -4.524 -0.193 -4.534 1.150 -4.467 1.255 -4.399 2.677 -4.488 1.216 -12.165 -44.029
8 0.8 -12.165 -44.029 -4.403 2.687 -4.269 4.236 -4.191 4.314 -3.972 5.936 -4.216 4.287 -16.380 -39.742
9 0.9 -16.380 -39.742 -3.974 5.951 -3.677 7.708 -3.589 7.756 -3.199 9.578 -3.617 7.743 -19.997 -31.999
10 1.0 -19.997 -31.999 -3.200 9.598 -2.720 11.566 -2.622 11.581 -2.042 13.603 -2.654 11.582 -22.652 -20.417

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Plots of yn+1 and zn+1 versus xn as shown in Figure below:

Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201


Thomas MakumbiDepartment of Electrical &Computer Engineering EMT 1201

You might also like