Numerical Methods Book PU PRO
Numerical Methods Book PU PRO
on
Numerical Methods
i
Prepared By: Er. Narayan Sapkota, [Link]. ii Everest Engineering College
Contents
0 Preliminaries 1
0.1 Mathematical Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
0.1.1 Derivative and Anti-derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
0.1.2 Limits and Continuity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
0.1.3 Intermediate Value Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
0.1.4 Mean Value Theorem for Derivatives (Lagrange Theorem) . . . . . . . . . . . . . . . . 2
0.1.5 Rolle’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
0.1.6 Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
0.1.7 Binomial Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
0.1.8 Taylor’s Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
0.2 Exact and Approximate Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
0.3 Errors in Numerical Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
0.3.1 Sources of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
0.3.2 Types of Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
0.3.3 Accuracy and Precision Trade-off . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
0.3.4 Significant Digits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
0.4 Methods of Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
0.5 Classification of Iterative Root finding Methods . . . . . . . . . . . . . . . . . . . . . . . . . . 10
0.5.1 Order of Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
0.5.2 Algorithm to Find the Order of Convergence . . . . . . . . . . . . . . . . . . . . . . . 11
iii
CONTENTS
5.1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.1.2 First-Order ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
5.1.3 Second-Order ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
5.2 Euler Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
5.3 Runge-Kutta Method for First-Order Differential Equation . . . . . . . . . . . . . . . . . . . 101
5.4 Runge-Kutta Method for Second-Order Differential Equation . . . . . . . . . . . . . . . . . . 106
5.5 Boundary Value Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
5.6 Shooting Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Continuity: A function f (x) is said to be continuous at a point c if the following three conditions are met:
1. f (c) is defined.
In other words, a function is continuous at a point c if its value at c is equal to the limit of the function as
x approaches c. A function is continuous on an interval if it is continuous at every point in that interval.
1
CHAPTER 0. PRELIMINARIES
Let f (x) is a continuous function on the closed interval [a, b] and let u be any number between f (a)
and f (b), we assume f (a) < f (b). Then, there exists at least one number c in the open interval (a, b)
such that f (c) = u.
It ensures the existence of roots for certain equations and guarantees the existence of solutions to various
problems in physics, engineering, and other scientific fields where continuous functions model phenomena.
If a continuous function f on [a, b] satisfies f (a) · f (b) < 0 (i.e., f (a) and f (b) have opposite signs),
then there exists at least one ξ ∈ (a, b) such that f (ξ) = 0.
If f is a continuous function on the closed interval [a, b] and differentiable on the open interval (a, b),
then there exists a point c in (a, b) such that the tangent at c is parallel to the secant line through
the endpoints (a, f (a)) and (b, f (b)), that is,
f (b) − f (a)
f ′ (c) = , a<c<b
b−a
Geometrically, the MVT says that there is at least one number c in the open interval (a, b) such that the
slope of the tangent line to the graph of y = f (x) at the point (c, f (c)) equals the slope of the secant line
through the points (a, f (a)) and (b, f (b)).
Figure 4: For any function that is continuous on [a, b] and differentiable on (a, b), there exists some c in the
interval (a, b) such that the secant joining the endpoints of the interval [a, b] is parallel to the tangent at c.
If f (x) is a real-valued function that is continuous on the closed interval [a, b], differentiable on the
open interval (a, b), and f (a) = f (b), then there exists at least one point c in the open interval (a, b)
such that f ′ (c) = 0.
Rolle’s Theorem is a special case of the MVT, where the average rate of change of a function over an interval
is zero.
0.1.6 Integrals
First Fundamental Theorem If f is continuous over [a, b] and F is any anti-derivative of f on [a, b], then
Z b
f (x) dx = F (b) − F (a) where F ′ (x) = f (x)
a
Mean Value Theorem for Integrals Assume that f ∈ C[a, b]. Then there exists a number c, with
c ∈ (a, b), such that
1
Z b
f (x) dx = f (c)
b−a a
The value f (c) is the average value of f over the interval [a, b].
Figure 5: If a real-valued function f is continuous on a closed interval [a, b], differentiable on the open interval
(a, b), and f (a) = f (b), then there exists a c in the open interval (a, b) such that f ′ (c) = 0.
f (n+1) (c)
Rn (x) = (x − a)n+1 , for some c between a and x.
(n + 1)!
∞
x3 x5 x7 x9 X x2n+1
sin(x) = x − + − + − ... = (−1)n
3! 5! 7! 9! n=0
(2n + 1)!
∞
x2 x4 x6 x8 X x2n
cos(x) = 1 − + − + − ... = (−1)n
2! 4! 6! 8! n=0
(2n)!
Exact numbers are values that are known with absolute certainty, having no rounding errors. These
are typically integers, counting numbers, or values defined by rules or constants.
Approximate numbers are those that arise from measurements or estimations, where the value is
known with some degree of uncertainty or rounding.
Modeling Errors: Mathematical modeling is a process when mathematical equations are used to represent
a physical system. This modeling introduces errors called modeling errors. For example, consider a simple
pendulum system modeled using the differential equation for simple harmonic motion. If the air resistance
or frictional forces are not accurately accounted for in the model, the predictions of the pendulum’s behavior
may deviate from experimental observations.
Blunders and Mistakes: Blunders occur at any stage of the mathematical modeling process and consist
of all other components of error. Blunders can be avoided by sound knowledge of fundamental principles
and by taking proper care in approaching and designing a solution. For instance, in an engineering design
project, incorrectly applying a fundamental equation such as Newton’s second law of motion can lead to
significant errors in predicting the behavior of a mechanical system. Mistakes, on the other hand, are due
to programming errors. For example, a typographical error in a computer program calculating numerical
integrals can result in incorrect results.
Machine Representation and Arithmetic Errors: These errors are inevitable when using floating-
point arithmetic while using computers or calculators. Examples include rounding and chopping errors. For
instance, when representing the irrational number π in a computer’s finite memory, only a finite number of
digits can be stored. Thus, calculations involving π may introduce rounding errors that accumulate over
successive computations, leading to discrepancies between the computed and exact values.
Mathematical Approximation Errors: This error is also known as truncation error or discretization
error. These errors arise when an approximate formulation is made to a problem that otherwise cannot be
solved exactly. For example, when solving a differential equation numerically using finite difference methods,
the continuous function is discretized into a finite number of points. The error introduced by this discretiza-
tion process is the truncation error, and it affects the accuracy of the numerical solution.
Propagated Error: Propagated error is more nuanced compared to other types of errors. It refers to
errors that arise in subsequent steps of a process due to an earlier mistake, compounding the local errors
present at each stage. This is somewhat similar to errors in initial conditions. Some root-finding techniques
discover additional zeros by modifying the function to eliminate the first root, a process known as reducing
or deflating the equation. In this context, the reduced equations carry forward the errors from the earlier
stages. To address this issue, it is important to verify the later results using the original equation.
In numerical methods discussed in later chapters, propagated error is particularly significant. If errors con-
tinue to increase throughout the process, they can eventually obscure the true value, making the method
invalid; such methods are considered unstable. A stable method—one that is desirable—ensures that errors
introduced at early stages diminish as the process continues.
Each type of error can occur independently of the others, although they may sometimes interact. For example,
round-off error can occur even without truncation error, as in analytical methods. Similarly, truncation errors
can lead to inaccuracies even if calculations are performed with perfect precision. Standard error analysis of
a numerical method often treats truncation error as though such perfect precision exists.
Ea = |XE − XA |
Suppose a measurement of a length is found to be 100 cm, and the true length is 98 cm. Then the absolute
error is |100 − 98| = 2 cm, and the relative error is 100−98
98 × 100% = 2.04%.
Inherent Errors:: Inherent errors are the errors that preexist in the problem statement itself before its
solution is obtained. These errors exist because of the approximate nature of the data or due to the limita-
tions of the calculations using digital computers. Inherent errors cannot be completely eliminated but can
Consider the problem of calculating the area of a circle using the formula A = πr2 . In this formula, π is an
irrational number that cannot be represented exactly in decimal form. Therefore, any calculation involving
π introduces inherent errors due to the finite precision of computer arithmetic.
Suppose we want to calculate the area of a circle with a radius of 2 meters. Using a standard value of π
truncated to four decimal places (3.1416), we get:
A = 3.1416 × 22 = 12.5664 square meters
However, the exact area of the circle, if π were known to infinite precision, would be:
Aexact = π × 22 = π × 4 = 12.5663706 . . . square meters
The inherent error in this calculation arises from the approximation of π. While it may seem small in this
example, for more complex calculations or when high precision is required, the impact of inherent errors can
be significant.
Round-off Errors: Round-off error happens when inaccuracies arise due to a finite number of digits of pre-
cision used to represent numbers. All computers represent numbers, except for integers and some fractions,
with imprecision. Digital computers use floating-point numbers of fixed word length. This type of repre-
sentation will not express the exact or true values correctly. Error introduced by the omission of significant
figures due to computer imperfection is called the round-off error.
Round-off errors are avoidable in most computations. When n digits are used to represent a real number,
one method to avoid the error is to keep the first n digits and chop off all remaining digits. Another method
is to round to the n-th digit by examining the values of the remaining digits.
Truncation Errors: Truncation errors are defined as those errors that result from using an approximation
in place of an exact mathematical procedure. Truncation error results from terminating after a finite number
of terms, known as formula truncation error or simply truncation error.
Example: Consider the function f (x) = ex and its Taylor series expansion around x = 0:
∞
X xn
ex =
n=0
n!
Suppose we want to approximate ex by truncating the series after a finite number of terms. Let’s say we
truncate the series after the n-th term. Then, the truncation error Tn (x) is given by the difference between
the exact function and its truncated approximation:
n
X xk
Tn (x) = e −
x
k!
k=0
As an example, let’s truncate the series expansion of ex after the first two terms (n = 1):
T1 (x) = ex − (1 + x)
This truncation error represents the discrepancy between the exact function ex and its approximation 1 + x
when only the first two terms of the Taylor series expansion are used.
• Thus, the numbers 3.1416, 0.66667, and 4.0687 contain five significant digits each. The number 0.00023
has, however, only two significant digits, namely 2 and 3, since the zeros serve only to fix the position
of the decimal point.
• In cases of ambiguity, the scientific notation should be used. For example, in the number 25, 600, the
number of significant figures is uncertain, whereas the numbers 2.56×104 , 2.560×104 , and 2.5600×104
have three, four, and five significant digits, respectively.
The key principles behind significant digits are:
1. Non-zero digits: All non-zero digits are considered significant. For example, in the number 1234, all
four digits (1, 2, 3, and 4) are significant.
2. Leading zeros: Leading zeros (zeros to the left of the first non-zero digit) are not significant. For
example, in the number 0.0023, only the digits 2 and 3 are significant.
3. Captive zeros: Captive zeros (zeros between non-zero digits) are significant. For example, in the
number 506, all three digits (5, 0, and 6) are significant.
4. Trailing zeros: Trailing zeros (zeros to the right of the last non-zero digit) are significant if they are
after the decimal point or if they appear in a number with a decimal point. For example, in the number
4.50, both digits 4 and 5 are significant.
5. Trailing zeros without a decimal point: Trailing zeros at the end of a whole number without a decimal
point are not considered significant. For example, in the number 200, only the digits 2 and 0 are
significant.
f (x) = 0 (1)
which may be given explicitly as a polynomial of degree n in x or f (x) may be defined implicitly as a tran-
scendental function. A transcendental (1) may have no root, a finite or an infinite number of real and/or
complex roots while a polynomial equation (1) has exactly n (real and/or complex) roots.
If the function f (x) changes sign in any one of the intervals [x∗ − ϵ, x∗ ], [x∗ , x∗ + ϵ], then x∗ defines an
approximation to the root of f (x) with accuracy ϵ. This is known as the intermediate value theorem. Hence,
if the interval [a, b] containing x∗ and α, where α is the exact root of (1), is sufficiently small, then
|x∗ − α| ≤ b − a
lim |xn − ξ| = 0.
k→∞
If xn , xn−1 , . . . , xn−m+1 are m approximates to a root, then we write an iteration method in the form
x = ϕ(x)
The function ϕ is called the iteration function. For m = 1, we get the one-point iteration method
If ϕ(x) is continuous in the interval [a, b] that contains the root and |ϕ′ (x)| ≤ c < 1 in this interval,
then for any choice of x0 ∈ [a, b], the sequence of iterates {xk } obtained from (3) converges to the
root of x = ϕ(x) or f (x) = 0.
Thus, for any iterative method of the form (2) or (3), we need the iteration function ϕ(x) and one or more
initial approximations to the root.
In practical applications, it is not always possible to find ξ exactly. We therefore attempt to obtain an
approximate root xn+1 such that
|f (xn+1 )| < ϵ
and/or
|xn+1 − xn | < ϵ
where xn and xn+1 are two consecutive iterates and ϵ is the prescribed error tolerance.
Definition An iterative method is said to be of order p or has the rate of convergence p, if p is the
largest positive real number for which
|ϵn+1 | ≤ c|ϵn |p
where ϵn = xn − ξ is the error in the n-th iterate.
Definition If a sequence x1 , x2 , x3 , · · · , xn converges to a value α and if there exist real numbers C > 0
and p > 0 such that
|xn+1 − α|
lim =C (4)
n→∞ |xn − α|p
then we say that p is the rate of convergence of the sequence.
If α is a real root of the equation f (x) = 0 and x1 , x2 , x3 , · · · , xn be the sequence of approximations, then
the error in the nth approximation is defined by |ϵn | = |xn − α|. Now, equation (4) becomes
|ϵn+1 |
lim =C (5)
n→∞ |ϵn |p
The constant C is called the asymptotic error constant. It depends on various order derivatives of f (x)
evaluated at α and is independent of n. The relation
By substituting xi = ξ + ϵi for all i in any iteration method and simplifying, we obtain the error equation
for that method. The value of p thus obtained is called the order of this method.
Linear Convergence (Order 1 (p=1)): If the error en decreases linearly with each iteration n, the
method exhibits linear convergence. Mathematically, en ≈ C en−1 , where C is a constant.
Super-linear Convergence (Order p > 1): If the error en decreases faster than linearly with each
iteration n, the method exhibits super-linear convergence. Mathematically, en ≈ C (en−1 )p , where p > 1
and C is a constant.
Suppose that f (x) is continuous and real-valued function on an interval a ≤ x ≤ b and f (a) and f (b) are of
opposite signs, that is f (a) × f (b) < 0, then there is at least one real root in the interval between a and b.
Let us define another point xm to be the midpoint between a and b. That is, xm = (a + b)/2. Now, there
exist a following three conditions:
1. If f (xm ) = 0, we have a root at xm
2. If f (xm ) × f (a) < 0, there is a root between xm and a.
3. If f (xm ) × f (b) < 0, there is a root between xm and b.
a+b
xm = (1.1)
2
To find out how many iterations will be necessary following equation could be use.
|b−a|
log ϵ
n≤ (1.2)
log 2
There are several advantages to the bisection method. The method is guaranteed to converge, and always
converges to an answer, provided a root was bracketed in the interval (a, b) to start with. In addition, the
13
CHAPTER 1. SOLUTIONS OF NON-LINEAR EQUATIONS
error bound, given in (1.1), is guaranteed to decrease by one half with each iteration.
The method may fail when the function is tangent to the axis and does not cross the x-axis at f (x) = 0. The
disadvantage of the bisection method is that it generally converges more slowly than most other methods.
For functions f (x) that have a continuous derivative, other methods are usually faster and these methods
may not always converge. When these methods do converge, they are almost always much faster than the
bisection method.
Example 1
Use the bisection method to find a root of the equation x3 − 4x − 9 = 0 accurate to three decimal
places.
|b−a| |2−3|
log ϵ log 0.0001
n≤ = = 9.965 ≈ 10
log 2 log 2
Therefore, total iteration required is 10.
We know that,
a+b
xm =
2
The calculations for the root using bisection method are shown in below table.
Homework 1
Use the bisection method to find a root of the equation 3x + sin(x) − ex = 0 accurate to four decimal
places.
Homework 2
Use the bisection method to find a root of the equation xsin(x) + cos(x) = 0 accurate to four decimal
places.
Homework 3
Use the bisection method to find a root of the equation cos(x) = xex accurate to four decimal places.
A tangent line touches the curve at exactly one point. It represents the instantaneous rate of change
or the slope of the curve at that specific point.
This method is an improvement over the method of false position as it does not require the condition
f (xa ) × f (xb ) < 0 unlike the bisection and false position method. The graph of the function y = f (x) is
approximated by a secant line but at each iteration, two most recent approximations to the root are used to
find the next approximation. Additionally, it is not necessary for the interval to contain the root.
The slope of the secant line passing through (x1 , f (x1 )) and (x3 , f (x3 )) = Slope of the secant line passing
through (x2 , f (x2 )) and (x3 , f (x3 )).
f (x1 ) f (x2 )
=
x1 − x 3 x2 − x 3
Aftermaths,
x2 − x 1
x3 = x2 − f (x2 ) (1.3)
f (x2 ) − f (x1 )
Similarly,
x1 − x 1
x3 = x1 − f (x1 ) (1.4)
f (x1 ) − f (x2 )
The (1.3) and (1.4) are known as the secant formula. The appropriate value of the root can be refined by
repeating this procedure by replacing x1 by x2 and x2 by x3 , respectively, in the (1.3).
xn+1 − xn
xn+2 = xn+1 − f (xn+1 ) (1.5)
f (xn+1 ) − f (xn )
Example 1
Use the secant method to find a root of the equation x3 − 4x − 9 = 0 accurate to four decimal places.
Homework 1
Use the Secant method to find a root of the equation 3x + sin(x) − ex = 0 accurate to four decimal
places.
Homework 2
Use the Secant method to find a root of the equation xsin(x) + cos(x) = 0 accurate to four decimal
places.
Homework 3
Let x0 be an initial approximation to the root of f (x) = 0. Then, the point P (x0 , f (x0 )), where f (x0 ) = f0 ,
lies on the curve. We draw the tangent to the curve at P (Fig. 1.3). We approximate the curve in the
neighborhood of the root by the tangent to the curve at the point P . The point of intersection of the tangent
with the x-axis is taken as the next approximation to the root. This process is repeated until the required
accuracy is obtained.
The equation of the tangent to the curve y = f (x) at the point P (x0 , f (x0 )) is given by:
y − f (x0 ) = (x − x0 )f ′ (x0 )
where f ′ (x0 ) is the slope of the tangent to the curve at P . Setting y = 0 and solving for x, we get:
f (x0 ) ′
x = x0 − , f (x) ̸= 0
f ′ (x0 )
f (x0 )
x1 = x0 − , f ′ (x0 ) ̸= 0.
f ′ (x0 )
f (x1 ) ′
x2 = x1 − , f (x1 ) ̸= 0 (1.6)
f ′ (x1 )
The Equation (1.6) is the Newton-Raphson formula. It is also called the tangent method.
f (xn )
xn+1 = xn − , f ′ (xn ) ̸= 0 (1.7)
f ′ (xn )
Example 1
Use the Newton-Raphson method to find a root of the equation xx + x − 4 = 0 accurate to three
decimal places.
Solution: Here,
f (x) = xx + x − 4
f ′ (x) = xx (ln(x) + 1) + 1
Suppose the initial guess for x0 = 3.
We know that, general form of Newton-Raphson method is,
f (xn )
xn+1 = xn =
f ′ (xn )
. Therefore,
f (3)
x1 = 3 − = 2.549101
f ′ (3)
Homework 1
Use the Newton-Raphson method to find a root of the equation xlog10 (x) = 1.2 accurate to four
decimal places.
Homework 2
Use the Newton-Raphson method to find a root of the equation 3x = cosx+1 accurate to four decimal
places.
Homework 3
Use Newton’s method to find the smallest root of the equation ex sin x = 1 to four decimal places.
The function ϕ(x) is called the iteration function. Here we also assume that ϕ(x) is continuously differentiable
in [a, b]. Let x0 be the initial approximation of r. Thus, x0 satisfies the equation
x0 = g(x0 ).
Putting x0 in the iteration function ϕ, we get the first approximation x1 of α as
x1 = ϕ(x0 ).
Then the successive approximations are calculated as
x2 = ϕ(x1 ), x3 = ϕ(x2 ), ....
and is called the iteration formula, where xn is the n-th approximation of the root α.
The sequence {xn } of iterations or the successive better approximations may or may not converge to a limit.
If {xn } converges, then it converges to α, and the number of iterations required depends upon the desired
degree of accuracy of the root.
The iteration converges:
lim xn = α
n→∞
Remark
Sometimes, it may not be possible to find a suitable iteration function ϕ(x) by manipulating the given
function f (x). In such cases, we may use the following procedure. Write f (x) = 0 as
x = x + αf (x) = ϕ(x),
Simplifying, we find the interval in which α lies. We choose a value for α from this interval and
compute the approximations. A judicious choice of a value in this interval may give faster convergence.
Example 1
Solution:
Note: As we do not need the interval where the root lies, but it makes it easier to check the convergence.
The positive root lies in the interval (0, 1).
(i)
x3k + 1
xk+1 = , k = 0, 1, 2, . . .
5
With x0 = 1, we get the sequence of approximations as
The method converges, and x4 ≈ x5 = 0.20164 is taken as the required approximation to the root.
(ii)
1/3
xk+1 = (5xk − 1) , k = 0, 1, 2, . . .
With x0 = 1, we get the sequence of approximations as
Example 2
Find the root of the equation 3x − cos x − 1 = 0, by the iteration method, correct to four significant
figures.
Solution: Let f (x) = 3x − cos x − 1. As f (0) = −2 < 0, f (1) = 1.45 > 0, there is one root of f (x) = 0
between 0 and 1.
Therefore, |ϕ′ (x)| < 1, as | sin x| < 1 and the convergence criteria is satisfied.
n xn ϕ(xn )
0 0 0.6
1 0.6 0.61
2 0.61 0.606
3 0.606 0.6073
4 0.6073 0.60706
5 0.60706 0.60711
6 0.60711 0.60710
As a initial value, we take x0 = 0. The successive approximations of the root are computed in tabular form
as follows:
Remark
Convergence of an iteration method
xk+1 = ϕ(xk ), k = 0, 1, 2, . . . ,
depends on the choice of the iteration function ϕ(x) and a suitable initial approximation x0 to the
root.
Assignment 1
Caution 1: log10 x ̸= lne (x). log10 x is commonly used to denote the base 10 logarithm, and lne (x) is used
for the natural logarithm (base e). To convert between the two, one may use:
lne (x)
log10 (x) =
lne (10)
Caution 2: Some functions may have multiple roots; the answer provided is one of them.
1. Use Bisection method to find the root of
(a) x3 − x + 1 = 0
(b) sinx = 1
x
Interpolation refers to the method of predicting the value of a function at any intermediate point along the
independent variable. Extrapolation, on the other hand, involves determining the value of a function for a
point beyond the known range of data.
If (xi , yi ), where i = 0, 1, 2, . . . , represent the (n + 1) given data points of the function y = f (x), then
the process of determining the value of y for any x = xi between x0 and xn is known as interpolation. In
interpolation, we try to construct the polynomial pn (xi ) = yi = f (xi ) ∀i = 0, 1, 2, ..., n. This polynomial
pn (xi ) is called interpolating polynomial.
Interpolation Properties
Interpolation Property: The most fundamental property is that the interpolation polynomial P (x) passes
exactly through all the given data points (xi , yi ) for i = 0, 1, . . . , n. Mathematically, this property is expressed
as P (xi ) = yi for all i.
Degree: The degree of the interpolation polynomial is determined by the number of data points used for
interpolation. If n + 1 points are used, the interpolation polynomial is of degree n or less.
Uniqueness: Under certain conditions (such as when the data points are distinct), the interpolation poly-
nomial is unique for a given set of data points. This means that using the same set of points will always
yield the same interpolation polynomial.
The problem of polynomial approximation is to find a polynomial Pn (x), of degree ≤ n, which fits the given
data exactly, that is,
Pn (xi ) = f (xi ), i = 0, 1, 2, . . . , n (2.1)
The polynomial Pn (x) is called the interpolating polynomial. The conditions given in (2.1) are called the
interpolating conditions.
x − x1 x − x0
l0 (x) = l1 (x) =
x0 − x 1 x1 − x 0
25
CHAPTER 2. INTERPOLATION AND APPROXIMATION
x − x1 x − x0
p1 (x) = l0 (x)f0 + l1 (x)f1 = f0 + f1 (2.2)
x0 − x 1 x1 − x 0
xi 9 9.5
f (xi ) 2.1972 2.2513
Solution:
x − x1 x − 9.5
l0 (x) = = = −2(x − 9.5)
x0 − x 1 9 − 9.5
x − x0 x−9
l1 (x) = = = 2(x − 9)
x1 − x 0 9.5 − 9
where,
(x − x1 )(x − x2 )
l0 (x) =
(x0 − x1 )(x0 − x2 )
(x − x0 )(x − x2 )
l1 (x) =
(x1 − x0 )(x1 − x2 )
(x − x0 )(x − x1 )
l2 (x) =
(x2 − x0 )(x2 − x1 )
Finally,
xi 9 9.5 11
f (xi ) 2.1972 2.2513 2.3972
Solution: The Lagrange basis polynomials and their evaluations at x = 9.2 are:
(x − 9.5)(x − 11.0)
l0 (x) = = x2 − 20.5x + 104.5, L0 (9.2) = 0.54
(9.0 − 9.5)(9.0 − 11.0)
(x − 9.0)(x − 11.0) 1
l1 (x) = =− (x2 − 20x + 99), L1 (9.2) = 0.48
(9.5 − 9.0)(9.5 − 11.0) 0.75
(x − 9.0)(x − 9.5) 1
l2 (x) = = (x2 − 18.5x + 85.5), L2 (9.2) = −0.02
(11.0 − 9.0)(11.0 − 9.5) 3
Proof:
Let’s consider an nth-degree polynomial of the given form,
By substituting x = x1 we get A1 :
If we substitute all values of Ai in function f (x) where i = 1, 2, 3, . . . , n then we get the Lagrange interpolation
formula as,
(x − x1 )(x − x2 ) . . . (x − xn )
P (x) = · y0 (2.5)
(x0 − x1 )(x0 − x2 ) . . . (x0 − xn )
(x − x0 )(x − x2 ) . . . (x − xn )
+ · y1
(x1 − x0 )(x1 − x2 ) . . . (x1 − xn )
+ ...
(x − x0 )(x − x1 ) . . . (x − xn−1 )
+ · yn
(xn − x0 )(xn − x1 ) . . . (xn − xn−1 )
= l0 (x) · y0 + l1 (x) · y1 + . . . + ln (x) · yn
n n
X Y x − xj
P (x) = yi · li (x) where li (x) = (2.6)
i=1
x
j=1 i
− xj
j̸=i
2.1.5 Example
Equal Interval
Find the polynomial f (x) by using Lagrange’s formula and hence find f (3) for following data points:
x 0 1 2 5
f (x) 2 3 12 147
Unequal Interval
Find value of log10 (301) by using Lagrange’s interpolation for following data points:
n n
X Y y − yj
P (y) = xi · li (y) where li (y) = (2.7)
i=1
y − yj
j=1 i
j̸=i
xi 1 ? 3 4
yi 4 7 14 19
Solution:
y0 = 4, y1 = 14, y2 = 19, y = 7 x0 = 1, x1 = 3, x2 = 4
Using (2.7) for n = 3:
(y − y1 )(y − y2 ) (y − y0 )(y − y2 ) (y − y0 )(y − y1 )
p2 (y) = x0 + x1 + x2
(y0 − y1 )(y0 − y2 ) (y1 − y0 )(y1 − y2 ) (y2 − y0 )(y2 − y1 )
(7 − 14)(7 − 19) (7 − 4)(7 − 19) (7 − 4)(7 − 14)
p2 (7) = 1+ 3+ 4
(4 − 14)(4 − 19) (14 − 4)(14 − 19) (19 − 4)(19 − 14)
= 1.6
2.1.7 Exercise
1. Given the following data points for the function f (x) = sin x + cos x:
In practical computations, the forward difference table can be formed in the following way. For the data
points (xi , yi ), i = 0, 1, 2, . . . , n and xi = x0 + ih, we have
∆yj = yj+1 − yj , j = 0, 1, . . . , n − 1
Similarly, higher-order central differences can be defined. With the values of x and y as in the preceding two
tables, a central difference can be formed:
It is clear from all the four tables that in a definite numerical case, the same numbers occur in the same
positions whether we use forward, backward or central differences. Thus, we obtain
The primary use of difference tables is in detecting errors in numerical computations, especially when the
data is expected to follow a known function or pattern.
Given a set of data points (x0 , f (x0 )), (x1 , f (x1 )), . . . , (xn , f (xn )), the difference table is constructed in the
following steps:
1. Step 1: First Differences
The first differences are calculated by subtracting each successive f (x) value from the previous one:
Example
Consider the function f (x) = x2 + 2 and calculate the difference table for the data points from x = 1
to x = 4.
x f (x) = x2 + 2
1 3
2 6
3 11
4 18
Solution:
The first differences are:
∆f (x0 ) = 6 − 3 = 3
∆f (x1 ) = 11 − 6 = 5
∆f (x2 ) = 18 − 11 = 7
∆f (x) = 3, 5, 7
The second differences are:
∆2 f (x0 ) = 5 − 3 = 2
∆2 f (x1 ) = 7 − 5 = 2
∆2 f (x) = 2, 2
The third differences are:
∆3 f (x0 ) = 2 − 2 = 0
∆3 f (x) = 0
Since the second differences are constant and the third differences are zero, the data follows a quadratic
pattern, and there are no errors.
Let’s consider the function f (x) = x2 + 2 and introduce an error by changing f (3) = 10 instead of
the correct value f (3) = 11.
x f (x)
1 3
2 6
3 10 (Error)
4 18
∆f (x2 ) = 18 − 10 = 8
∆f (x) = 3, 4, 8
The second differences are:
∆2 f (x0 ) = 4 − 3 = 1 (Error, should be 2)
∆2 f (x1 ) = 8 − 4 = 4
∆2 f (x) = 1, 4
The third differences are:
∆3 f (x0 ) = 4 − 1 = 3
∆3 f (x) = 3
The irregularities in the first and second differences indicate that there is an error in the data. Specifically,
the value f (3) = 10 is incorrect. The correct value should be f (3) = 11, which would yield consistent first
and second differences. The difference table has successfully detected the error.
Then we obtain
y(x + h) − y(x) = a0 [(x + h)n − xn ] + a1 [(x + h)n−1 − xn−1 ] + · · ·
= a0 (nh)xn−1 + a′1 xn−2 + · · · + a′n
where a′1 , a′2 , . . . , a′n are the new coefficients.
which shows that the first difference of a polynomial of the nth degree is a polynomial of degree (n − 1).
Similarly, the second difference will be a polynomial of degree (n − 2), and the coefficient of xn−2 will be
a0 n(n − 1)h2 .
Thus the nth difference is a0 n!hn , which is a constant. Hence, the (n + 1)th, and higher differences of a
polynomial of nth degree will be zero. Conversely, if the nth differences of a tabulated function are constant
and the (n + 1)th, (n + 2)th, . . ., differences all vanish, then the tabulated function represents a polynomial
of degree n. It should be noted that these results hold good only if the values of x are equally spaced. The
converse is important in numerical analysis since it enables us to approximate a function by a polynomial if
its differences of some order become nearly constant.
∆2 y 0 ∆3 y0
P (x) = y0 + ∆y0 u + u(u − 1) + u(u − 1)(u − 2) + . . . (2.8)
2! 3!
where
x − x0
u=
h
is the normalized distance.
∇2 y n ∇3 yn
P (x) = yn + ∇yn u + u(u + 1) + u(u + 1)(u + 2) + . . . (2.9)
2! 3!
where,
x − xn
u=
h
represents the normalized distance. This formula allows us to approximate the value of a function at a given
point x using backward interpolation, which is useful when the point lies near the end of the data range.
2.5.3 Example
Example 1
The table given below gives the value of tan(x) for 0.10 ≤ x ≤ 0.30. Find the value of tan(x) at (i)
x = 0.12 (ii) x = 0.26
Solution:
Since x = 0.12 lies between 0.1 and 0.15, therefore x0 = 0.1 and y0 = 0.1003.
x − x0 0.12 − 0.1
h = 0.15 − 0.1 = 0.05, u= = = 0.4
h 0.05
Now, using newton’s forward interpolation formula,
∆2 y0 ∆3 y 0 ∆4 y0
P (x) = y0 + ∆y0 u + u(u − 1) + u(u − 1)(u − 2) + u(u − 1)(u − 2)(u − 3)
2! 3! 4!
= 0.1205798
x − xn 0.26 − 0.30
h = 0.30 − 0.25 = 0.05, u= = = −0.8
h 0.05
Example 2
Sn = 13 + 23 + 33 + · · · + n3
Solution: We have
Sn+1 = 13 + 23 + 33 + · · · + n3 + (n + 1)3
Hence
Sn+1 − Sn = (n + 1)3
or
∆Sn = (n + 1)3
It follows that
(3.1) gives
Further, during calculations, there is always a chance of committing some error due to a number of positive
and negative signs in the coefficients of each term. Except for this, there is no way to guess the degree of
the resulted polynomial before the final result is obtained after lengthy calculations.
For example, suppose the data corresponds to a polynomial of degree 2, but there are 5 data points. We will
have to simplify five terms, with each coefficient being a polynomial of degree 4. Only after simplifying these
five terms can we obtain the final polynomial of degree 2. Hence, it is not advisable to use the Lagrange
formula for more than four points in the data set.
To overcome this problem, we prefer to use the Newton’s Divided Difference formula.
f [xi ] = yi
f [xj ] − f [xi ]
f [xi , xj ] =
xj − x i
f [xj , xk ] − f [xi , xj ]
f [xi , xj , xk ] = and so on.
xk − x i
2.6.4 Example
Evaluate f (9), using Newton’s divided difference formula from the following data-points.
x 5 7 11 13 17
f (x) 150 392 1452 2366 5202
Solution:
Therefore,
Therefore,
2.7 Curve Fitting: Least Squares Lines for Linear and Nonlinear
Data
2.8 Cubic Spline Interpolation
If the values of x are equally spaced and the derivative is needed near the start of the data,
Newton’s forward formula is used. If the derivative is needed near the end, Newton’s
backward formula is applied. When the required point lies near the middle of the table,
Stirling’s or Bessel’s formula is more suitable. If the x-values are not equally spaced, we
use Lagrange’s interpolation formula or Newton’s divided difference formula. Each of
these interpolation methods can be used to derive a corresponding differentiation formula.
Important Note: It’s essential to recognize that the data table only defines the function at specific points
and may not represent the complete function, which might not be differentiable everywhere. Therefore,
numerical differentiation should be applied only when the data indicates that differences of a certain order
remain approximately constant. Otherwise, errors can grow significantly, especially when computing higher-
order derivatives. This occurs because while the interpolating polynomial ϕ(x) might closely match the actual
function f (x) at the given points, the derivative ϕ′ (x) may still differ considerably from f ′ (x).
x − x0
u=
h
∆2 y 0 ∆3 y 0
y(x) = y0 + ∆y0 u + u(u − 1) + u(u − 1)(u − 2)
2! 3!
∆4 y 0
+ u(u − 1)(u − 2)(u − 3)
4! (3.1)
∆5 y 0
+ u(u − 1)(u − 2)(u − 3)(u − 4)
5!
∆ y0
6
+ u(u − 1)(u − 2)(u − 3)(u − 4)(u − 5) + . . .
6!
First Derivative
Differentiating both sides of Equation (3.1) with respect to u:
41
CHAPTER 3. NUMERICAL DIFFERENTIATION AND INTEGRATION
dy ∆2 y 0
= ∆y0 + [(u − 1) + u]
du 2!
∆3 y0
+ [(u − 1)(u − 2) + u(u − 2) + u(u − 1)]
3!
∆4 y0 d
+ [u(u − 1)(u − 2)(u − 3)] (3.2)
4! du
∆ y0 d
5
+ [u(u − 1)(u − 2)(u − 3)(u − 4)]
5! du
∆6 y0 d
+ [u(u − 1)(u − 2)(u − 3)(u − 4)(u − 5)]
6! du
Since u = h ,
x−x0
we have du
dx = h1 . Therefore, by the chain rule:
dy dy du 1 dy
= · = ·
dx du dx h du
"
dy 1 ∆2 y 0 ∆3 y0 2
= ∆y0 + [2u − 1] + 3u − 6u + 2
dx h 2! 3!
∆4 y 0
+ 4u − 18u2 + 22u − 6
3
4! (3.3)
∆5 y 0
+ 5u − 40u3 + 105u2 − 100u + 24
4
5! #
∆6 y 0
+ 6u − 75u4 + 300u3 − 540u2 + 390u − 120 + · · ·
5
6!
At x = x0 , u = 0, so:
1 ∆2 y0 ∆3 y 0 ∆4 y0 ∆5 y 0 ∆6 y0
dy
= ∆y0 − + − + − + ··· (3.4)
dx x=x0 h 2 3 4 5 6
Second Derivative
Differentiating Equation (3.2) w.r.t. u:
d2 y 6u − 18u + 11
2
= ∆2
y 0 + ∆ 3
y0 (u − 1) + ∆4
y 0
du2 12
2u − 12u + 22u − 10
3 2
+ ∆ 5 y0 (3.5)
12
30u − 300u3 + 1020u2 − 1350u + 548
4
+ ∆ 6 y0 + ···
720
Recalling that
d2 y 1 d2 y
= ,
dx2 h2 du2
d2 y 1 11 5 137 6
= 2 ∆ y0 − ∆ y0 + ∆4 y0 − ∆5 y0 +
2 3
∆ y0 + · · · (3.7)
dx2 x=x0 h 12 6 180
x − xn
u=
h
∇2 y n ∇3 yn
y(x) = yn + ∇yn u + u(u + 1) + u(u + 1)(u + 2)
2! 3!
∇4 yn
+ u(u + 1)(u + 2)(u + 3)
4! (3.8)
5
∇ yn
+ u(u + 1)(u + 2)(u + 3)(u + 4)
5!
∇6 yn
+ u(u + 1)(u + 2)(u + 3)(u + 4)(u + 5) + · · ·
6!
First Derivative
dy ∇2 y n ∇3 y n
= ∇yn + (2u + 1) + (3u2 + 6u + 2)
du 2! 3!
∇4 yn
+ (4u3 + 18u2 + 22u + 6)
4!
∇5 yn
+ (5u4 + 40u3 + 105u2 + 100u + 24)
5!
∇6 yn
+ (6u5 + 75u4 + 340u3 + 675u2 + 548u + 120) + · · ·
6!
Using du
dx = h1 , we get:
"
dy 1 2u + 1 2 3u2 + 6u + 2 3
= ∇yn + ∇ yn + ∇ yn
dx h 2! 3!
4u3 + 18u2 + 22u + 6 4
+ ∇ yn
4! (3.9)
5u4 + 40u3 + 105u2 + 100u + 24 5
+ ∇ yn
5! #
6u5 + 75u4 + 340u3 + 675u2 + 548u + 120 6
+ ∇ yn + · · ·
6!
At x = xn , we have u = 0, so:
1 1 2 1 3 1 4 1 5 1 6
dy
= ∇yn + ∇ yn + ∇ yn + ∇ yn + ∇ yn + ∇ yn + · · · (3.10)
dx x=xn h 2 3 4 5 6
Second Derivative
Differentiating Equation (3.9) with respect to u:
d2 y ∇2 y n ∇3 yn ∇4 yn
= ·2+ (6u + 6) + (12u2 + 36u + 22)
du 2 2! 3! 4!
∇5 y n
+ (20u3 + 120u2 + 210u + 100)
5!
∇6 y n
+ (30u4 + 300u3 + 1020u2 + 1350u + 548) + · · ·
6!
Using du
dx = h1 , we get:
"
d2 y 1 12u2 + 36u + 22 4
= 2 ∇2 yn + (u + 1)∇3 yn + ∇ yn
dx 2 h 24
20u3 + 120u2 + 210u + 100 5
+ ∇ yn (3.11)
60 #
30u4 + 300u3 + 1020u2 + 1350u + 548 6
+ ∇ yn + · · ·
720
At x = xn (u = 0):
d2 y 1 11 4 5 5 137 6
= ∇ 2
y n + ∇ 3
yn + ∇ yn + ∇ yn + ∇ yn + · · · (3.12)
dx2 x=xn h2 12 3 180
Example 1
Given
x 1.0
1.1 1.2 1.3 1.4 1.5 1.6
y 7.989
8.403 8.781 9.129 9.451 9.750 10.031
2
dy d y
Using the above table, compute the and at x = 1.1 and x = 1.6.
dx dx2
Solution: Given that the values of x are equidistant with step size:h = 1.1 − 1.0 = 0.1
(a) At x = 1.1 we, use Newton’s Forward Difference Formula
x y ∆y ∆2 y ∆3 y ∆4 y ∆5 y ∆6 y
1.0 7.989
0.414
1.1 8.403 −0.036
0.378 0.006
1.2 8.781 −0.030 −0.002
0.348 0.004 0.001
1.3 9.129 −0.026 −0.001 0.002
0.322 0.003 0.003
1.4 9.451 −0.023 0.002
0.299 0.005
1.5 9.750 −0.018
0.281
1.6 10.031
dy
∴ = 3.947
dx
Now, the second derivative is:
"
d2 y 1 6u − 18u + 11
2
= ∆ y0 + ∆ y0 (u − 1) + ∆ y0
2 3 4
dx2 h2 12
2u − 12u2 + 22u − 10
3
+ ∆5 y0
12
#
30u4 − 300u3 + 1020u2 − 1350u + 548
+ ∆ y0
6
720
d2 y
∴ = −3.583
dx2
(b) At x = 1.6 we use Newton’s Backward Difference Formula
We use the above difference table and the backward difference operator ∇ instead of ∆.
For x = 1.6, u = x−xn
h = 1.6−1.6
0.1 =0
dy
∴ = 2.75
dx
Now, the second derivative:
d2 y 1 11 4 5 5 137 6
= 2 ∇ yn + ∇ yn + ∇ yn + ∇ yn +
2 3
∇ yn + · · ·
dx2 x=xn h 12 3 180
d2 y
∴ = −0.715
dx2
Homework 1
Given time and velocity in the table below. Find the initial acceleration.
t (sec) 0 5 10 15 20
v (m/s) 0 3 14 69 228
Homework 2
Let
x = x0 + rh ⇒ dx = h dr
As x goes from x0 to x0 + nh, r goes from 0 to n. So,
Z x0 +nh Z n
I= f (x) dx = h f (x0 + rh) dr
x0 0
n
n2
Z
r∆y0 dr = ∆y0 ·
0 2
r(r − 1) 2
n
∆2 y 0 n 2
Z Z
∆ y0 dr = (r − r) dr
0 2 2 0
∆2 y0 n3 n2
= −
2 3 2
n
r(r − 1)(r − 2) 3 ∆3 y0 n 3
Z Z
∆ y0 dr = (r − 3r2 + 2r) dr
0 6 6 0
∆3 y 0 n 4
= −n +n
3 2
6 4
Putting all terms together:
n2 1 n3 n2 1 n4
I = h ny0 + ∆y0 + − ∆2 y 0 + − n 3 + n 2 ∆3 y 0 + · · ·
2 2 3 2 6 4
Factor out nh:
n(2n − 3) 2 n(n − 2)(2n − 1) 3
n
I = nh y0 + ∆y0 + ∆ y0 + ∆ y0 + · · ·
2 12 72
This is the general Newton–Cotes quadrature formula, from which various rules such as the trapezoidal
rule, Simpson’s 1/3 rule, Simpson’s 3/8 rule, and others are derived by choosing specific values of n and
neglecting higher-order differences.
Z x6
h
f (x) dx ≈ [(y0 + y6 ) + 2(y1 + y2 + y3 + y4 + y5 )] (3.14)
x0 2
Z x6
h
f (x) dx ≈ [(y0 + y6 ) + 4(y1 + y3 + y5 ) + 2(y2 + y4 )] (3.15)
x0 3
x6
3h
Z
f (x) dx ≈ [(y0 + y6 ) + 3(y1 + y2 + y4 + y5 ) + 2y3 ] (3.16)
x0 8
General form:
n−1 n−3
xn
3h
Z X X
f (x) dx ≈ y0 + yn + 3 yi + 2 yi
x0 8 i=1 i=3
i mod 3̸=0 i mod 3=0
Example 1
R6 1
Evaluate 0 x+1 dx using
1. Trapezoidal rule
1
2. Simpson’s rule
3
3
3. Simpson’s rule
8
4. Compare the results with its actual value.
Function values:
1
y0 = f (0) = =1
1
1
y1 = f (1) =
2
1
y2 = f (2) =
3
1
y3 = f (3) =
4
1
y4 = f (4) =
5
1
y5 = f (5) =
6
1
y6 = f (6) =
7
1 1 1 1 1 1 1
≈ 1+2 + + + + + ≈ 2.0214
2 2 3 4 5 6 7
1
(2) Simpson’s Rule
3
Z 6
h
f (x) dx ≈ [y0 + 4(y1 + y3 + y5 ) + 2(y2 + y4 ) + y6 ]
0 3
1 1 1 1 1 1 1
= 1+4 + + +2 + + ≈ 1.9587
3 2 4 6 3 5 7
3
(3) Simpson’s Rule
8
6
3h
Z
f (x) dx ≈ [y0 + 3(y1 + y2 + y4 + y5 ) + 2y3 + y6 ]
0 8
3 1 1 1 1 1 1
= 1+3 + + + +2 + ≈ 1.9661
8 2 3 5 6 4 7
by the Trapezoidal rule. If I1 , I2 are the values of I with sub-intervals of width h1 , h2 and E1 , E2 their
corresponding errors, respectively, then
¯ ) are very
Since f ′′ (X̄) is also the largest value of f ′′ (x), we can reasonably assume that f ′′ (X̄) and f ′′ (X̄
nearly equal.
E1 h2 E1 h2
∴ = 12 or = 2 1 2 (1)
E2 h2 E2 − E1 h2 − h1
Now since I = I1 + E1 = I2 + E2 ,
⇒ E2 − E1 = I1 − I2 (2)
Hence,
h21 I1 h22 − I2 h21
I = I1 + E1 = I1 + (I1 − I2 ) i.e., I= (3)
h22 − h21 h22 − h21
which is a better approximation of I.
To evaluate I systematically, we take h1 = h and h2 = h
2 so that (3) gives
I1 (h/2)2 − I2 h2 4I2 − I1
I= =
(h/2) − h
2 2 3
1
i.e., I(h, h/2) = [4I(h/2) − I(h)] (4)
3
Now we use the trapezoidal rule several times, successively halving h and apply (4) to each pair of values as
per the following scheme:
I(h)
I(h, h/2)
I(h/2) I(h, h/2, h/4)
I(h/2, h/4) I(h, h/2, h/4, h/8)
I(h/4) I(h/2, h/4, h/8)
I(h/4, h/8)
I(h/8)
The computation is continued until successive values are close to each other. This method is called Richard-
son’s deferred approach to the limit and its systematic refinement is called Romberg’s method.
Example
R6
Evaluate 1
0 x+1
dx using Romberg Integration.
Solution:
When n=8:
b−a 6−0
a = 0, b = 6, n = 8, h= = = 0.75
n 8
i 0 1 2 3 4 5 6 7 8
xi 0 0.75 1.5 2.25 3.0 3.75 4.5 5.25 6.0
yi = xi1+1 1 0.571429 0.4 0.307692 0.25 0.210526 0.181818 0.16 0.142857
Z 6
h
I(h/8) = f (x) dx ≈ [y0 + 2(y1 + y2 + y3 + y4 + y5 + y6 + y7 ) + y8 ] ≈ 1.9897
0 2
When n=4:
b−a 6−0
a = 0, b = 6, n = 4, h= = = 1.5
n 4
i 0 1 2 3 4
xi 0 1.5 3.0 4.5 6.0
yi = xi1+1 1 0.4 0.25 0.181818 0.142857
Z 6
h
I(h/4) = f (x) dx ≈ [y0 + 2(y1 + y2 + y3 ) + y4 ] ≈ 2.1049
0 2
When n=2:
b−a 6−0
a = 0, b = 6, n = 2, h= = =3
n 2
i 0 1 2
xi 0 3.0 6.0
yi = xi1+1 1 0.25 0.142857
Z 6
h
I(h/2) = f (x) dx ≈ [y0 + 2(y1 ) + y2 ] ≈ 2.4643
0 2
When n=1:
b−a 6−0
a = 0, b = 6, n = 1, h= = =6
n 1
i 0 1
xi 0 6.0
yi = xi1+1 1 0.142857
Z 6
h
I(h/1) = f (x) dx ≈ [y0 + y1 ] =≈ 3.4286
0 2
As we know,
1
I(h, h/2) = [4I(h/2) − I(h)]
3
1
I(h/2, h/4) = [4I(h/4) − I(h/2)]
3
1
I(h/4, h/8) = [4I(h/8) − I(h/4)]
3
1
I(h, h/2, h/4) = [4I(h/2, h/4) − I(h, h/2)]
3
1
I(h/2, h/4, h/8) = [4I(h/4, h/8) − I(h/2, h/4)]
3
1
I(h, h/2, h/4, h/8) = [4I(h/2, h/4, h/8) − I(h, h/2, h/4)]
3
Therefore,
I(h) = 3.4286
I(h, h/2) = 2.1429
I(h/2) = 2.4643 I(h, h/2, h/4) = 1.9325
I(h/2, h/4) = 1.9851 I(h, h/2, h/4, h/8) = 1.9425
I(h/4) = 2.1049 I(h/2, h/4, h/8) = 1.9400
I(h/4, h/8) = 1.9513
I(h/8) = 1.9897
R6
∴ 1
0 x+1
dx = 1.9425
where xi are the nodes (or abscissas) and wi are the corresponding weights. These nodes and weights are
chosen such that the approximation is exact for polynomials of degree 2n − 1 or less. The general idea of
Gaussian quadrature is to approximate the integral of a function f (x) over an interval [a, b] by a weighted
sum of the function’s values at specified points within the interval.
While only defined for the interval [−1, 1], this is actually a universal function, because we can convert the
limits of integration for any interval [a, b] to the Legendre-Gauss interval [−1, 1]:
Z b Z 1 n
X
f (x) dx = f (ξi ) dξ ≈ wi × f (ξi ) (3.17)
a −1 i=1
where, x = b−a
2 ξ + b+a
2
Example
a) Use the one-point Gauss quadrature rule to estimate the value of the integral.
b) Use the two-point Gauss quadrature rule to estimate the value of the integral.
c) Use the three-point Gauss quadrature rule to estimate the value of the integral.
d) Find the true error for part (a), (b) and (c).
e) Find the absolute relative true error for part (a), (b) and (c).
Solution: The Gaussian Quadrature nodes and weights are defined on the interval [−1, 1]. We change
variables from x ∈ [0.1, 1.3] to ξ ∈ [−1, 1] via
b−a a+b
x= ξ+ = 0.6ξ + 0.7,
2 2
where a = 0.1, b = 1.3.
Then, the integral becomes
1.3 1 1
b−a
Z Z Z
I= 5xe−2x dx = f (ξ) dξ = 0.6 f (ξ) dξ,
0.1 2 −1 −1
where
f (ξ) = 5 (0.6ξ + 0.7) e−2(0.6ξ+0.7) .
The estimate is
I1 = 0.6 × w1 × f (ξ1 ) = 1.2 × f (0).
Calculate f (0):
Therefore,
I1 ≈ 1.2 × 0.8631 = 1.0357.
1
ξ1,2 = ± √ ≈ ±0.57735, w1 = w2 = 1.
3
The estimate is
I2 = 0.6 × [f (−0.57735) + f (0.57735)] .
Calculate
Therefore,
I2 = 0.6 × 1.5077 = 0.9046.
Calculate
f (0) = 0.8631,
f (0.7746) = 5 × (0.6 × 0.7746 + 0.7) × e−2(0.6×0.7746+0.7) = 5 × 1.1648 × e−2.3296 ≈ 0.5687,
f (−0.7746) = 5 × (0.6 × −0.7746 + 0.7) × e−2(0.6×−0.7746+0.7) = 5 × 0.2332 × e−0.4664 ≈ 0.731.
0.8889 × 0.8631 + 0.5556 × 0.5687 + 0.5556 × 0.731 = 0.767 + 0.316 + 0.406 = 1.489.
Therefore,
I3 = 0.6 × 1.489 = 0.893.
n In Error = |Itrue − In |
1 1.0357 0.1435
2 0.9046 0.0124
3 0.8930 0.0008
|Itrue − In |
ϵrel = × 100%.
|Itrue |
n ϵrel (%)
1 16.07%
2 1.39%
3 0.09%
Assignment 3
1. Given the following table of values of x and y:
dy d2 y
Use finite differences to approximate the first derivative and the second derivative at:
dx dx2
(a) x = 1.05
(b) x = 1.25
(c) x = 1.15
2. From the following table of values of x and y, find the values of
dy d2 y
and
dx dx2
at x = 2.03.
x 1.96 1.98 2.00 2.02 2.04
y 0.7825 0.7739 0.7651 0.7563 0.7473
3. The table below gives the velocity v of a body at various times t. Using finite differences, find the
acceleration at t = 1.1.
1 2
A=
3 4
Here, A is a matrix of order 2 × 2.
A= 2 4 6
1
B = 3
5
Submatrix
A matrix obtained by deleting one or more rows or columns from a given matrix is called a submatrix.
1 2
A= ⇒ 1
3 4
Square Matrix
A matrix having the same number of rows and columns is called a square matrix.
2 1
A=
0 3
A = 0 4 5
0 0 6
59
CHAPTER 4. SOLUTION OF LINEAR ALGEBRAIC EQUATIONS
A = 2 3 0
4 5 6
Diagonal Matrix
A square matrix in which all non-diagonal elements are zero is called a diagonal matrix.
2 0 0
A = 0 5 0
0 0 7
Identity Matrix
An identity matrix is a diagonal matrix in which all diagonal elements are equal to one.
1 0
I=
0 1
A skew-symmetric matrix:
0
h g
−h 0 f
−g −f 0
1 2 5 6
A= , B=
3 4 7 8
6 8
A+B =
10 12
Subtraction of Matrices
Subtraction of matrices is also defined only for matrices of the same order.
−4 −4
A−B =
−4 −4
Multiplication of Matrices
Let A be a matrix of order m × n and B be a matrix of order n × p. Then the product AB is a matrix of
order m × p.
1 2 2 0
A= , B=
3 4 1 2
Transpose of a Matrix
The matrix obtained from a given matrix A by interchanging its rows and columns is called the transpose
of A and is denoted by AT .
Let
1 2 3
A= .
4 5 6
AT = 2 5 .
3 6
Inverse of a Matrix
If A is a non-singular square matrix of order n, then a square matrix B of the same order such that
AB = BA = I,
The determinant of A is
|A| = (1)(4) − (2)(3) = −2 ̸= 0,
so A is non-singular.
The inverse of A is
1 4 1
−2 −2
A−1 = = 3 .
|A| −3 1 2 − 12
Rank of a Matrix
If we select any r rows and r columns from any matrix A, deleting all other rows and columns, then the
determinant formed by these r × r elements is called a minor of A of order r. Clearly, there will be a number
of different minors of the same order, obtained by deleting different rows and columns from the same matrix.
Definition: A matrix is said to be of rank r if
1. it has at least one non-zero minor of order r, and
2. every minor of order higher than r is zero.
Sylvester’s Criterion: A real symmetric matrix is positive definite if and only if all its leading principal
minors are positive.
For a 3 × 3 matrix
a11 a12 a13
A = a12 a22 a23 ,
a13 a23 a33
the conditions are:
1. det([a11 ]) > 0
a11 a12
2. det >0
a12 a22
3. det(A) > 0
Example
Consider the matrix
2 0
−1
A = −1 2 −1 .
0 −1 2
Step 1: Symmetry
AT = A,
so the matrix is symmetric.
Step 2: First Leading Principal Minor
det([2]) = 2 > 0.
2
−1
det = (2)(2) − (−1)(−1) = 3 > 0.
−1 2
Since all leading principal minors are positive, the matrix A is positive definite.
Here, the first equation is called the pivotal equation and a1 is called the first pivot.
Step II: Elimination of y from the third equation
b′3
Assuming b′2 ̸= 0, we eliminate y from the third equation by subtracting times the second equation from
b′2
the third equation. We then obtain:
a1 x + b1 y + c1 z = d1 ,
b′2 y + c′2 z = d′2 ,
c′′3 z = d′′3 .
Here, the second equation is the pivotal equation and b′2 is the new pivot.
Step III: Evaluation of the unknowns
The values of x, y, and z are obtained from the reduced system by back substitution.
Example 1
x + 4y − z = −5 (i)
x + y − 6z = −12 (ii)
3x − y − z = 4 (iii)
Solution:
Step I: Elimination of x
Subtract equation (i) from equation (ii), and subtract 3 times equation (i) from equation (iii).
13
(v) − (iv) :
3
71 148
z= (vi)
3 3
Example 1
x + 2y + 3z − u = 10,
2x + 3y − 3z − u = 1,
2x − y + 2z + 3u = 7,
3x + 2y − 4z + 3u = 2.
Solution:
The system can be written in matrix form as
1 2 3 10
−1 x
2 3 −3 −1 y = 1 .
2 −1 2 3 z 7
3 2 −4 3 u 2
We obtain
1 2 3 −1 | 10
0 −1 −9 1 | −19.
0 5 | −13
−5 −4
0 −4 −13 6 | −28
R3 → R3 − 5R2 , R4 → R4 − 4R2 .
This gives
1 2 3 −1 | 10
0 −1 −9 1 | −19.
0 0 41 0 | 82
0 0 23 2 | 48
−y − 9z + u = −19 ⇒ −y − 18 + 1 = −19 ⇒ y = 2.
x + 2y + 3z − u = 10 ⇒ x + 4 + 6 − 1 = 10 ⇒ x = 1.
This means: "Choose the element with the largest absolute value in column k, from row k downward, as the
pivot."
Example
Solution:
Step 1: Write the augmented matrix
Then back-substitute to find y and x. This is partial pivoting because we only swapped rows.
Example
x+y+z =9
2x − 3y + 4z = 13
3x + 4y + 5z = 40
Solution:
Step 1: Form the augmented matrix
1 1 1 9
2 −3 4 13
3 4 5 40
3 4 5 40
2 −3 4 13
1 1 1 9
2 1
R2 → R2 − R1 , R3 → R3 − R1
3 3
3 4 5 40
0 − 17 2
− 86
3 3 3
0 − 13 − 32 7
3
−1/3 1
R3 → R3 − R2 = R3 − R2
−17/3 17
3 4 5 40
0 − 17 2
− 86
3 3 3
0 0 − 36
17
145
17
Step 6: Back-substitution
145/17 145
z= =−
−36/17 36
40 − 4y − 5z
x= =3
3
145
x = 3, y = 5, z = −
36
This means: "Choose the element with the largest absolute value in the remaining submatrix as the pivot."
Why: It gives better numerical stability than partial pivoting, especially for ill-conditioned matrices.
Example
A = 4 5 6 , b = 2
7 8 9 3
Solution:
Step 1: Find the largest absolute value in the matrix
The largest element is 9 (row 3, column 3).
Step 2: Swap row 1 ↔ row 3 and column 1 ↔ column 3
New augmented matrix:
9 8 7 3
6 5 4 2
3 2 0 1
1 1 1 9
2 −3 4 13
3 4 5 40
5 4 3 40
4 −3 2 13
1 1 1 9
4 1
R2 → R2 − R1 , R3 → R3 − R1
5 5
5 4 3 40
0 − 31 − 25 −19
5
0 1
5
2
5 1
145
x = 3, y = 5, z = −
36
Here, the first equation is called the pivotal equation and a1 is called the first pivot.
Step II: Elimination of y from the first and third equations
b1
Assuming b′2 ̸= 0, we eliminate y from the first and third equations by subtracting times the second
b′2
b′3
equation from the first equation and times the second equation from the third equation. We then obtain:
b′2
Here, the second equation is the pivotal equation and b′2 is the new pivot.
Step III: Elimination of z from the first and second equations
c′1
Assuming c′′3 ̸= 0, we eliminate z from the first and second equations by subtracting times the third
c′′3
c′2
equation from the first equation and times the third equation from the second equation. This yields:
c′′3
a′′1 x = d′′1 ,
b′′2 y = d′′2 ,
c′′3 z = d′′3 .
Here, the third equation is the pivotal equation and c′′3 is the final pivot.
Step IV: Evaluation of the unknowns
a′′1 0 0 d′′1
0 b′′2 0 d′′2 .
0 0 c′′3 d′′3
1 0 0
x
0 1 0 y .
0 0 1 z
The values of x, y, and z are obtained directly from the diagonal system by simple division. The augmented
matrix corresponding to the given system is
1 1 1 9
2 −3 4 13 .
3 4 5 40
R2 → R2 − 2R1 , R3 → R3 − 3R1
1 1 1 9
0 −5 2 −5 .
0 1 2 13
1
R2 → − R2
5
1 1 1 9
0 1 −2 1 .
5
0 1 2 13
R1 → R1 − R2 , R3 → R3 − R2
1 0 7
8
5
0 1 − 25 1 .
0 0 12
5 12
5
R3 → R3
12
1 0 7
8
5
0 1 −2 1 .
5
0 0 1 5
7 2
R1 → R1 − R3 , R2 → R2 + R3
5 5
1 0 0 1
0 1 0 3 .
0 0 1 5
x = 1, y = 3, z = 5.
by decomposing the coefficient matrix A into a product of simpler matrices. This approach reduces compu-
tational effort and improves numerical stability compared to direct methods.
4.3.1 LU Decomposition
In LU decomposition, the matrix A is factorized as
A = LU
1 0 0
u11 u12 u13
L = l21 1 0 , U = 0 u22 u23
l31 l32 1 0 0 u33
i−1
X
uij = aij − lik ukj , i≤j
k=1
j−1
!
1 X
lij = aij − lik ukj , i>j
ujj
k=1
Algorithm:
1. Set diagonal elements of L equal to 1
2. Compute elements of U
3. Compute sub-diagonal elements of L
4. Solve LY = B
5. Solve U X = Y
Example
3x + 2y + 7z = 4
2x + 3y + z = 5
3x + 4y + z = 7
Equating A = LU :
3 2 7 1 0 0
u11 u12 u13 u11 u12 u13
2 3 1 = l21 1 0 0 u22 u23 = l21 u11 l21 u12 + u22 l21 u13 + u23
3 4 1 l31 l32 1 0 0 u33 l31 u11 l31 u12 + l32 u22 l31 u13 + l32 u23 + u33
1 0 0 3 2 7
L = 23 1 0 , U = 0 5
3 − 11
3
1 6
5 1 0 0 3
5
Step 4: Solve LY = B
Let
y1
Y = y2
y3
Then,
1 0 0 y1 4
LY = B ⇒ 32 1 0 y2 = 5
1 6
5 1 y3 7
y1 = 4
2 7
y1 + y 2 = 5 ⇒ y 2 =
3 3
6 1
y1 + y2 + y3 = 7 ⇒ y3 =
5 5
Thus,
4
Y = 73
1
5
Step 5: Solve U X = Y
3 2 7 4
x
U X = Y ⇒ 0 5
3 − 11
3
y = 7
3
0 0 3
5 z 1
5
3 1 1
z= ⇒z=
5 5 3
5 11 7 6
y− z= ⇒y=
3 3 3 5
4
3x + 2y + 7z = 4 ⇒ x =
15
4 6 1
x= , y= , z=
15 5 3
0 0 1
l11 u12 u13
L = l21 l22 0 , U = 0 1 u23
l31 l32 l33 0 0 1
j−1
X
lij = aij − lik ukj , i≥j
k=1
i−1
!
1 X
uij = aij − lik ukj , i<j
lii
k=1
Algorithm:
2. Compute columns of L
3. Compute rows of U
4. Solve LY = B
5. Solve U X = Y
Example
Solution:
The given system of equations is
3x + 2y + 7z = 4
2x + 3y + z = 5
3x + 4y + z = 7
Then
0 0 1
l11 u12 u13 l11 l11 u12 l11 u13
A = LU = l21 l22 0 0 1 u23 = l21 l21 u12 + l22 l21 u13 + l22 u23
l31 l32 l33 0 0 1 l31 l31 u12 + l32 l31 u13 + l32 u23 + l33
3 0 0 1 2 7
3 3
L = 2 5
3 0 , U = 0 1 − 11
5
3 2 3
5 0 0 1
Let
y1
Y = y2
y3
Then,
3 0 0 4
y1
LY = B ⇒ 2 5
3 0 y2 = 5
3 2 3
5 y3 7
4
3y1 = 4 ⇒ y1 =
3
5 7
2y1 + y2 = 5 ⇒ y2 =
3 5
3 1
3y1 + 2y2 + y3 = 7 ⇒ y3 =
5 3
Thus,
4
3
Y = 75
1
3
1
2 7
4
3 3 x 3
U X = Y ⇒ 0 1 − 11
5
y = 75
0 0 1 z 1
3
1
z=
3
11 7 6
y− z= ⇒y=
5 5 5
2 7 4 4
x+ y+ z = ⇒x=
3 3 3 15
4 6 1
x= , y= , z=
15 5 3
A = LLT
0 0
l11
L = l21 l22 0
l31 l32 l33
v
u
u i−1
X
lii = taii − 2
lik
k=1
j−1
!
1 X
lij = aij − lik ljk , i>j
ljj
k=1
Algorithm:
1. Verify that A is symmetric and positive definite
2. Compute the matrix L
3. Solve LY = B
4. Solve LT X = Y
Example
Solution:
Step 1: Matrix Form
AX = B
where
4 2 2 6
x
A = 2 5 4 , X = y , B =3
2 4 6 z 10
with
0 0
l11 l11 l21 l31
L = l21 l22 0 , U =0 l22 l32
l31 l32 l33 0 0 l33
Then
2
4 2 2
l11 l11 l21 l11 l31
LU = l21 l11 2
l21 + l222
l21 l31 + l22 l32 = 2 5 4
l31 l11 l31 l21 + l32 l22 2
l31 + l32
2
+ l33
2
2 4 6
Thus,
2 0 0 2 1 1
L = 1 2 0 , U = LT = 0 2
3
√ √2
1 3
2
11
2 0 0 11
2
2 0 0 6
y1
LY = B ⇒ 1 2 √
0 y2 = 3
1 3
2 2
11 y3 10
2y1 = 6 ⇒ y1 = 3
y1 + 2y2 = 3 ⇒ y2 = 0
√
3 11 14
y1 + y2 + y3 = 10 ⇒ y3 = √
2 2 11
3
Y = 0
√14
11
2 1 1 3
x
UX = Y ⇒ 0 2 = 0
3
√2 y
0 0 11 z √14
2 11
√
11 14 28
z= √ ⇒z=
2 11 11
3 21
2y + z = 0 ⇒ y = −
2 11
13
2x + y + z = 3 ⇒ x =
11
Final Solution:
13 21 28
x= , y=− , z=
11 11 11
Example
Solution: Remark: Cholesky’s method is applicable only to matrices that are symmetric and positive
definite. The coefficient matrix of the given system is
3 2 7
A = 2 3 1
3 4 1
Since A ̸= AT , Cholesky decomposition cannot be applied directly. Hence, we form the normal equations:
AT AX = AT B
AT AX = AT B
3 2 3
AT = 2 3 4
7 1 1
22 24 26 43
22 24 26 43
x
24 29 21 y = 51
26 21 51 z 40
0 0
l11 l11 l21 l31
L = l21 l22 0 , U = LT = 0 l22 l32
l31 l32 l33 0 0 l33
2
22 24 26
l11 l11 l21 l11 l31
LU = l21 l11
2
l21 + l222
l21 l31 + l22 l32 = 24 29 21
l31 l11 l31 l21 + l32 l22 2
l31 + l32
2
+ l33
2
26 21 51
√
2
l11 = 22 ⇒ l11 = 22
24 26
l21 l11 = 24 ⇒ l21 = √ , l31 l11 = 26 ⇒ l31 = √
22 22
2
24 61
r
2
l21 + 2
l22 = 29 ⇒ √ + 2
l22 = 29 ⇒ l22 =
22 11
21 − 24·26
l21 l31 + l22 l32 = 21 ⇒ l32 = q 22
61
11
q
2
l31 + l32
2
+ l33
2
= 51 ⇒ l33 = 51 − (l31
2 + l2 )
32
Hence,
√
22 q0 0
L = √2422 61
0 , U = LT
11
√26 l32 l33
22
43
LY = 51
40
43
l11 y1 = 43 ⇒ y1 = √
22
√
7 11
l21 y1 + l22 y2 = 51 ⇒ y2 =
5
1
l31 y1 + l32 y2 + l33 y3 = 40 ⇒ y3 =
3
√43
√22
Y = 7 11
5
1
3
UX = Y
1 1
l33 z =⇒z=
3√ 3
7 11 6
l22 y + l32 z = ⇒y=
5 5
43 4
l11 x + l21 y + l31 z = √ ⇒ x =
22 15
4 6 1
x= , y= , z=
15 5 3
Conclusion: Although the original matrix is not symmetric, Cholesky’s method can be applied successfully
by first converting the system into its normal equations.
1 0 0
a11 a12 a13
[A|I] = a21 a22 a23 0 1 0
a31 a32 a33 0 0 1
4. Make the pivot in row 3 equal to 1 and eliminate above: R3 → R3 /a33 , R1 → R1 − a13 R3 , R2 →
R2 − a23 R3 .
Step 3: Result
At the end, the augmented matrix becomes
1 0 0
∗ ∗ ∗
[I|A−1 ] = 0 1 0 ∗ ∗ ∗ ,
0 0 1 ∗ ∗ ∗
Example
Find the inverse of the following matrix using Gauss Jordan Method:
2 1 1
A = 1 3 2 .
1 0 0
Solution:
Step 1: Write the augmented matrix
2 1 1 1 0 0
[A|I] = 1 3 2 0 1 0
1 0 0 0 0 1
1 1 1 1
0 0
R1 2 2 2
R1 → ⇒ 1 3 2 0 1 0
2
1 0 0 0 0 1
R2 → R2 − R1 , R3 → R3 − R1
1 1 1 1
0 0
2 2 2
0 5 3
− 21 1 0
2 2
0 − 12 − 21 − 21 0 1
1 1 1 1
0 0
2 2 2 2
R2 → R2 ⇒ 0 1 3
− 15 2
0
5 5 5
0 − 21 − 12 − 12 0 1
1 1
R1 → R1 − R2 , R3 → R3 + R2
2 2
1 0 1 11
− 15 0
5 20
0 1 3
− 15 2
0
5 5
0 0 − 10
7
− 11
20
1
5 1
1 0 1 11
− 51 0
10 5 20
R3 → − R3 ⇒ 0 1 3
− 51 2
0
7 5 5
0 0 1 11
14 − 72 − 10
7
1 3
R1 → R1 − R3 , R2 → R2 − R3
5 5
1 0 0 0 0 1
0 1 0 −2 1 3
0 0 1 11
14 − 27 − 10
7
0 0 1
A−1 = −2 1 3
3 −1 −5
System II:
x + y = 2,
x + 1.001y = 2.001.
Although the coefficients differ only slightly, the solutions of these systems differ significantly, illustrating
the sensitivity of ill-conditioned systems.
Condition Number
The degree of conditioning of a matrix A is measured by its condition number, denoted by κ(A).
Simple iterative methods are particularly effective when the coefficients of the leading diagonal are large
compared to the other coefficients. We now discuss two important iterative methods:
1. Jacobi’s Iteration Method
2. Gauss–Seidel Iteration Method
If the coefficients a1 , b2 , c3 are large compared to the other coefficients, we solve each equation for its leading
variable:
1
x= (d1 − b1 y − c1 z) ,
a1
1
y= (d2 − a2 x − c2 z) , (4.2)
b2
1
z= (d3 − a3 x − b3 y) .
c3
Let the initial approximations be
x(0) , y (0) , z (0) .
The first approximations are obtained by substituting these initial values into the right-hand sides:
1
x(1) = d1 − b1 y (0) − c1 z (0) ,
a1
1
y (1) = d2 − a2 x(0) − c2 z (0) , (4.3)
b2
1
z (1) = d3 − a3 x(0) − b3 y (0) .
c3
This process is continued until the difference between two successive approximations is negligible.
Observation: If no better initial estimates are available, one may take
x(0) = y (0) = z (0) = 0.
First Iteration
1
x(1) = (11.19) = 1.119
10
1
y (1) = (28.08) = 2.808
10
1
z (1) = (35.61) = 3.561
10
Second Iteration
1
x(2) = (11.19 − 2.808 + 3.561) = 1.19
10
1
y (2) = (28.08 − 1.119 − 3.561) = 2.34
10
1
z (2) = (35.61 + 1.119 − 2.808) = 3.39
10
Third Iteration
1
x(3) = (11.19 − 2.34 + 3.39) = 1.22
10
1
y (3) = (28.08 − 1.19 − 3.39) = 2.35
10
1
z (3) = (35.61 + 1.19 − 2.34) = 3.45
10
Fourth Iteration
1
x(4) = (11.19 − 2.35 + 3.45) = 1.23
10
1
y (4) = (28.08 − 1.22 − 3.45) = 2.34
10
1
z (4) = (35.61 + 1.22 − 2.35) = 3.45
10
Fifth Iteration
x(5) = 1.23, y (5) = 2.34, z (5) = 3.45
Example
20x + y − 2z = 17,
3x + 20y − z = −18,
2x − 3y + 20z = 25.
Solution:
Rewriting the equations:
1
x= (17 − y + 2z),
20
1
y= (−18 − 3x + z),
20
1
z= (25 − 2x + 3y).
20
x = 1, y = −1, z=1.
a1 x + b1 y + c1 z = d1 ,
a2 x + b2 y + c2 z = d2 ,
a3 x + b3 y + c3 z = d3
is rewritten as
1
x= (d1 − b1 y − c1 z) ,
a1
1
y= (d2 − a2 x − c2 z) ,
b2
1
z= (d3 − a3 x − b3 y) .
c3
Example
20x + y − 2z = 17,
3x + 20y − z = −18,
2x − 3y + 20z = 25.
Solution:
Rewriting:
1
x= (17 − y + 2z),
20
1
y= (−18 − 3x + z),
20
1
z= (25 − 2x + 3y).
20
Second iteration:
x(2) = 1.0025, y (2) = −0.9998, z (2) = 0.9998.
Third iteration:
x(3) = 1.0000, y (3) = −1.0000, z (3) = 1.0000.
x = 1, y = −1, z=1.
A non-trivial solution exists only if the determinant of the coefficient matrix vanishes:
det(A − λI) = 0
This determinant gives an n-th degree equation in λ, called the characteristic equation of A. Its roots
λi , i = 1, 2, . . . , n are called the eigenvalues of A. For each eigenvalue λi , a corresponding non-zero solution
Xi = [x1 , x2 , . . . , xn ]T is called an eigenvector.
Example
5 4
A= .
1 2
Solution:
The characteristic equation is
5−λ 4
det(A − λI) = =0
1 2−λ
(5 − λ)(2 − λ) − 4 = λ2 − 7λ + 6 = 0
⇒ λ = 6, 1.
For λ = 6:
4
−1 x
(A − 6I)X = =0 ⇒ x + 4y = 0 ⇒ x = −4y.
1 −4 y
Hence, an eigenvector is (4, 1).
For λ = 1:
4 4 x
(A − I)X = =0 ⇒ x + y = 0.
1 1 y
Hence, an eigenvector is (1, −1).
Example
8 6 3
A = 6 7 4 .
2 4 3
Solution:
The characteristic equation is
⇒ λ = 0, 3, 15.
Eigenvectors:
• For λ = 0:
(A − 0I)X = 0 ⇒ X = (1, 2, 2)
• For λ = 3:
X = (2, 1, −2)
• For λ = 15:
X = (2, −2, 1)
Multiplying by A:
AX = k1 λ1 X1 + k2 λ2 X2 + · · · + kn λn Xn
Similarly,
A2 X = k1 λ21 X1 + k2 λ22 X2 + · · · + kn λ2n Xn
Ar X = k1 λr1 X1 + k2 λr2 X2 + · · · + kn λrn Xn
If |λ1 | > |λ2 | > · · · > |λn |, then λ1 is the dominant eigenvalue, and repeated multiplication of X by A makes
it increasingly aligned with X1 , the corresponding eigenvector.
Procedure
1. Start with an initial approximation X (0) to the eigenvector.
2. Compute AX (r) and normalize it to obtain X (r+1) .
3. Approximate the eigenvalue as
X (r+1)T AX (r+1)
λ(r+1) =
X (r+1)T X (r+1)
Example
2 1 0
A = 1 2 1
0 1 2
Solution:
1
X (0) = 0
0
2 1 0 1 2
1
Next iteration:
2 1 0 1 2.5
AX (1) = 1 2 1 0.5 = 2
0 1 2 0 0.5
1
Largest eigenvalue: λmax ≈ 3.41, Corresponding eigenvector: Xmax ≈ [0.74, −1, 0.67]T
Example
15 4 3
A = 10 12 6
20 4 2
Solution:
Iteration 1:
15 4 3 1 22
22 0.786
1
X (1) = 28 ≈ 1 , λ(1) ≈ 28
28
26 0.929
Iteration 2:
15 4 3 0.786 22.57
0.809
Conclusion: Since X (8) ≈ X (7) and λ(8) ≈ λ(7) , the dominant eigenvalue and corresponding eigenvector
are:
4.8 Assignment
4.8.1 Gauss Elimination Method
Question 1: Solve the following system of equations by Gauss elimination:
x + 2y + z = 7
2x − y + 3z = 12
3x + y − z = 2
Question 2: Solve:
2x + y + z = 10
x + 3y − z = 5
3x − 2y + 2z = 7
Question 3: Solve:
x + y + 2z = 9
2x − y + z = 8
x + 3y + z = 12
Question 2: Solve:
2x + 3y + z = 10
x − y + 2z = 5
3x + y + 4z = 15
Question 3: Solve:
x + 2y + 3z = 14
2x + y − z = 3
x−y+z =2
Question 2: Solve:
3x + y + 2z = 10
x + 2y + z = 7
2x + 3y + 4z = 20
Question 3: Solve:
2x + 3y + z = 9
x + 4y + 2z = 10
3x + y + 3z = 12
Question 2: Solve:
28x + 4y − z = 32
x + 3y + 10z = 24
2x + 17y + 4z = 35
Question 3: Solve:
10x + y + z = 12
2x + 10y + z = 13
2x + 2y + 10z = 14
Question 4: Solve:
7x + 52x2 + 13x3 = 104
1
83x1 + 11x2 − 4x3 = 95
3x1 + 8x2 + 29x3 = 71
Question 5: Solve:
3x − 0.1x2 − 0.2x3 = 7.85
1
0.1x1 + 7x2 − 0.3x3 = −19.3
0.3x1 − 0.2x2 + 10x3 = 71.4
Question 2: Solve:
28x + 4y − z = 32
x + 3y + 10z = 24
2x + 17y + 4z = 35
Question 3: Solve:
10x + y + z = 12
2x + 10y + z = 13
2x + 2y + 10z = 14
Question 4: Solve:
7x + 52x2 + 13x3 = 104
1
83x1 + 11x2 − 4x3 = 95
3x1 + 8x2 + 29x3 = 71
Question 5: Solve:
3x1 − 0.1x2 − 0.2x3 = 7.85
0.1x1 + 7x2 − 0.3x3 = −19.3
0.3x1 − 0.2x2 + 10x3 = 71.4
2 3 4
A = 4 3 1
1 2 4
Question 2: Use the Gauss-Jordan method to find the inverse of the following matrix:
0 1 2
B = 1 2 3
3 1 1
Question 3: Use the Gauss-Jordan method to find the inverse of the following matrix:
8 4 3
C = 2 1 1
1 2 1
2 1 0
A = 1 2 1 .
0 1 2
3 1 0
B = 1 3 1 .
0 1 3
4 2 0
C = 2 4 2 .
0 2 4
1 2 0
D = 2 1 2 .
0 2 1
dy
= f (x, y), y(x0 ) = y0
dx
In most numerical methods, the differential equation is replaced by a difference equation, which is then
solved to yield either:
1. Series solutions: Methods such as Picard or Taylor series approximate y by a truncated series in
x. These methods use information at a single point and do not iterate to find the next value. They
are called single-step methods.
2. Step-by-step solutions: Methods such as Euler, Runge-Kutta, Milne, and Adams-Bashforth
compute the solution iteratively, moving from one point to the next in small steps. These methods are
called multi-step or step-by-step methods because each subsequent value of y depends on previous
points.
A boundary value problem (BVP) for a first-order ODE is less common but occurs when the value of
the function is specified at two different points:
y(a) = α, y(b) = β
In such cases, numerical methods like the shooting method are used, where an initial guess for y ′ (a) (if
needed) is iteratively adjusted to satisfy the boundary condition at x = b.
• Euler and Runge-Kutta methods are particularly suited for computing y over a limited range of
x-values.
97
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
• Milne and Adams methods are more appropriate for computing over a wider range, but they require
starting values obtained from single-step methods like Runge-Kutta.
d2 y
= f (x, y, y ′ )
dx2
Second-order ODEs frequently appear in mechanical vibrations, electrical circuits, and motion under
force. To solve them numerically, they are often reduced to a system of first-order ODEs:
dy dy1 dy2
y1 = y, y2 = ⇒ = y2 , = f (x, y1 , y2 )
dx dx dx
This specifies the values of the function and its first derivative at a single point x0 . Numerical methods such
as Euler and Runge-Kutta can then compute the solution over a range of x.
y(a) = α, y(b) = β
Here, the values of the function are prescribed at two different points a and b. BVPs are commonly solved
using shooting methods or finite difference methods, often starting with initial guesses and iterating
until the boundary conditions are satisfied.
dy
= f (x, y), y(x0 ) = y0 (5.1)
dx
As we have seen, the Taylor-series method requires higher-order derivatives for good accuracy of the solution,
and in many cases, it may be awkward to apply if the derivatives become complicated. Further, we know
that the error in a Taylor series will be small if the step size h is small. In fact, if we make h small enough, we
may only need a few terms of the Taylor-series expansion for good accuracy. The Euler method follows this
idea to the extreme for first-order differential equations—it uses only the first two terms of the Taylor series.
Suppose that we have chosen h small enough so that we may truncate the series after the first derivative
term. Then:
h2 ′′
y(x0 + h) = y(x0 ) + hy ′ (x0 ) + y (ξ); x0 ≤ ξ ≤ x0 + h
2!
where the last term is the usual error term for the truncated Taylor series. Adopting a subscript notation
for the successive y-values and representing the error by the order relation, we may write the algorithm for
Euler’s method in the form:
yn+1 = yn + hy ′ + O(h2 ) (5.2)
Finally,
This error is just the local error, i.e., the error in a single step. Over many steps, the global error becomes
of O(h).
Example
Solve dy
dx = −(2x + y), y(0) = −1 find y(0.4) taking h = 0.1.
yn+1 = yn + hf (xn , yn ), n = 0, 1, 2, 3, · · ·
and
x0 = 0, x1 = x0 + h = 0.2, x2 = x1 + h = 0.3, x3 = x2 + h = 0.4
At x0 = 0:
y0 = −1, f (x0 , y0 ) = −(2(0.0) + (−1)) = 1, hf (x0 , y0 ) = 0.1 × 1 = 0.1
y1 = y0 + hf (x0 , y0 ) = −1 + 0.1 = −0.9
Here, we see that there is only one-decimal-place accuracy, even though we have advanced the solution only
for four steps. To gain four-decimal-place accuracy, one has to repeat the process more than 400 times,
taking a very small value of h, say h < 0.00005.
Alternative Method:
We observe that,
yn+1 = yn + hf (xn , yn ), n = 0, 1, 2, 3
yn+1 = yn + h(−2 xn − yn ), n = 0, 1, 2, 3
n = 0, y1 = y0 + h(−2 x0 − y0 ) = −0.9
n = 1, y2 = y1 + h(−2 x1 − y1 ) = −0.83
n = 2, y3 = y2 + h(−2 x2 − y2 ) = −0.787
n = 3, y4 = y3 + h(−2 x3 − y3 ) = −0.7683
Prepared By: Er. Narayan Sapkota, [Link]. 100 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
dy
= f (x, y), y(x0 ) = y0 (5.4)
dx
Example
Solve dy
dx = −(2x + y), y(0) = −1 for y(0.4) taking h = 0.1. (b) RK1 (b) RK2 (c) RK4
dy
= −(2x + y), y(0) = −1 ∴ f (x, y) = −(2x + y)
dx
and we will compute y from x = 0 to x = 0.4, with step size h = 0.1, so we need 4 steps:
Prepared By: Er. Narayan Sapkota, [Link]. 101 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Step 1: x0 = 0, y0 = −1
y(0.4) ≈ −0.7683
k1 = f (xn , yn )
k2 = f (xn + h, yn + hk1 )
1
k = (k1 + k2 )
2
yn+1 = yn + h · k
Step 1: x0 = 0, y0 = −1
Prepared By: Er. Narayan Sapkota, [Link]. 102 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
y(0.4) ≈ −0.8124
k1 = f (xn , yn )
h h
k2 = f xn + , yn + k1
2 2
h h
k3 = f xn + , yn + k2
2 2
k4 = f (xn + h, yn + hk3 )
1
k = (k1 + 2k2 + 2k3 + k4 )
6
yn+1 = yn + h · k
Prepared By: Er. Narayan Sapkota, [Link]. 103 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Thus, we obtain:
y(0.4) ≈ −0.81096
Example
dy y 2 − x2
= 2 , y(0) = 1
dx y + x2
at x = 0.2, 0.4.
Solution:
We are given the differential equation:
dy y 2 − x2 y 2 − x2
= 2 , y(0) = 1 ∴ f (x, y) =
dx y + x2 y 2 + x2
To find y(0.2) and y(0.4), we use the 4th order Runge-Kutta method with step size h = 0.2. The given
differential equation is:
Prepared By: Er. Narayan Sapkota, [Link]. 104 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
dy y 2 − x2
= 2 , y(0) = 1
dx y + x2
The Runge-Kutta formulas are:
k1 = f (xn , yn )
h h
k2 = f xn + , yn + k1
2 2
h h
k3 = f xn + , yn + k2
2 2
k4 = f (xn + h, yn + hk3 )
1
k = (k1 + 2k2 + 2k3 + k4 )
6
yn+1 = yn + h · k
Step 1: Solving for x = 0.2 We start with x0 = 0 and y0 = 1.
y 2 − x2
f (x, y) =
y 2 + x2
At x0 = 0, y0 = 1:
12 − 02 1
k1 = f (0, 1) = 2 = =1
1 + 02 1
0.2 0.2 1.12 − 0.12
k2 = f 0 + ,1 + · 1 = f (0.1, 1.1) = ≈ 0.9836
2 2 1.12 + 0.12
0.2 0.2 1.09842 − 0.12
k3 = f 0 + ,1 + · 0.9836 = f (0.1, 1.0984) = ≈ 0.9835
2 2 1.09842 + 0.12
1.19672 − 0.22
k4 = f (0.2, 1 + 0.2 · 0.9835) = f (0.2, 1.1967) = ≈ 0.9465
1.19672 + 0.22
1
k = (1 + 2(0.9836 + 0.9835) + 0.9465) ≈ 0.9801
6
y1 = y0 + 0.2 · 0.9801 = 1.1960
Step 2: Solving for x = 0.4 Now, we use x1 = 0.2 and y1 = 1.1960 to calculate the next step:
1.19602 − 0.22
k1 = f (0.2, 1.1960) = ≈ 0.9463
1.19602 + 0.22
0.2 0.2 1.46932 − 0.32
k2 = f 0.2 + , 1.1960 + · 0.9463 = f (0.3, 1.4693) = ≈ 0.9211
2 2 1.46932 + 0.32
0.2 0.2 1.46812 − 0.32
k3 = f 0.2 + , 1.1960 + · 0.9211 = f (0.3, 1.4681) = ≈ 0.9211
2 2 1.46812 + 0.32
1.48022 − 0.42
k4 = f (0.4, 1.1960 + 0.2 · 0.9211) = f (0.4, 1.4802) = ≈ 0.8632
1.48022 + 0.42
1
k = (0.9463 + 2(0.9211 + 0.9211) + 0.8632) ≈ 0.9157
6
y2 = y1 + 0.2 · 0.9157 = 1.3791
y(0.4) ≈ 1.3791
Prepared By: Er. Narayan Sapkota, [Link]. 105 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
d2 y dy dy
2
= f (x, y, ), y(x0 ) = y0 , (x0 ) = y0′ (5.1)
dx dx dx
dz d2 y
= 2 = f (x, y, z)
dx dx
Therefore, the second-order equation is reduced to the system of two first-order equations:
dy
= z = ϕ(x, y, z)
dx (5.2)
dz
= f (x, y, z)
dx
yn+1 = yn + hϕ(xn , yn , zn ), n = 0, 1, 2, 3
′
yn+1 = zn+1 = zn + hf (xn , yn , zn ), n = 0, 1, 2, 3
Prepared By: Er. Narayan Sapkota, [Link]. 106 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Example
y ′′ = xy ′2 − y 2
Solution:
We first convert the second-order ODE into a system of first-order equations by introducing a new variable:
z = y′ , so that z ′ = f (x, y, z) = xz 2 − y 2
Using the first-order Runge-Kutta method (Euler’s method), the update formulas are:
yn+1 = yn + h · ϕ(xn , yn , zn ), n = 0, 1, 2, . . .
zn+1 = zn + h · f (xn , yn , zn ), n = 0, 1, 2, . . .
Step 1: At x0 = 0
y0 = 1, z0 = 0, h = 0.2
ϕ(x0 , y0 , z0 ) = z0 = 0
f (x0 , y0 , z0 ) = x0 z02 − y02 = 0 · 02 − 12 = −1
y1 = y0 + h · ϕ(x0 , y0 , z0 ) = 1 + 0.2 · 0 = 1.0
z1 = z0 + h · f (x0 , y0 , z0 ) = 0 + 0.2 · (−1) = −0.2
Step 2: At x1 = 0.2
y(0.2) ≈ 1.0
y ′ (0.2) ≈ −0.2
Initial values: x0 = 0, y0 = 1, z0 = 0
Prepared By: Er. Narayan Sapkota, [Link]. 107 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Step 1:
k1 = z0 = 0
l1 = f (0, 1, 0) = 0 · 02 − 12 = −1
k2 = z0 + hl1 = 0 + 0.2 · (−1) = −0.2
l2 = f (0.2, 1 + 0.2 · 0, −0.2) = 0.2 · 0.04 − 1 = 0.008 − 1 = −0.992
1
k = (0 + (−0.2)) = −0.1
2
1
l = (−1 + (−0.992)) = −0.996
2
y1 = y0 + hk = 1 − 0.02 = 0.98
z1 = z0 + hl = 0 + 0.2 · (−0.996) = −0.1992
Let: x0 = 0, y0 = 1, z0 = 0, h = 0.2
Step 1: Compute k1 , l1
k1 = z0 = 0, l1 = f (x0 , y0 , z0 ) = 0 · 02 − 12 = −1
Step 2: Compute k2 , l2
h
x0 + = 0.1
2
h
y0 + k1 = 1 + 0.1 · 0 = 1
2
h
z0 + l1 = 0 + 0.1 · (−1) = −0.1
2
k2 = ϕ(0.1, 1, −0.1) = −0.1
l2 = f (0.1, 1, −0.1) = 0.1 · 0.01 − 1 = 0.001 − 1 = −0.999
Step 3: Compute k3 , l3
h
y0 + k2 = 1 + 0.1 · (−0.1) = 0.99
2
h
z0 + l2 = 0 + 0.1 · (−0.999) = −0.0999
2
k3 = ϕ(0.1, 0.99, −0.0999) = −0.0999
l3 = f (0.1, 0.99, −0.0999) = 0.1 · (−0.0999)2 − (0.99)2
= 0.00099801 − 0.9801 = −0.97910199
Prepared By: Er. Narayan Sapkota, [Link]. 108 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Step 4: Compute k4 , l4
x0 + h = 0.2
y0 + hk3 = 1 + 0.2 · (−0.0999) = 0.98002
z0 + hl3 = 0 + 0.2 · (−0.97910199) = −0.195820398
k4 = ϕ(0.2, 0.98002, −0.195820398) = −0.195820398
l4 = f (0.2, 0.98002, −0.195820398)
= 0.2 · (−0.1958)2 − (0.98002)2
= 0.2 · 0.03837 − 0.9604392 = 0.007674 − 0.9604392 = −0.9527652
Final Answer:
y(0.2) ≈ 0.9802, y ′ (0.2) ≈ −0.1970
Prepared By: Er. Narayan Sapkota, [Link]. 109 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
d2 y dy
(i) 2
+ λ(x) + µ(x)y = γ(x)
dx dx
with the conditions y(x0 ) = a, and y(xn ) = b.
d4 y
(ii) + λ(x)y = µ(x)
dx4
y(xn ) = y ′ (xn ) = b.
There exist two numerical methods for solving such boundary value problems. The first one is known as the
finite difference method which makes use of finite difference equivalents of derivatives. The second one is
called the shooting method which makes use of the techniques for solving initial value problems.
Prepared By: Er. Narayan Sapkota, [Link]. 110 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
Assignment 5
[A] Solve the following first order differential equation with initial conditions using (a)RK1 method (b) RK2
method (c) RK4 method.
Note: You can solve any 4 from the following questions, but question number 1 is compulsory.
1. Using the Runge-Kutta method, solve for y at x = 1.2 and x = 1.4, given the differential equation:
dy y + ex
=
dx 1 + xex
with initial condition:
x0 = 1, y0 = 0
2. Using the Runge-Kutta method, solve for y at x = 1.2 and x = 1.4, given the differential equation:
dy y + ex
=
dx 1 + xex
with initial condition:
x0 = 1, y0 = 0
3. Use Runge’s method to approximate y when x = 1.1, given that y = 1.2 when x = 1 and dy
dx = 3x + y 2 .
4. Using the Runge-Kutta method, find y(0.2) given that dy
dx = 3x + y 2 , y(0) = 1, taking h = 0.1.
5. Using the Runge-Kutta method, compute y(0.2) and y(0.4) from dy
dx = 2x + y 2 , y(0) = 1, taking
h = 0.1.
6. Use the Runge-Kutta method to find y when x = 1.2 in steps of 0.1, given that dy
dx = x2 + y 2 and
y(1) = 1.5.
7. Given dy
dx = x3 + y, y(0) = 2, compute y(0.2), y(0.4), and y(0.6) by the Runge-Kutta method.
8. Find y(0.1) and y(0.2) using the Runge-Kutta formula, given that y ′ = x2 − y and y(0) = 1.
9. Using the Runge-Kutta method, solve the following equation, taking each step of h = 0.1, given
y(0) = 3. dx
dy
= 4x
y − xy. Calculate y for x = 0.1 and x = 0.2.
[B] Solve the following second order differential equation with initial conditions using (a)RK1 method (b)
RK2 method (c) RK4 method.
Note: You can solve any 4 from the following questions, but question number 1 and 2 is compulsory.
1. Use the Runge-Kutta method to solve the second-order ODE:
d2 y
= −y
dx2
with initial conditions y(0.1) = 0, y ′ (0) = 1, and step size h = 0.1, to compute y(0.2) and y(0.3).
2. Solve the differential equation for y(0.25) using the RRunge-Kutta method:
2
d2 y
dy
10 2 + + 6x = 0
dx dx
with initial conditions:
y(0) = 1, y ′ (0) = 0, h = 0.25
Answer: y(0.25) ≈ 0.9937, y ′ (0.25) ≈ −0.0188
Prepared By: Er. Narayan Sapkota, [Link]. 111 Everest Engineering College
CHAPTER 5. SOLUTION OF ORDINARY DIFFERENTIAL EQUATIONS
d2 y dy
2
=x· −y
dx dx
With initial values: y(0) = 2, y ′ (0) = −1, and step size h = 0.1, find y(0.1) and y(0.2).
5. Apply the Runge-Kutta method to solve:
d2 y
= ex − y
dx2
with y(0) = 1, y ′ (0) = 0, and step size h = 0.2. Compute y(0.2) and y(0.4).
6. Use the Runge-Kutta method to solve:
d2 y dy
= sin(x) −
dx2 dx
Given: y(0) = 0, y ′ (0) = 1, with step size h = 0.1, find y(0.1), y(0.2), and y(0.3).
Prepared By: Er. Narayan Sapkota, [Link]. 112 Everest Engineering College
Chapter 6
Solutions of PDEs
∂ku
∂u ∂u
F x1 , x2 , . . . , xn , u(x1 , x2 , . . . , xn ), , ,..., k = 0
∂x1 ∂x2 ∂xn
Here:
• F is a general function that relates u, its partial derivatives, and possibly the independent variables.
A general second-order partial differential equation (PDE) in two variables x and y can be written as:
Here:
This equation is classified based on the discriminant D = b2 − 4ac, where a = A, b = B, and c = C. The
classification is as follows:
• Elliptic: When D < 0, the equation is classified as elliptic. The solution tends to describe steady-
state or equilibrium problems, such as Laplace’s equation or Poisson’s equation. The spatial variable
solutions in this case are typically smooth and continuous.
• Parabolic: When D = 0, the equation is classified as parabolic. The solution typically describes
diffusion or heat flow, such as in the heat equation. Parabolic equations represent processes that
smooth out over time.
• Hyperbolic: When D > 0, the equation is classified as hyperbolic. The solution typically represents
wave propagation or transmission problems, such as the wave equation. Hyperbolic equations describe
systems where information or disturbances propagate with finite speed.
113
CHAPTER 6. SOLUTIONS OF PDES
Example
∂2u 2
3. ∂x2 − ∂y 2 + 2 ∂x = 0
∂ u ∂u
∂2u
4. ∂x2 + ∂x + 2 ∂y = 0
∂u ∂u
Solution:
1.
∂2u ∂2u ∂2u
− 2 + =0
∂x2 ∂x∂y ∂y 2
Compare with the general form
Here:
A = 1, B = −2, C=1
D = B 2 − 4AC = (−2)2 − 4(1)(1) = 4 − 4 = 0
The given PDE is Parabolic
2.
∂ 2 u ∂ 2 u ∂u
+ 2 + =0
∂x2 ∂y ∂x
Here:
A = 1, B = 0, C=1
D = B 2 − 4AC = 02 − 4(1)(1) = −4
The given PDE is Elliptic
3.
∂2u ∂2u ∂u
2
− 2 +2 =0
∂x ∂y ∂x
Here:
A = 1, B = 0, C = −1
D = B 2 − 4AC = 02 − 4(1)(−1) = 4
The given PDE is Hyperbolic
4.
∂ 2 u ∂u ∂u
+ +2 =0
∂x2 ∂x ∂y
A = 1, B = 0, C=0
D = B 2 − 4AC = 02 − 4(1)(0) = 0
The given PDE is Parabolic
Prepared By: Er. Narayan Sapkota, [Link]. 114 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
h2 ′′ h3
y(x + h) = y(x) + hy ′ (x) + y (x) + y ′′′ (x) + . . . (1)
2! 3!
and
h2 ′′ h3
y(x − h) = y(x) − hy ′ (x) + y (x) − y ′′′ (x) + . . . (2)
2! 3!
Equation (1) gives:
y(x + h) − y(x)
y ′ (x) = + O(h) (3)
h
which is the forward difference approximation of y ′ (x) with an error of the order h.
Similarly, equation (2) gives:
y(x) − y(x − h)
y ′ (x) = + O(h) (4)
h
which is the backward difference approximation of y ′ (x) with an error of the order h.
Subtracting equation (2) from equation (1), we obtain:
y(x + h) − y(x − h)
y ′ (x) = + O(h2 ) (5)
2h
which is the central difference approximation of y ′ (x) with an error of the order h2 . Clearly, this central
difference approximation is better than the forward or backward difference approximations and should be
preferred.
Adding equations (1) and (2), we get:
yi+1 − yi−1
yi′ =
2h
For the second derivative:
Prepared By: Er. Narayan Sapkota, [Link]. 115 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
Figure 6.1
∂2u ∂2u
∇2 u(x, y) = 0 or + 2 =0 (6.3)
∂x2 ∂y
Prepared By: Er. Narayan Sapkota, [Link]. 116 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
It is assumed that the length of the subintervals along x and y directions are equal, i.e., h = k. Then, the
above equations becomes
1
ui,j = (ui+1,j + ui−1,j + ui,j+1 + ui,j−1 ) (6.4)
4
This equation represents the discretized form of the Laplace equation using the 5-point standard formula,
which can be used to iteratively solve for u(i, j) at each grid point.
Example 1
Consider a steel plate of size 15 cm × 15 cm, where two sides are held at 100◦ C and the other two
sides are held at 0◦ C. Find the steady-state temperature at the interior points assuming a grid size
of 5 cm × 5 cm.
Solution:
Prepared By: Er. Narayan Sapkota, [Link]. 117 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
100◦ C
15
u1 u2
10
0◦ C 0◦ C
u3 u4
5
0
0 5 100◦ C 10 15
The steady–state temperature distribution satisfies Laplace’s equation. Using the finite difference approxi-
mation,
1
ui,j = (ui+1,j + ui−1,j + ui,j+1 + ui,j−1 ) .
4
With grid spacing h = 5 cm, the plate is divided into 4 × 4 nodes. There are four interior points, which we
denote as
u1 = u(5, 10),
u2 = u(10, 10),
u3 = u(5, 5),
u4 = u(10, 5).
1
u1 = (100 + u3 + 0 + u2 ),
4
1
u2 = (100 + u4 + u1 + 0),
4
1
u3 = (100 + 0 + u4 + u1 ),
4
1
u4 = (100 + 0 + u3 + u2 ).
4
Prepared By: Er. Narayan Sapkota, [Link]. 118 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
4u = 100 + 2u,
2u = 100, ⇒ u = 50◦ C.
xy 0 5 10 15
15 100 100 100 100
10 0 50 50 0
5 0 50 50 0
0 100 100 100 100
Example 2
uxx + uyy = 0
Find the approximate values at the interior meshes by dividing the square region [0, 1] × [0, 1] into a
4 × 4 grid.
Solution:
Step 1: Grid and mesh size
Dividing [0, 1] × [0, 1] into a 4 × 4 grid gives
1
h= .
4
The grid points are
xi = ih, yj = jh, i, j = 0, 1, 2, 3, 4.
There are 9 interior points:
(1, 1), (2, 1), (3, 1), (1, 2), (2, 2), (3, 2), (1, 3), (2, 3), (3, 3).
Prepared By: Er. Narayan Sapkota, [Link]. 119 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
1
u11 = (u21 + u12 )
4
1
u21 = (u11 + u31 + u22 )
4
1
u31 = (u21 + u32 + 1.25)
4
1
u12 = (u11 + u22 + u13 )
4
1
u22 = (u12 + u21 + u23 + u32 )
4
1
u32 = (u22 + u31 + u33 + 2.5)
4
1
u13 = (u12 + u23 + 1.25)
4
1
u23 = (u13 + u22 + u33 + 2.5)
4
1
u33 = (u23 + u32 + 3.75 + 3.75)
4
Prepared By: Er. Narayan Sapkota, [Link]. 120 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
Example 3
Consider a steel plate of size 20 cm × 15 cm, where upper and lower two sides are held at 80◦ C and the
other two sides are held at 20◦ C. Find the steady-state temperature at the interior points assuming
a grid size of 4 cm × 5 cm.
Solution:
Using central finite differences with unequal mesh widths h = 4 cm (along x-direction) and k = 5 cm (along
y-direction), we have
ui+1,j − 2ui,j + ui−1,j ui,j+1 − 2ui,j + ui,j−1
+ = 0.
h2 k2
Solving for ui,j ,
k 2 ui+1,j + ui−1,j + h2 ui,j+1 + ui,j−1
ui,j = .
2(k 2 + h2 )
Substituting h = 4 and k = 5,
25 ui+1,j + ui−1,j + 16 ui,j+1 + ui,j−1
ui,j = .
82
Grid arrangement:
The plate dimensions give
20 15
=5 intervals in x, =3 intervals in y.
4 5
Boundary conditions:
u(x, 0) = 80◦ C,
u(x, 15) = 80◦ C,
u(0, y) = 20◦ C,
u(20, y) = 20◦ C.
Prepared By: Er. Narayan Sapkota, [Link]. 121 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
∂ 2 u(x, y) ∂ 2 u(x, y)
+ = g(x, y)
∂x2 ∂y 2
Discretization
To apply the Finite Difference Method, we discretize the spatial domain (grid) and approximate the deriva-
tives by finite differences.
Consider a grid with Nx points in the x-direction and Ny points in the y-direction. Let hx and hy represent
the grid spacing in the x- and y-directions, respectively. Using a central difference scheme for the second
derivative, we approximate the Laplacian as:
Prepared By: Er. Narayan Sapkota, [Link]. 122 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
where ui,j is the value of u(xi , yj ) at the grid point (xi , yj ), and gi,j is the value of the source term g(xi , yj )
at that point.
It is assumed that the length of the subintervals along x and y directions are equal, i.e., hx = hy = h. Then,
the above equations becomes,
1
ui,j = (ui+1,j + ui−1,j + ui,j+1 + ui,j−1 ) − h2 gi,j
4
Boundary Conditions
To fully solve the Poisson equation, boundary conditions are required. These are often given as Dirichlet
(specified u values) or Neumann (specified ∂u/∂n) boundary conditions.
For example:
• Dirichlet boundary conditions: u(x, y) is specified on the boundary.
• Neumann boundary conditions: The gradient of u(x, y) is specified on the boundary.
Example 1
Solve the equation ∇2 u = −10(x2 + y 2 + 10) over the square with sides x = 0, y = 0, x = 3, y = 3,
with u = 0 on the boundary and mesh length h = 1.
Solution:
The Poisson equation in two dimensions is
Thus,
ui+1,j + ui−1,j + ui,j+1 + ui,j−1 − 4ui,j
= −10(x2i + yj2 + 10).
h2
Prepared By: Er. Narayan Sapkota, [Link]. 123 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
Since h = 1,
ui+1,j + ui−1,j + ui,j+1 + ui,j−1 − 4ui,j = −10(x2i + yj2 + 10).
The grid points are x, y = 0, 1, 2, 3. and the interior points are (1, 1), (2, 1), (1, 2), (2, 2).
Let u11 = u(1, 1), u21 = u(2, 1), u12 = u(1, 2), u22 = u(2, 2).
Finite difference equations:
At (1, 1):
u21 + u12 − 4u11 = −10(12 + 12 + 10) = −120,
4u11 − u21 − u12 = 120.
At (2, 1):
u11 + u22 − 4u21 = −10(22 + 12 + 10) = −150,
4u21 − u11 − u22 = 150.
At (1, 2):
u11 + u22 − 4u12 = −10(12 + 22 + 10) = −150,
4u12 − u11 − u22 = 150.
At (2, 2):
u12 + u21 − 4u22 = −10(22 + 22 + 10) = −180,
4u22 − u12 − u21 = 180.
System of equations:
4u11 − u21 − u12 = 120,
−u11 + 4u21 − u22 = 150,
−u11 + 4u12 − u22 = 150,
−u12 − u21 + 4u22 = 180.
Example 2
Solve the Poisson equation ∇2 u = 2x2 y 2 over the square domain 0 < x < 3 and 0 < y < 3, with
Dirichlet boundary conditions u(x, y) = 0 on the boundary. The grid spacing is h = k = 1, and the
Gauss-Seidel method is to be used for the solution.
Solution:
Prepared By: Er. Narayan Sapkota, [Link]. 124 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
Since h = k = 1:
ui+1,j + ui−1,j + ui,j+1 + ui,j−1 − 4ui,j = 2x2i yj2 .
1 1
u11 = u21 + u12 + u01 + u10 − 2(12 · 12 ) = (u21 + u12 + 0 + 0 − 2)
4 4
1 1
u21 = (u31 + u11 + u22 + u20 − 2(22 · 12 )) = (0 + u11 + u22 + 0 − 8)
4 4
1 1
u12 = (u22 + u02 + u11 + u13 − 2(12 · 22 )) = (u22 + 0 + u11 + 0 − 8)
4 4
1 1
u22 = (u32 + u12 + u23 + u21 − 2(22 · 22 )) = (0 + u12 + 0 + u21 − 32)
4 4
Prepared By: Er. Narayan Sapkota, [Link]. 125 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
y\x 0 1 2 3
3 0 0 0 0
2 0 −2.49 −8.48 0
1 0 −1.93 −2.49 0
0 0 0 0 0
Example 3
Solution:
Here, h = 13 . The standard five-point finite difference formula for the Poisson equation is:
1 2
Here, f (x, y) = −81xy, and xi = ih, yj = jh. Since h2 = = 19 , we have
3
1
h2 f (xi , yj ) = (−81xi yj ) = −9xi yj .
9
u3 u4
u1 u2
Prepared By: Er. Narayan Sapkota, [Link]. 126 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
Subtract the first equation from the third: (u1 − 4u3 + u4 ) − (−4u1 + u2 + u3 ) = −218 − (−9)
=⇒ 5u1 − u2 − 5u3 + u4 = −209.
u3 = 25.792 u4 = 51.083
u1 = 51.083 u2 = 76.548
∂u(x, t) ∂ 2 u(x, t) k
= α2 and α2 = (6.1)
∂t ∂x2 ρcp
where:
• u(x, t) is the temperature at position x and time t,
• k is the thermal conductivity,
• ρ is the density of the material,
• cp is the specific heat capacity at constant pressure,
• α is the thermal diffusivity constant,
∂ 2 u(x,t)
• ∂x2 is the spatial second derivative of the temperature.
The solution is not defined in a closed form (as in elliptic equations) but propagates in an open-ended region
from initial values satisfying the prescribed boundary conditions (see Figure).
The Schmidt method is an explicit finite difference method used to solve the heat equation numerically. This
involves discretizing the spatial and time domains.
Prepared By: Er. Narayan Sapkota, [Link]. 127 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
• Time Derivative:
∂u(xi , tn ) un+1 − uni
≈ i
∂t ∆t
• Second Spatial Derivative:
∂ 2 u(xi , t) un − 2uni + uni−1
≈ i+1
∂x 2 (∆x)2
α2 ∆t
Put λ = (∆x)2 , above equation becomes
un+1
i = λuni−1 + (1 − 2λ)uni + λuni+1 (6.2)
This is the Schmidt Explict formula for solving the 1D heat equation. This formula is valid only for 0 < λ ≤ 21 .
The temperature at the next time step un+1i is computed based on the values at the current time step.
1 n
un+1 = ui−1 + uni+1 (6.3)
i
2
This shows that the value of u at xi at time tn+1 is the mean of the u-values at xi−1 and xi+1 at time tn .
This relation, known as the Bendre-Schmidt recurrence relation, gives the values of u at the internal mesh
Prepared By: Er. Narayan Sapkota, [Link]. 128 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
Example 1
Solve the boundary value problem ut = uxx under the conditions u(0, t) = 0, u(1, t) = 0, and
u(x, 0) = sin(πx), where 0 ≤ x ≤ 1, using the Bendre-Schmidt method. (Take h = 0.2.
Solution:
Step 1: Identify parameters Compare
ut = uxx with ut = α2 uxx .
We have α = 1 and h = ∆x = 0.2.
The stability parameter is
α2 ∆t
λ= .
(∆x)2
Taking λ = 0.1 (typical small value for stability in explicit methods),
∆t = λ(∆x)2 = 0.02.
Step 2: Discretization using Bender-Schmidt
The Bender-Schmidt (explicit) scheme is
1 n
un+1 = ui−1 + uni+1 , i = 1, 2, . . . , 4
i
2
with boundary points
un0 = 0, un5 = 0.
Prepared By: Er. Narayan Sapkota, [Link]. 129 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
1 0 1
u11 = (u + u02 ) = (0 + 0.9511) = 0.4756,
2 0 2
1 1
u12 = (u01 + u03 ) = (0.5875 + 0.9511) = 0.7693,
2 2
1 1
u13 = (u02 + u04 ) = (0.9511 + 0.5875) = 0.7693,
2 2
1 1
u14 = (u03 + u05 ) = (0.9511 + 0) = 0.4756.
2 2
u10 = 0, u15 = 0.
Repeat the same Bender-Schmidt iteration for n = 1, 2, . . . until the desired time is reached.
1 n
un+1 = ui−1 + uni+1 , i = 1, . . . , 4.
i
2
Prepared By: Er. Narayan Sapkota, [Link]. 130 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
6.5 Exercise
1. Solve the partial differential equation uxx + uyy = 0 over a square domain of side 4 units, subject to
the following boundary conditions:
u(0, y) = 0, 0 ≤ y ≤ 4,
u(4, y) = 12 + y, 0 ≤ y ≤ 4,
u(x, 0) = 3x, 0 ≤ x ≤ 4,
u(x, 4) = x ,2
0 ≤ x ≤ 4.
2. Solve the Poisson equation: ∇2 f = 2x2 + y over the square domain 1 ≤ x ≤ 4 and 1 ≤ y ≤ 4, with the
boundary condition f = 0 on the boundary. The grid spacing is h = k = 1.
3. Consider a steel plate of size 20 cm × 15 cm, where upper and lower two sides are held at 80◦ C and the
other two sides are held at 20◦ C. Find the steady-state temperature at the interior points assuming a
grid size of 4 cm × 5 cm. The Poisson equation is ∇2 u = −10(x2 + y 2 + 10).
4. Solve the heat equation
ut = uxx , 0 ≤ x ≤ 1, t > 0,
subject to the boundary conditions
u(0, t) = 0, u(1, t) = 0,
Solve for the steady-state temperature distribution using the finite difference method with a grid size
of 2 cm × 2 cm.
8. Solve the one-dimensional heat equation
ut = αuxx , 0 ≤ x ≤ L, t > 0,
subject to
u(0, t) = u(L, t) = 0, u(x, 0) = f (x),
. Let ∆x = 0.1, ∆t = 0.01, and α = 0.5.
Prepared By: Er. Narayan Sapkota, [Link]. 131 Everest Engineering College
CHAPTER 6. SOLUTIONS OF PDES
Prepared By: Er. Narayan Sapkota, [Link]. 132 Everest Engineering College