NumericalMethodsforEngineers PDF
NumericalMethodsforEngineers PDF
net/publication/287209798
CITATIONS READS
0 32,815
1 author:
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Shree Krishna Khadka on 24 January 2016.
NUMERICAL METHODS
For BE-V Semester (Computer Engineering)
Prepared By
Er. SriKisna
Inside
o Numerical Methods: Introduction & Scope
o Errors in Numerical Calculation
o Solution of Algebraic & Transcendental Equation
o Interpolation
o Curve Fitting, B Splines & Approximation
o Numerical Differentiation & Integration
o Matrices & Linear System of Equations
o Solution of Ordinary Differential Equations
o Solution of Partial Differential Equations
o Solution of Integral Equations
o Programming Examples
HWHIC GSSE
BLEX IV
CONTENT
Introduction to Numerical Methods (1 – 6)
Course Plan & Strategy ----------------------------------- 2
Importance & Need of Numerical Methods 4
Scope & Application of Numerical Methods 6
Chapter: 1 Error in Numerical Calculations (8 – 14)
1
HWHIC GSSE
BLEX IV
1
HWHIC GSSE
BLEX IV
1
WhiteHouse Institute of Science & Technology
Khumaltar, Lalitpur-Satdobato
NUMRECIAL METHODS
Lecture Handouts
2012
1
Page
Prepared By
Er. Shree Krishna Khadka
1. Reference books:
2. Teaching Schedule:
a. Theory: 3hrs/week
b. Practical: 1.5hrs/week
3. Examination Scheme:
a. Internal Assessment
i. Theory: 20 marks
ii. Practical: 50 marks
b. Final Examination
i. Theory: 80 marks
5. Abbreviations:
a. A & CP: Attendance & Class Participation
b. GD & P: Group Discussion & Presentation
c. TP & MT: Test Papers & Mid Term
d. PBE : Pre Board Examination
e. RS & P: Report Submission & Presentation
f. PE & MCQs: Practical Exam & Multiple Choice Questions
6. Adjustments:
7. Ratings:
Prepared By
Er. Shree Krishna Khadka
8. Final Examination:
a. Board Exam:
i. Full marks: 80
ii. Question Pattern: Generally consists of two groups
b. For BIT: Sometimes, one extra paper with 20 objectives questions can be asked
each carrying 1 marks for twenty minutes as a Group A. In that case, long answer
type questions weigh 10 marks each and short type questions weigh 5 marks for
each.
For BE: Choices may vary from more than one questions in each groups.
c. Lab Exam
Prepared By
Er. Shree Krishna Khadka
Introduction
Problem Definition
Numerical/Graphical
Result
Validation by:
Societal interlaces, Scheduling,
Optimization, Communication &
Public Interaction
Implementation/
Application
4
Page
Prepared By
Er. Shree Krishna Khadka
3. Example:
Newton’s Second Law of Motion
1. Theory:
The time rate of change of momentum of a body is equal to the resulting force acting
on it.
2. Mathematical Model:
3. Analysis:
It characterizes the typical mathematical model of the physical world as:
a. Natural process or system in mathematical term.
b. Idealization and simplification of reality.
c. Yields reproducible results.
4. Solution:
Manipulation of mathematical model gives rise to the solution of the problem.
This example is just a prototype; most of the real-world problems (99.9%) are
5
Prepared By
Er. Shree Krishna Khadka
4. Summary:
5. Applications:
6
Page
Prepared By
Er. Shree Krishna Khadka
Errors in Numerical Calculation
Contents:
Prepared By
Er. Shree Krishna Khadka
NUMBERS & THEIR ACCURACY
There are two kinds of numbers:
i) Exact numbers, e.g. 1, 2, 3 …1/2, 5/2 etc.
ii) Approximate numbers, e.g. PI, K … etc
o Significant Digit:
Digits that are used to express a number are called significant digits/figures. The
following statements describe the notion of significant digits.
- All non-zero digits.
- All zeroes occurring between non- zero digits.
- Trailing zeroes following a decimal point, e.g. 3.50, 65.0, 0.230 have three
significant digits.
- Zeroes between the decimal point are preceding a non-zero digits are not
significant, e.g. 0.01234, 0.001234, 0.0001234 all have four significant digits.
- When the decimal point is not written, trailing zeroes are not considered to be
significant, e.g. 4500 contain only two significant digits.
Prepared By
Er. Shree Krishna Khadka
DIFFERENT TYPES OF ERROR:
a) Absolute Error: Numerical difference between true value of a quantity and its
approximate value.
Mathematically;
b) Relative error: Ratio of absolute error to a true value of that quantity being
concerned.
Mathematically;
Mathematically;
Example:
e) Relative Accuracy: Ratio of change in true value to the modulus of true value.
Mathematically;
9
Page
Prepared By
Er. Shree Krishna Khadka
NUMERICAL EXAMPLES:
Solution:
Three approximate values of the number 1/3 are given as 0.30, 0.33 and 0.34,
which of these is the best approximation?
Solution:
E1 = |(1/3)-0.30| = 1/30
E2 = |(1/3)-0.33| = 1/300
E3 = |(1/3)-0.34| = 1/150
Evaluate the sum S=_/3 + _/5 + _/7 to four significant digits and find its absolute
and relative error.
Solution:
Prepared By
Er. Shree Krishna Khadka
MATHEMATICAL PRELIMINARIES
Where; .
( ) ( )
11
Page
Prepared By
Er. Shree Krishna Khadka
Theorem 8 (Taylor’s Series for several variables):
( )
( )
{ }
Formula for the error committed in using a certain formula or a functional relation.
Let; u=f(x1, x2, x3, x4, x5, … xn) be the function of several variable xi (i=1,2…n) and let the
error in each xi be xi , then the error u in u is given by:
….(i)
( )
( )
{ }
i.e. ( ) ∑
∑ … (ii)
Prepared By
Er. Shree Krishna Khadka
CONVERGENCE
13
Page
Prepared By
Er. Shree Krishna Khadka
ASSIGNMENT 1
Full Marks: 20
Pass Marks: 10
2.1) if u = 3v7-6v, find the percentage error in u at v=1, if the error in v is 0.05.
2.2) if y = (0.31x+2.73)/(x+0.35), where the coefficients are rounded off; find the
absolute and relative error in y when x= .
If
find the maximum absolute error in:
a) a+b+c+d
b) a+5c-d
c) c3
If u=5xy2/z3,
&
;
Prepared By
Er. Shree Krishna Khadka
Solution of Algebric &
Transcendental Equations
Contents:
o Introduction
o Evaluation of Polynomials by Horner’s Method
o Methods of solving non linear equations
o Bracketing Methods
o Bisection Method
o Regular Falsi Method
o Open End Methods
o Newton Raphson Method
o Secant Method
o Fixed Point Iteration Method
o Horner’s Method of Finding Root
o Assignment 2
15
Page
Prepared By
Er. Shree Krishna Khadka
INTRODUCTION
All iterative methods require the evaluation of function for which solution is sought.
Since, it is a recurring task; the design of an efficient algorithm for evaluating the
function assumes a greater importance.
As: ∑ ∑
Now, let us consider the evaluation of a polynomial using Horner’s Rule as:
16
( )
Page
Prepared By
Er. Shree Krishna Khadka
Where; innermost expression is evaluated first. Hence, the resulting value
constitutes a multiplicand for the expression at the next level. In this way, the number
level will be n for nth-order polynomial and consists of total n-addition and n-
multiplication.
Algorithm:
Pn = an
Pn-1 = Pn(x) + an-1
Pn-2 = Pn-1(x) + an-2
………………………………………………
………………………………………………
Pj = Pj+1(x) + aj
………………………………………………
………………………………………………
P1 = P2(x) + a1
P0 = P1(x) + a0 = f(x)
Example:
Solution:
n = 3, a3 = 1, a2 = -4, a1 = 1, and a0 = 6
Using algorithm:
P3 = a3 = 1
P2 = P3(x) + a2 = 1(2) + (-4) = -2
P1 = P2(x) + a1 = (-2)(2) +1 = -3
P0 = P1(x) + a0 = (-3)(2) +6 = 0 = f(x=0)
Prepared By
Er. Shree Krishna Khadka
METHOD OF SOLVING NON-LINEAR EQUATIONS
1. Iterative Methods
Iterative methods begin with one or more guesses at the solution being sought. It
generates a sequence of estimate of the solution which is expected to converge at
the solution. Based on the number of guess, we have two different methods.
A) Bracketing Method: It starts with two initial guesses that brackets the root
and then, systematically reduced the width of bracket until the solution is
reached. Example: Bisection Method, False Position Method etc.
B) Open End Method: It uses single starting values or two values that do not
necessarily bracket the root. Example: Newton Raphson Method with one
initial guess, Secant Method with two starting guesses, Fixed Point Iteration
Method etc.
BISECTION METHOD
This is one of the bracketing methods and is also known as Bolzano Method, Binary
Chopping or Half Interval Method.
F(x)
xn
x
xm xp
Let f(x) be the function defined in the interval [xn, xp], where f(xn) and f(xp) are of
opposite sign i.e.[ f(xn)*f(xp)] < 0, then the root of the function lies in between xn and
18
xp.
Page
Prepared By
Er. Shree Krishna Khadka
Algorithm:
1. Read xn and xp , define stopping criteria: EPS
2. Calculate, xm = (xn+xp)/2
3. If |(xp – xn)/xn| < EPS, go to step 6 (Optional)
4. Check for f(xm)
a. If f(xm) = 0, goto step 6
b. F(xm) < 0, xn = xm
c. F(xm) > 0, xp = xm
5. Repeat steps 2, 3 and 4, until EPS is achieved.
6. Print xm
7. Stop
Example:
Find the root of the equation x3-2x-5, using bisection method.
Solution:
x -5 -4 -3 -2 -1 0 1 2 3 4 5
f(x) -120 -61 -26 -9 -6 -5 -6 -1 16 51 110
Here, the sign changes occur, when the value of x shifts from +2 to +3. So, xn = 2
and xp = 3
n xn xp xmF(xm)
1 2 3 2.5 Positive
2 2 2.5 2.25 Positive
3 2 2.25 2.125 Positive
4 2 2.125 2.0625 Negative
5 2.0625 2.125 2.09375 Negative
6 2.09375 2.125 2.109375 Positive
7 2.09375 2.109375 2.1015625 Positive
8 2.09375 2.1015625 2.09765625 Positive
Since, it has not mentioned the value of stopping criteria, so for our convenient
stopping criteria, EPS = 0.005.
Since, xp = 2.1015625, xn = 2.09375, i.e. EPS = 0.003
Hence, the root of the equation is xm = 2.09765625 and with rounded off to four
significant digits, xm = 2.0976
/Home Work/
Find the root of the equation x(ex ) = 1, correct to three decimal places using Bisection
Method. Ans: 0.567
19
Page
Prepared By
Er. Shree Krishna Khadka
Convergence of Bisection Method:
In Bisection Method, we choose a mid point xm in the interval between xp and xn.
Depending upon the sign of f(xm), xp or xn is set equal to xm such that the root lies In
the interval. In other case the interval containing the root is reduced by a function of 2.
The same process is repeated for the new interval. If the procedure is repeated ‘n’
times, then the interval containing the root is reduced to the size:
After iteration the root must lies within of our estimate, this mean the error
bound at nth iteration is:
.
Similarly,
Thus, the error decreases linearly with each step by a factor of 0.5.This method is therefore
linearly convergent.
(b, f(b))
f(x)
a
x
(c,0) b
(a, f(a))
Suppose, we are given f(x) = 0. By the method of ‘Falsi Position’, the geometrical
interpretation of is given by two point formula as follows:
i.e.
Or,
Or,
Or,
20
Page
Prepared By
Er. Shree Krishna Khadka
Algorithm:
1. Find a and b such that f(a)*f(b) < 0.
2. Compute,
Example:
Find the root of the equation (x)log(x)=1; which lies in between 2 and 3 correct to
3 decimal places using Regular Falsi Method.
Solution:
We have: f(x) = (x)log(x)-1
As given: a = 2 and b = 3, i.e. the starting values. Now tabulating the data as below:
Hence, the root of the equation is: 2.506 (correct to 3-decimal places).
In the false position iteration, one of the starting points is fixed while the other moves
towards the solution. Assume that the initial points bracketing the solution are ‘a’ and
‘b’, where a moves towards the solution and ‘b’ is fixed as illustrated in following
figure.
21
Page
Prepared By
Er. Shree Krishna Khadka
(b, f(b))
f(x)
x1 x2 x3
xr x
b
(d, f(d))
(c, f(c))
(a, f(a))
e1 = xr – x1
e2 = xr – x2
………………………………………….
………………………………………….
That is:
ei = xr – xi
In general:
ei+1 = (Ref: Go online via. Google Search)
Consider a graph f(x) as shown in the above figure. Let us assume that x1 is an
approximate root of f(x) = 0. Draw a tangent at the curve f(x) at x=x1 as shown in the
figure.
(x1, f(x1))
(x2, f(x2))
f(x)
xr
x
x3 x2 x1
22
Prepared By
Er. Shree Krishna Khadka
The point of intersection of this tangent with the x-axis gives the second
approximation to the root. Let, the point of intersection be x2. The slope of the tangent
is given by:
This is called Newton Raphson Formula for first iteration. Then the next
approximation will be:
In general;
Algorithm:
1. Assign an initial value to x, say x0 and read the stopping criteria (EPS).
2. Evaluate f(x0) and f’(x0). If f(x0) = 0; then the root will be x0.
3. Find the improved estimate of x0 a:
Example:
Find the root of the equation f(x) = x2 – 3x + 2 in the vicinity of x = 0 using
Newton Raphson Method correct to 4-decimal places.
Solution:
23
Page
Prepared By
Er. Shree Krishna Khadka
Here, initial estimate of the root (x0) = 0;
We have, f(x) = x2 – 3x + 2, So, f’(x) = 2x – 3
Now, for the better approximation, we have the tabular data as follow:
n x0 f(x0) f'(x0) x1
0 0 2 -3 0.6667
1 0.6667 0.4444 -1.6667 0.9333
2 0.9333 0.0711 -1.1333 0.9961
3 0.9961 0.0032 -1.0078 0.9961
h = xn+1 - xn …… (i)
…… (ii)
If xn+1 is the root of f(x), then: f(xn+1) = 0. Putting this value in equation (ii) it gives:
i.e.
i.e.
24
i.e.
Page
Prepared By
Er. Shree Krishna Khadka
Special cases of Newton Raphson Method:
Case 1: Find the solution to compute the sequence root of any positive integer ‘N’.
Solution:
As per the case: √
i.e. √
i.e.
i.e. f(x) = and f’(x) =
i.e. { }
In general:
{ }
Case 2: Show that the Pth root of any given positive integer ‘N’ is:
{ }
Solution:
i.e. { }
In general:
{ }
25
Page
Prepared By
Er. Shree Krishna Khadka
Case 3: Show that the reciprocal of the Pth root of any positive number ‘N’ is:
Solution:
As per the case:
√
i.e.
i.e. f(x) = and f’(x) =
i.e.
In general:
Case 4: Derive the general equation to find the value of reciprocal of any positive
integer ‘N’.
Solution:
i.e.
In general:
26
Page
Prepared By
Er. Shree Krishna Khadka
Convergence of Newton Raphson Method:
Let xn be the estimate to the root of the function f(x)=0. If xn and xn+1 are close to each
other, then using Taylor’s Series Expansion:
(i)
Let us assume that, the exact root of f(x) be xr, then: xn+1 = xr, then: f(xn+1)=0. So,
equation (i) becomes:
… (ii)
As we have:
i.e. … (iii)
Similarly,
Now, neglecting the higher power terms and expressing equation (iii) in terms of error:
This shows that error is roughly proportional to the square of the error at previous
iteration. Therefore, Newton Raphson method has quadratic convergence.
Prepared By
Er. Shree Krishna Khadka
SECANT METHOD
Secant method uses two initial estimates but does not required that they must bracket
the root. It can use two points x1 and x2 as shown in the figure below as starting values
although they do not bracket the root.
X1, f(x1)
f(x)
X2, f(x2)
x3
x
x2 x1
…. (i)
… (ii)
Hence, the approximate value of the root can be refined by repeating the process
to the desired level of accuracy. So, in general:
…. (iii)
Algorithm:
1. Decide the initial points: x1 and x2 and EPS.
2. Compute: f1 = f(x1) and f2 = f(x2)
3. Compute:
Set (x1 = x2, f1 = f2) and set (x2 = x3, f2 = f(x3)); go to step 3, otherwise set root =
x3.
28
5. Print root
6. Stop
Page
Prepared By
Er. Shree Krishna Khadka
Example
Use Secant Method to estimate the root of the equation x2 – 4x -10 = 0, with
initial estimate x1 = 4 and x2 = 2.
Solution:
x1 = 4, f(x1) = f1 = 42 – 4*4 – 10 = -10
x2 = 2, f(x1) = f1 = 22 – 4*2 – 10 = -14
n x1 f1 x2 f2 x3 f3 EPS
0 4 -10 2 -14 9 35 0.7778
1 2 -14 9 35 4 -10 1.2500
2 9 35 4 -10 5.1111 -4.321 0.2174
3 4 -10 5.1111 -4.321 5.9565 1.6539 0.1419
4 5.1111 -4.321 5.9565 1.6593 5.7225 -0.1429 0.0409
Hence, the root is: 5.7225, which is less than EPS = 0.05
Where EPS =| | and in each iteration: x1 = x2, f1 = f2 and x2 = x3, f2 = f(x3).
…. (i)
… (ii)
the derivative.
Page
Prepared By
Er. Shree Krishna Khadka
Convergence of Secant Method:
We have, Secant Iterative Formula:
Or … (i)
If xr be the actual root fo f(x) and ei be the error in estimate of xi, then:
xn+1 = en+1 + xr
xn = en + xr
xn-1 = en-1 + xr
Now, rewriting equation (i) in terms of error with these values, we get:
… (ii)
According to Mean Value Theorem, if x = Rn lie in the interval xn and xr, then:
…. (iii)
Similarly:
Substituting these values in the numerator of equation (ii), we get:
.. (iv)
i.e. … (v)
As we also know that, if the order of convergence of an iterative process is P, then:
i.e. … (vi)
Now, from equation (iv) and (v):
… (vii)
Finally, from equation (vi) and (vii):
So, the order of convergence of Secant Method is 1.618, which is a slow rate (<2). It
also requires previous two iterative to estimate the new one. These are recognized
30
Prepared By
Er. Shree Krishna Khadka
ITERATION METHOD:
It is also known as, direct substitution method or method of fixed point iteration or
method of successive approximation. It is applicable if the equation f(x) = 0 can be
expressed in terms of x = g(x). If x0 is the initial approximation to the root, then the
next approximation will be: x1 = g(x0) and the next again will be: x2 = g(x1) and so on.
In general: xn+1 = g(xn)
Where, x = g(x) is known as fixed point equation.
Algorithm:
1. Read an initial guess: x0 and EPS
2. Evaluate: x1 = g(x0)
3. Check for error: if | | EPS, x1 is root, else continue.
4. Assign the value of x1 to x0, i.e. x0 = x1 and repeat steps 2 & 3.
5. Print x1.
6. Stop
Example:
Evaluate the square root of 5 using Fixed Point Iterating method.
Solution:
As, √
Let, x0 = 1, then:
g(x0) = 5/1 = 5 = x1
g(x1) = 5/5 = 1 = x2
g(x2) = 5/1 = 5 = x3
g(x3) = 5/5 = 1 = x4 and so on.
Here, the solution does not converge to the solution, this type of divergence is
known as oscillatory divergence.
Prepared By
Er. Shree Krishna Khadka
As x = 5/x can also be written in the form: ( )
For x0 = 1,
g(x0) = 3 = x1
g(x1) = 2.3333 = x2
g(x2) = 2.2381 = x3
g(x3) = 2.2361 = x4
g(x4) = 2.2361 = x5
Now, the process converges rapidly to the solution. Hence, the root of 5 is 2.2361.
….. (i)
….. (ii)
…. (iii)
… (iv)
…. (v)
If ei is the error in ith iteration then equation (v) in terms of error will be:
…. (vi)
This shows that, the error will decrease with each iteration iff g’(R) < 1. Hence, the
Iteration Method converges only when |g’(x)|<1.
32
Page
Prepared By
Er. Shree Krishna Khadka
HORNER’S METHOD FOR FINDING ROOTS
- Historic name for synthetic division is Horner’s Method.
- Let positive root of f(x) = 0 lies in between and , where is an integer.
Then the value of the root will be , where d1, d2 … are digits in their
decimal parts.
- To find the value of d1, first diminish the roots of f(x) = 0 by . For example, if
root lies in between 0 and 1 then root will be 0. . And make the
transformed equation.
- Multiply the root of the equation by the order of 10 and diminish other decimal
parts and so on.
- Continue the process to obtain the root of the equation at any desired degree of
accuracy by digit.
Example:
Find the root of the equation x3 + 9x2 – 18 = 0 to two decimal digit using
Horner’s Method.
Solution:
As: x3 + 9x2 – 18 = 0 =f1 (x) … (i)
So, f(x1)*f(x2) < 0 is analysed using following table.
x -5 -4 -3 -2 -1 0 1 2 3 4 5
f(x) 82 62 36 10 -10 -18 -8 26 90 190 332
So, root lies in between 1 and 2 as f(x) shifted from negative to positive at these
values. Hence, the integer part of the root is: 1. d1d2 up to two decimal places.
Now, we are going to diminish the root of the equation by 1 using synthetic
division as follow.
Coeff. x3 x2 x1 x0
1) 1 9 0 -18
0 1 10 10
1) 1 10 10 (-8)
0 1 11
1) 1 11 (21)
0 1
(1) (12)
Prepared By
Er. Shree Krishna Khadka
x -4 -3 -2 -1 0 1 2 3 4
f(x) -14544 -13247 -11728 -9981 -8000 -5779 -3312 -593 2384
Here, f2(x=3) * f2 (x=4) < 0. So, d1 must be 3. Hence, the integer part updated to
1.3d2. Now again, diminishing the root by 3 using synthetic division.
Coeff. x3 x2 x1 x0
3) 1 120 2100 -8000
0 3 369 10
3) 1 123 2469 (-593)
0 3 378
3) 1 126 (2847)
0 3
(1) (129)
X -3 -2 -1 0 1 2 3
f(x) -1435517 -1157248 -876411 -593000 -307009 -18432 272737
34
Page
Prepared By
Er. Shree Krishna Khadka
Assignment: 2
Full Marks: 50
Pass Marks: 25
(a) [5]
(a) – & compare the output with the true value of x as 0.567143. [5]
(b) [5]
35
Page
Prepared By
Er. Shree Krishna Khadka
Interpolation
Contents:
o Introduction
o Errors in Polynomial Interpolation
o Interpolation with Equally Spaced Values
o Finite Difference Method
Forward Difference Method
Backward Difference Method
Central Difference Method
o Difference of Polynomial
o Interpolation with Unequally Spaced Values
o Linear Interpolation Formula
o Lagrange Interpolation Formula
o Newton Interpolation Polynomial
o Inverse Interpolation
o Divided Differences
o Assignment 3
36
Page
Prepared By
Er. Shree Krishna Khadka
INTERPOLATION
If a function, say f(x) is constructed, such that it passes through all the set of data
points and then evaluating f(x) for the specified value of x is known as interpolation.
This method of constructing a function gives the estimation of values at non tabular
print. The functions are known as interpolation polynomials.
2. …(ii), this
is known as nth order polynomial in Shifted Power Form, and
3. ...(iii),
this is known as nth
order polynomial in Newton Form, which reduces to
shifted power form, when c1 = c2 = c3 = … = cn and reduces to simple power form,
when ci = 0 for all i.
Let the function y(x), defined by the (n+1) points (xi, yi), i = 0, 1, 2 … n, be the
continuous and differentiable (n+1) times and let y(x) be approximated by a
polynomial of degree not exceeding ‘n’ such that:
i = 0, 1 … n
… (i)
Since, y(x) is generally unknown and hence, we do not have any information
concerning y(n+1)(x). It is almost useless in practical computation. But, on the other
37
Prepared By
Er. Shree Krishna Khadka
FINITE DIFFERENCES: INTERPOLATION WITH EQUALLY SPACED VALUES
Assume that, we have a table of values: (xi, yi), (i = 0, 1, 2, … n) of any function y =f(x),
the values of x being equally spaced, i.e. xi = x0 + ih, (i = 0, 1, 2, … n). The method of
finding the solution of f(x) for some ‘x’ in the range is based on the
concept of such finite differences.
Forward Difference:
If y0, y1, …. Yn denote a set of values of y at x0, x1, … xn respectively, then (y1 – y0),
(y2 – y1), …. (yn – yn-1) are called difference of y; i.e. , ,
….. , where is the forward difference operator. Usually, the
functions are tabulated at equal intervals, i.e. x1 – x0 = x2 – x1 = x3 – x2 …. xn – xn-1 =
na. Here, with tabulation at equal intervals a difference table for ‘n’ points may
be expressed as shown below:
x f(x) ….
….
…. ….
…. …. ….
…. …. …. ….
…. …. …. …. …. ….
Formula. It is applied when the required point is close to the start of the table.
Page
Prepared By
Er. Shree Krishna Khadka
Example:
For the given table, find the value of f(0.16).
x 0.1 0.2 0.3 0.4
f(x) 1.005 1.020 1.045 1.081
Solution:
x0 = 0.1, x1 = 0.2 … i.e. h = x1 – x0 = 0.2 – 0.1 = 0.1
We have given, x = 0.16. So: s = (x – x0)/h = (0.16 – 0.1)/0.1 = 0.6
X f(x)
Now:
Backward Difference:
If the required point is close to the end of the table, we can use another formula
known as Newton Gregory Backward Difference Formula. Here, the reference
point is: ‘xn’ instead of x0. Therefore, s = (x – xn)/h.
So, the Newton Gregory Formula is given by:
The table for the backward difference will be identical to the forward difference
table. However, the reference point will be below the point for which the
estimate is required. So, the value of ‘s’ will be negative for backward
interpolation. The backward difference table is shown below.
39
Page
Prepared By
Er. Shree Krishna Khadka
X f(x) ….
….
…. ….
…. …. ….
…. …. ….
…. …. ….
…. ….
…. ….
Example:
Estimate the value of sin(45o) using backward difference method with the
following set of data.
x 10 20 30 40 50
f(x)=sin(x) 0.1736 0.342 0.5 0.6428 0.768
Solution:
x0 = 10, x1 = 20 … i.e. h = x1 – x0 = 20 – 10 = 10
We have given, x = 45. So: s = (x – xn)/h = (45 – 50)/10 = -0.5
Where, the necessary data are fetched from the following Backward Difference
Table.
40
Page
Prepared By
Er. Shree Krishna Khadka
Backward Difference Table:
x f(x)
0.0024
0.1252
50 0.768
Difference of a polynomial:
As, we have discussed difference table by forward and backward difference
method. Let us analyse, what actually differs in the first, second and … difference
in their degrees.
i.e; ,
Then we obtain:
[ [
[ ]
[
This shows that the first difference of polynomial of the nth degree is a
polynomial of degree (n-1) and so on.
Page
Prepared By
Er. Shree Krishna Khadka
Where;
Coefficient of xn-1 is a0(nh) in first difference.
Coefficient of xn-2 is a0n(n-1)h2 in second difference.
……………….. ….. … …………….. ………………………….
……………….. ….. …. …………….. …………………………..
Coefficient of x0 is a0n!hn in nth difference.
Where, s = (x-x0)/h; ‘x’ is referred near to the start of the table and ‘h’ is a
interval constant
Where, s = (x-xn)/h; ‘x’ is referred near to the end of the table and ‘h’ is a
interval constant
For interpolation near the middle of the table, Stirling’s Formula gives the most
accurate result for and Bessel’s Formula is most efficient near ,
say . But in the case, where a series of calculations have to made, it
would be inconvenient to use both of these formulae and a choice must be made
between them. Everett’s Formula may be gainfully employed for the aforesaid
reason.
42
Page
Prepared By
Er. Shree Krishna Khadka
LINEAR INTERPOLATION
The simplex form of interpolation is to approximate two data points by straight line.
Suppose, we are given two points, [x1, f(x1)] and [x2, f(x2)], these two points can be
connected linearly as shown in the figure below.
f(x)
f(x2)
f(x)
f(x1)
x
x1 x x2
{ } … (i)
C1 = x 1, a0 = f(x1) and a1 =
Hence, the co-efficient ‘a1’ represent the first derivative of the given function.
43
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Given the table of data:
x 1 2 3 4 5
f(x) 1 1.4142 1.7321 2 2.2361
Solution:
Since, the given value 2.5 lie in between the point 2 and 3. So, x1 = 2 and x2 = 3
whereas x=2.5.
Now:
{ }
i.e. { }
i.e. { }
Here, Error_2 > Error_1. Hence, it can be concluded that: smaller the interval
between the interpolation data points, the better will be the approximation.
….. (ii)
44
Substituting the values of b1, b2 and b3 from equation (iii) to equation (i), we get:
Page
Prepared By
Er. Shree Krishna Khadka
i.e. … (iii)
… (iv)
Where:
… (iv)
∑ … (v)
Where;
∏ ( ) … (vi)
Here, equation (v) is called Lagrange’s Interpolation Polynomial of degree ‘n’ and
then equation (vi) is called Lagrange’s Basic Polynomial.
45
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Find the Lagrange’s Interpolation Polynomial to fit the following data. Use
polynomial to estimate the value of e1.5.
0 1 2 3
0 1 2 3
0 1.7183 6.3891 19.0855
Solution:
= 0 + 1.7183{ }+6.3891{ } { }
Now:
approximation is used.
Page
Prepared By
Er. Shree Krishna Khadka
Divided Differences
The Lagrange’s Interpolation Formula has the disadvantage that if another
interpolation point were added, then the interpolation coefficients li(x) will have to
be recomputed; we therefore seek an interpolation polynomial which has the
property that a polynomial of higher degree may be derived from it by simply
adding new terms.
Newton general interpolation formula is one such formula, which employs what are
called divided differences. It is our principle purpose to define sch differences and
discuss certain of their properties to obtain the basic formula.
If (x0,y0), (x1,y1)…. (xn,yn) be the given (n+1) points, then the divided difference of
order 1, 2, … n are defined by the relation>
f(x0) = a0
Prepared By
Er. Shree Krishna Khadka
Example:
A table of polynomial is given below. Fit the polynomial and find the value of
f(x) at x = 2.5. Use divided difference table.
x -3 -1 0 3 5
f(x) -30 -22 -12 330 3458
Solution:
Therefore,
f(x) = -30+4(x+3)+2(x+3)(x+1)+4(x+3)(x+1)(x-0)+5(x+3)(x+1)(x-0)(x-3)
i.e. f(2.5)= -30+4(2.5+3)+2(2.5+3)(2.5+1)+4(2.5+3)(2.5+1)(2.5-0)+5(2.5+3)(2.5+1)(
2.5-0)( 2.5-3)
i 0 1 2 3 4
xi 1 2 3 4 5
f(xi) 0 7 26 63 124
Solution:
a0 = 0, a1 = 7, a2 = 6, a3 = 1 and a4 = 0
48
f(1.5) = 2.375
Page
Prepared By
Er. Shree Krishna Khadka
Assignment: 3
Full Marks: 40
Pass Marks: 20
2. Use linear interpolation method to calculate the square root of 4.5 from
following table.
x 1 2 3 4 5 6
f(x) 1 1.4142 1.7321 2 2.2361 2.4494
x -2 -1 2 3
f(x) -12 -8 3 5
x 50 52 54 56
f(x)= √ 3.684 3.732 3.779 3.825
5. Given the following set of data points. Obtain the table of divided
difference and use that table to estimate the value of f(1.5), f(3.45) & [5]
(4.2)3.
x 1 2 3 4 5
f(x)=x3-1 0 7 26 63 124
49
Page
Prepared By
Er. Shree Krishna Khadka
`
Contents:
Prepared By
Er. Shree Krishna Khadka
CURVE FITTING & REGRESSION: INTRODUCTION
Previously, we have discussed the methods of curve fitting for the data points of well
defined functions. In this topic, we will discuss on methods of curve fitting for
experimental data. In many applications it often becomes necessary to establish a
mathematical relationship between experimental values. The mathematical equation
can be used to predict values of the dependent variables. For example: we would like
to know the maintenance cost of equipment as a function of age or mileage.
a) Relation is linear
b) Relation is transcendental
c) Relation is polynomial
f(x)
f(x) = a + bx
ai
(Xi, yi)
a
x
Consider a point (xi, yi) as shown in figure. The vertical distance of this point from the
line f(x) = a + bx is the error: ai. Then ai = yi – f(xi) = yi – a – bxi ….. (i)
The best approach that could be tried for fitting a best line through the data is to
minimize the sum of squares of errors.
i.e. ∑ ∑
The technique of minimizing the sum of square of errors is known as least square
regression.
51
Page
Prepared By
Er. Shree Krishna Khadka
FITTING LINEAR EQUATIONS
∑ ∑ … (i)
In this method of least square, we choose ‘a’ and ‘b’ such that Q is minimum. Since, Q
depends on ‘a’ and ‘b’, a necessary condition for Q to be minimum is given by:
&
Then:
∑ & ∑
Equations, (ii) and (iii) are called normal equations, solving for ‘a’ and ‘b’, we get:
∑ ∑ ∑ ∑ ∑
∑ ∑
…. (iv) & ̅ ̅ … (v)
Example
Fit a straight line to the following set of data.
x 1 2 3 4 5
y 3 4 5 6 8
Solution:
The various summations are calculated as below:
xi yi
1 3 1 3
2 4 4 8
3 5 9 15
4 6 16 24
5 8 25 40
∑ = 15 ∑ = 26 ∑ = 55 ∑ = 90
Here, n = 5
52
Prepared By
Er. Shree Krishna Khadka
FITTING TRANSCENDENTAL EQUATIONS
The relationship between dependent and independent variables is not always linear.
The non-linear relationship may exist in the form of transcendental equation. For
example, the familiar equation of population growth is given by:
… (i)
Where, ‘P0’ is the initial population, ‘K’ is the rate of growth and ‘t’ is time.
… (ii)
Where, ‘P’ is pressure and ‘v’ is volume. If we observe the values of ‘P’ for the various
values of ‘v’, we can then determine the parameter ‘a’ and ‘b’.
The problem of finding the values of ‘a’ and ‘b’ can be solved by using the algorithm
given for linear equation. Let us rewrite the equation using the conversion of variable
as ‘x’ and ‘y’. So, the equation becomes:
… (iii)
… (iv)
Now, comparing equation (iv) with standard linear equation, y = a + bx, we found:
…. (v)
∑ ∑ ∑
∑ ∑
…. (vi) &
∑ ∑
∑ ∑
53
i.e. { } …. (vi)
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Given the data table:
x 1 2 3 4 5
y 0.5 2 4.5 8 12.5
Solution:
Now:
∑ ∑ ∑
∑ ∑
∑ ∑
ln(a) =
Home Work
The temperature of a metal strip was measured at various time intervals during
heating and the values are given in the table below:
Time ‘t(min)’ 12 2 3 4
Temperature ‘T( C) 70 83 100 124
o
If the relation between the time ‘t’ and temperature ‘T’ is of the form: T = b.et/4 +
a, estimate the temperature at t = 6 minute.
Solution:
Hint: As T = b.et/4 +a … (i), we can write this equation in the form: y = b.f(x) +a …. (ii),
54
where, y = T and f(x) = et/4. Now, use linear formula and adjust the values at final. Ans:
37.56et/4+21.31
Page
Prepared By
Er. Shree Krishna Khadka
FITTING A POLYNOMIAL EQUATION
When a given series of data does not appear to satisfy a linear equation, we can try a
suitable polynomial as a regression to fit the data. The least square technique can be
used to fit the data to a polynomial
Consider the polynomial of degree (m-1) as below:
… (i)
If the data contains ‘n’ sets of ‘x’ and ‘y’, then the sum of squares of the error is given
by:
∑ …. (ii)
Hence; f(x) is a polynomial and contain coefficients: a1, a2,….,am. We have to estimate
all ‘m’ coefficients. As before, we have the following ‘m’ equations that can be solved
for these coefficients.
i.e.
∑ ; Where:
Thus we have:
∑ ; Where:
Or ∑ { } ; …. (iii)
∑ ∑
So, there are ‘m’ equations: (j=1, 2, 3, …. ,n) and each summation is for i =1 to i =n.
∑ ∑ ∑ ∑
∑ ∑ ∑ ∑ ∑
……………………………… …….. ……..
……………………………… …….. ……..
55
∑ ∑ ∑ ∑ ∑
Page
Prepared By
Er. Shree Krishna Khadka
#Note: For a second order polynomial, we will have the following simultaneous
equations:
∑ ∑ ∑
∑ ∑ ∑ ∑
∑ ∑ ∑ ∑
Example:
Fit a second order polynomial to the data in the table below:
x 1 2 3 4
y 6 11 18 27
Solution:
Below is the tabulation the values as second order polynomial components.
x y x2 x3 x4 xy x2y
1 6 1 1 1 6 6
2 11 4 8 16 22 44
3 18 9 27 81 54 162
4 27 16 64 256 108 432
∑ ∑ ∑ ∑ ∑ ∑ ∑
On calculation: a1 = 3, a2 = 2 and a3 = 1
Hence, the least square quadratic polynomial is: y = 3 + 2x + x2.
Home Work:
From the given data table, fit a second order polynomial.
x 1 2.1 3.2 4
y 2 2.5 3.0 4
Equations:
4a1 + 10.3a2 + 31.65a3 = 11.5 … (i)
10.3a1 + 31.65a2 + 107.029a3 = 32.85 … (ii)
31.65a1 + 107.029a2 + 381.3057a3 = 107.745 … (iii)
56
Prepared By
Er. Shree Krishna Khadka
MULTIPLE LINEAR REGRESSIONS:
There are number of situations, where the dependent variable is a function of two or
more variables. For example, the salary of a sales person may be expressed as: y = 500
+ 5x1 + 8x2, where x1 and x2 are the number of unit sold of product 1 and 2
respectively. We shall discuss an approach to fit the experimental data, where the
variable under consideration is a linear function of two independent variables.
… (i)
∑ ∑ … (ii)
Differentiation equation … (ii) w. r. t. a1, a2, a3 and equating them to zero, we will get
the condition for minimum error.
∑ ∑ ∑
∑ ∑ ∑ ∑
∑ ∑ ∑ ∑
Example:
Given the table of data:
x 1 2 3 4
z 0 1 2 3
y 12 18 24 30
Solution:
57
Prepared By
Er. Shree Krishna Khadka
x z Y x2 z2 z.x x.y y.z
1 0 12 1 0 0 12 0
2 1 18 4 1 2 36 18
3 2 24 9 4 6 72 48
4 3 30 16 9 12 120 90
∑ ∑ ∑ ∑ ∑ ∑ ∑ ∑
Home Work
Given the data points
X 5 4 3 2 1
Z 3 -2 -1 4 0
Y 15 8 -1 26 8
Solution:
Ans: y = 10 – 2x + 5z
SPLINE INTERPOLATION:
Data fitting by means of polynomials has been considered in the previous exercise.
From the viewpoint of cubic splines, the resulting approximation called the cubic
spline approximation, suffers from the disadvantage of being a global approximation,
which means that a change in one point affects the entire approximation curve. So, a
method based on the basis splines, which posses a local character, viz; a change in one
point introduces a change only in the immediate neighbourhood of that point, called
B-spline method that finds important application in computer graphics and smoothing
of data.
Cubic B-Splines:
58
It resembles the ordinary cubic spline in which a separate cubic is derived for each
interval. Specially, a cubic B-spline (or a B-spline of order-4) denoted by B4i(x), is a
Page
cubic spline with knots Ki-4, Ki-3, Ki-2, Ki-1 and Ki, which is zero everywhere except in the
Prepared By
Er. Shree Krishna Khadka
range Ki-4 < x < Ki. In such case, B4i(x) is said to have a support [Ki-1, Ki]. It may be
noted that a B-spline need not necessarily pass through any or all of the data points.
Cubic splines are popular because of their ability to interpolate data with smooth
curves. If we consider the construction of a cubic spline function which would
interpolate the points (x0, f0), (x1, f1) … (xn, fn). The cubic spline S(x) consists of (n-1)
cubic corresponding to (n-1) sub intervals. If we denote such cubic by Si(x), then:
S(x) = Si(x); for I = 1, 2, … n.
a) S(x) must interpolate the function at all the points: x0 , x1, …. xn; i.e. for each ‘i',
S(xi) = fi.
b) The function values must be equal at all the interior knots, i.e. Si(xi) = Si+1(xi)
c) The first derivative at the interior knots must be equal; Si’(x) = Si+1’(x)
d) The second derivative at the interior knots must be equal; Si’’(xi) = Si+1’’(xi)
e) The second derivative at the end points are zero; S’’(x0) = S’’(xn) = 0
Let us consider (n+1) sample points with ‘n’ number of different section as shown in
the figure below. Suppose, gi(x) represents a cubic polynomial between [xi, f(xi)] and
[xi+1, f(xi+1)].
g(xi)
F(x) g(xi+1)
……… ………
x
xi-2 xi-1 xi xi+1… x
1.) Since, function must pass through all the points; i.e; gi(xi) = di = f(xi) ….(i)
Prepared By
Er. Shree Krishna Khadka
at x = xi , equation (iii) becomes: gi’’(x) = 2bi = Si say; i.e. bi = Si/2 …(iv)
Similarly:
gi’’(xi+1) = Si+1 = 6ai(xi+1 - xi) + 2bi = 6aihi + 2bi
Where; xi+1 - xi = hi
Then; ai = (Si+1 – Si)/6hi …. (v)
3.) Again, gi(xi+1) = f(xi+1);
But, f(xi+1) = aihi3 + bihi2 + Cihi + di = aihi3 + bihi2 + Cihi + f(xi)
i.e. Ci = [{f(xi+1) – f(xi)}/h] - aihi2 - bihi ….(vi)
4.) Also from equation (ii) we have: gi-1’(x) = 3ai-1(x-xi-1)2 + 2bi-1(x-xi-1) + Ci-1 … (vii)
And we also have the condition that, at x = xi, gi’(xi) = gi-1’(xi), then:
Ci = 3ai-1(hi-1)2 + 2bi-1(hi-1) + Ci-1 …. (viii)
5.) Finally on manipulating all these values, we get a final equation as:
{ }
6.) Expressing above equation in matrix form:
[ ][ ]=6[ ]
Example:
Fit the data of table with a natural cubic spline curve and evaluate the spline
values, g(0.66) and g(1.75), with h0 = 1, h1 = 0.5 and h2 = 0.75
X 0 1 1.5 2.25
f(x) 2 4.4366 6.7134 13.9130
(Hint: The relation is described as: f(x) = 2ex – x2)
Solution:
h1 = x2 – x1 = 1.5 – 1 = 0.5
h2 = x3 – x2 = 2.25 – 1.5 = 0.75
Page
Prepared By
Er. Shree Krishna Khadka
2.) For natural spline, S0 = 0 and S3 = 0
[ ][ ] [ ]
i.e. [ ][ ] [ ]
i.e. 3S1 + 0.5S2 = 12.702 … (i) and 0.5S1 + 2.5S2 = 30.2742 …(ii)
i 0 1 2
ai = (Si+1 – Si)/6hi 0.381 3.12 -2.598
bi = Si/2 0 1.146 5.825
Ci = [{f(xi+1) – f(xi)}/h] - aihi2 - bihi 2.0556 3.200 6.680
di = f(xi) 2 4.4366 6.7134
Home Work:
Given the data points:
i 0 1 2
xi 4 9 16
f(xi) 2 3 4
Solution:
h0 = 5 and h1 = 7
S0 = 0 = S2, but S1 = -0.01428
a0 = -0.000476, a1 = 0.00034
b0 = 0, b1 = -0.00714
c0 = 0.2119, c1 = 0.6259
61
d0 = 2, d1 = 3
Page
If f1, f2 … fn be the values of the given function and g1, g2, … gn be the corresponding
values of the approximating function; then the error vector ‘e’, where the components
of ‘e’ is given by: ei = fi – gi …..(i).
The approximation may be chosen in a number of ways. For example, we may find the
approximation such that the quantity √ is minimum. This leads us
to the least square approximation, which we have already studied. On the other hand,
we may choose the approximation such that the maximum component of ‘e’ is
minimized. This leads us to the ‘Celebrated Chebyshev Polynomials’, which have found
important application in the approximation of function in digital computers.
62
Page
Prepared By
Er. Shree Krishna Khadka
Assignment 4
Full Marks: 25
Pass Marks: 15
6. The table below gives the temperatures T(OC) and lengths(mm) of a heated
rod. If l = a0 + a1T, find the values of a0 and a1 using linear least squares.
Find the length of the rod when T = 72.5oC. [5]
T 40 50 60 70 80
l 600.5 600.6 600.8 600.9 601.0
Time(‘t’ min) 1 2 3 4
Temp(‘T’ OC) 70 83 100 124
If the relation between the time ‘t’ and temperature ‘T’ is of the form: T =
bet/4 + a. Estimate the temperature at t = 6 minute. [5]
8. Fit a second order polynomial to the data given in the table below. [5]
x 1 2.1 3.2 4
f(x) 2 2.5 3.0 4
x 5 4 3 2 1
z 3 -2 -1 4 0
y 15 8 -1 26 8
Use multiple linear regression formula to fit the data of the form:
y = a1 + a2(x) +a3(z) & Find f(5.3) and f(3.7). [5]
10. Fit a natural cubic B-Spline, S to the data given below in the table. [5]
Prepared By
Er. Shree Krishna Khadka
`
Numerical Differentiation
& Integration
Contents:
Prepared By
Er. Shree Krishna Khadka
NUMERICAL DIFFERENTIATION: INTRODUCTION
The method of obtaining the derivative of a function using a numerical technique is
known as numerical differentiation. The general method for deriving the numerical
differentiation formulae is to differentiate the interpolating polynomial. There are
essentially two situations where numerical differentiation is required. They are:
1. The function values are known but the function is unknown. Such functions are
called tabulated function.
Since, analytical methods give exact answers; the numerical techniques provide only
approximations to derivatives. Numerical differentiation methods are very sensitive
to round off errors, in addition to the truncation error introduced by the methods of
themselves. So, it is necessary to discuss the errors and ways to minimize them.
Similarly, we can also show that the first order backward difference quotient is:
…. (a)
65
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Estimate approximate derivative of f(x) = x2 at x = 1, for h = 0.2, 0.2, 0.05, 0.01
using first order forward difference formula.
Solution:
We have: f(x) = x2
a) Analytical Method: f’(x) = 2x, i.e. f’(x=1) = 2 X 1 = 2 (true value)
b) Numerical Method:
, which will give the approximation of derivative.
h f'(1) Error
0.2 2.2 0.2
0.1 2.1 0.1
0.05 2.05 0.05
0.01 2.01 0.01
Conclusively, it is found that the derivative approximation approaches the exact value
as ‘h’ decreases. The truncation error decreases proportionally with decrease in ‘h’.
There is no round off error.
… (b)
Prepared By
Er. Shree Krishna Khadka
Example:
Repeat the previous example for three point formula.
Solution:
We have: f(x) = x2 , i.e. f(x=1) = 2 (true value)
Now, for different values of ‘h’ the derivative approximations are tabulated below:
h f'(1) Error
0.2 2 0
0.1 2 0
0.05 2 0
0.01 2 0
Where:
Error Analysis
Numerical differentiation is very sensitive to round off errors. If Er(h) is the round off
error introduced in an approximation of derivative, then the total error is given by:
E(h) = Er(h) + Et(h) …. (i)
i.e.
( ) ( )
If the errors e1 and e0 are of the magnitude ‘e’ and of opposite signs, the we get bound
for round off error as:
We can obtain a rough estimation of ‘h’ that gives the minimum error. By
differentiating equation (a) with respect to ‘h’, we get:
Now, we know that E(h) is minimum when E’(h) = 0. So, solving for ‘h’, we obtain
Where, hopt is optimum step size. Substituting this value in equation (a), we get:
( ) √
Example:
Compute the approximate derivative of f(x) = sin(x) at x = 0.45 radian at
increasing value of ‘h’ from 0.01 to 0.04 with a step size of 0.005. Analyse the
total error. What is the optimum step size?
Solution:
We have given: y = f(x) = sin(x) and f’(x) = cos(x)
So, f(x=0.45rad) = sin(0.45rad) = 0.4350(rounded to four digits)
And f’(x=0.45rad) = cos(0.45rad) = 0.9004
Using two point formula, table below gives the approximate derivatives of sin(x) at x =
0.45 radian using different values of ‘h’.
Prepared By
Er. Shree Krishna Khadka
The total error decreases from 0.0104 (at h = 0.01) till h = 0.02 and again increases
when ‘h’ is increased.
Since, we have used four significant digits; the bound for round off error ‘e’ is 0.5x10 -4.
For the two point formula, the bound M2 is given by:
M2 = max|f’’( )| for:
√ √
( ) √
As we know that:
… (a) and similarly,
… (b)
Where: R1 = and R2 = =
…. (c)
Therefore:
i.e. Et(h) =
69
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Find the approximation to second derivative of cos(x) at x = 0.75 with = 0.01.
Compare with the true value.
Solution:
Therefore,
f’’(0.75) =
When function values are available in tabulated from, we may approximate this
function by an interpolation polynomial P(x) as discussed in earlier chapter and then
differentiate P(x).
i.e. …. (i)
Then: …. (ii)
If x0 = x, x1 = x + h, x2 = x + 2h, then:
[ … (b)
Page
Prepared By
Er. Shree Krishna Khadka
Now, substituting the values of a1 and a2 in equation (ii), we will get the three-point
forward difference formula for the approximation of first derivative as below:
… (iii)
… (iv)
[ … (c) and
Example:
The table below gives the values of distance travelled by a car at various time
intervals during the initial running.
Time, t(s) 5 6 7 8 9
Distance Travelled, s(t) (km) 10.0 14.5 19.5 25.5 32.0
Estimate the velocity at time t = 5s, t = 7s and t = 9s. Also find the acceleration at
t = 7s.
Solution:
Prepared By
Er. Shree Krishna Khadka
Case I:
At time, t = 5, we use the three-point forward difference formula.
i.e. v(t=5)
4.25km/s
Case II:
At time, t = 7, we use the central difference formula.
i.e. v(t=7)
5.5 km/s
Case III:
At time, t = 9, we use the three-point backward difference formula.
i.e. v(t=9)
= 6.75 km/s
Case IV:
Acceleration is given by the second derivative of s(t). Therefore:
72
i.e. = 1 km/s2
Page
Prepared By
Er. Shree Krishna Khadka
NUMERICAL INTEGRATION: INTRODUCTION
The general objective of numerical integration is to compute the value of the definite
integral given below for a given set of data points (x0, y0), (x1, y1), (x2, y2), (x3, y3), …
,(xn, yn) of a function y = f(x), where f(x) is not know explicitly. So, f(x) is determined
using the interpolation technique and then integration is carried out.
i.e. ∫ …(i)
A definite integral of the form: ∫ can be treated as the area under curve y =
f(x), enclosed between the limits x = a and x = b. Then the problem of integration is
then simply reduced to the problem of finding the shaded area.
If the limits of integration ‘a’ and ‘b’ are in the set of interpolating points xi = 0, 1, 2, …,
n, then the formula is referred to as closed form. Whereas if the points ‘a’ and ‘b’ lie
beyond the set of interpolating points, then the formula is termed as open form. Since,
open form formula is not used for definite integration; we consider here only the
73
Prepared By
Er. Shree Krishna Khadka
Let us consider a General Newton’s Interpolation Formula, given by:
(ii)
Where, , then
When, and When
∫ ∫
{ ( ) ( ) }
{ ( ) ( ) } …. (iii)
Where: h = (xn – x0)/n and equation (iii) is the general equation for numerical
integration and is called General Newton Cotes Formula.
F(x) F(b)
F(a)
x
x0=a x1=b
Area(a) ={F(b)+F(a)/2}(b-a)
Prepared By
Er. Shree Krishna Khadka
Example:
Evaluate the integral: I = ∫ for (i) (1, 2) and (ii) (1, 1.5)
Solution:
F(x)
x
x0=a x1 x2 x3 xn-1 xn=b
If the data range (a, b) is divided into ‘n’ stripes of equal width ‘h’, then:
∫ ∫ ∫ ∫
( ) ( ) ( )
Here, equation (i) is the general formula for composite trapezoidal rule.
75
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Evaluate: ∫ by dividing into four stripes.
Solution:
We have given: f(x) = sin(x)
Number of stripes (n) = 4
Limits (a, b) = (0, )
Interval (h) = (b-a)/n = ( /4 = /4
x 0 /4 /2 3 /4
f(x) 0 0.7071 1 0.7071 0
Solution:
I Case:
For n = 2, we have: h = (1-(-1))/2=1
x -1 0 1
f(x) 0.368 1 2.718
II case:
For n = 4, we have: h = (1-(-1))/4 = 0.5
x -1 -0.5 0 0.5 1
f(x) 0.368 0.607 1 1.649 2.718
} = 2.3995
76
Page
Prepared By
Er. Shree Krishna Khadka
SIMPSON (1/3) RULE: (THREE POINT FORMULA)
Here, the function f(x) is approximated by a second order polynomial, which passes
through three sampling points. So, taking n = 2 in General Newton Cotes Formula and
neglecting third and higher order differences, we get:
I ∫
Since, it uses three points to evaluate the integral; it is also known as three-point
formula. The three points are: x0 = a, x2 = b and x1 = (a + b)/2. Where, the interval ‘h’ is
given by: h = (b – a)/2.
Example:
Evaluate the integral, ∫ using Simpson’s 1/3 Rule.
Solution:
Now, for h = 1, the range (a, b), the function will generate the following table:
x -1 0 1
f(x) = e 0.3698 1 2.7182
x
Prepared By
Er. Shree Krishna Khadka
COMPOSITE SIMPSON’S 1/3 RULE:
As in the case of composite trapezoidal rule, the range over which the integral have to
be carried out is divided into ‘n’ number of stripes in order to improve the accuracy of
the estimate of the area. Each stripe is then integrate by Simpson’s 1/3 Rule and
finally tied together to give the Composite Simpson’s Output. Hence, the integration
will be:
∫ ∫
∫ ∫ ∫ ∫
{ } { } { }
∑ ∑
Example:
Compute the integral: ∫ √ applying Composite Simpson’s 1/3 Rule
for n = 4 and n = 6 with accuracy to five decimal places.
Solution:
I Case: For n = 4
We have given: f(x) = √ , Limit Range (a, b) = (0, )
Interval (h) = (b – a)/n = ( )/4 =
So, the functional table will be:
x 0
f(x)= √ 0 0.61861 0.84090 0.96119 1
II Case: For n = 6, h = , and the integration will be: I = 1.18728 (same way)
Page
Prepared By
Er. Shree Krishna Khadka
SIMPSON’S 3/8 RULE
Simpson’s 1/3 rule was derived using three sampling points that fit a quadratic
equation. We can extent this approach to incorporate four sampling points so that the
rule can be exact for f(x) of degree 3.
By using the first four terms from General Newton Cotes Formula and applying the
same procedure followed in the previous case, we will get the following result:
Where, h = (b – a)/3
Example:
Use Simpson’s 3/8 Rule to evaluate, ∫ for n = 3.
Solution:
Here, a = 1, b = 2; So, h = (b – a)/3 = 1/3
Now, for different values of ‘x’ f(x) will generate the following values.
x 1 1.33 1.66 2
f(x) = x3 + 3 4 5.353 7.574 11
So, following the same procedure as we did in earlier section, we will get the formulae
for the Composite Simpson’s 3/8 Rule as below:
Where, h = (b – a)/n
Example:
Evaluate ∫ for h = 0.1 using Composite Simpson’s 3/8 Rule.
79
Page
/Home Work/
Prepared By
Er. Shree Krishna Khadka
NUMERICAL DOUBLE INTEGRATION
∫ ∫ … (i)
Dividing the range [a, b] into ‘n’ equal sub-intervals of length ‘h’ and dividing the range
[c, d] into ‘m’ equal sub intervals of equal length ‘k’.
∫ ∫
[∫ ∫ ∫ ∫
∫ ]
I [
Example:
Evaluate the double integral, ∫ ∫ using composite trapezoidal
rule. Take h = k = 0.5.
80
Page
Prepared By
Er. Shree Krishna Khadka
Solution:
Now, for different combination of (x, y) characterized by the interval (h, k), we can
generate the following table:
x x0 x1 x2
y 0 0.5 1
y0 0 1 1.648 2.718
y1 0.5 1.648 2.718 4.482
y2 1 2.718 4.482 7.389
Now, the double integral is evaluated using the composite trapezoidal formula given
by:
I [
= 0.0625(7.014+23.132+19.067)
= 3.0758
Gauss Integration is based on the concept that the accuracy of numerical integration
can be improved by choosing the sampling points wisely, rather than on the basis of
81
equal spacing.
Page
Prepared By
Er. Shree Krishna Khadka
So, Gauss Integration assumes an approximation of the form:
∫ ∑ …. (i)
Here, the method of implementing the strategy of finding appropriate values of xi and
wi and obtaining the integral f(x) over the range [-1, 1] is called Gaussian Integration
or Quadrature. Where wi are known as weights of that function associated with and xi
are the nodes (both are unknowns).
∫ … (ii)
Let us find the Gaussian Quadrature Formula for n = 2. In this case, we need to find out
the values of four unknowns, namely: and x1 and x2. Let us assume that the
integral will be exact up to cubic polynomials. This implies that the function 1, x, x2, x3
can be numerically integrated to obtain the exact results. Then from equation (i) we
will get:
and ( , )
√ √
∫ ∑ ( ) ( )
√ √
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Compute the integral, ∫ using two-point Gauss Legendre Formula.
Solution:
∫ ( ) ( ) √ √
√ √
∫ ∫ …. (i)
Assume the following transformation between ‘x’ and the new variable ‘z’.
x = Az + B …. (a)
This must satisfy the following conditions:
At x = a, z = -1 and at x = b, z = 1, which gives: B – A = a & A + B = b.
Solving for A and B, we get: A = (b – a)/2 and B = (a + b)/2
Therefore, Equation (a) becomes:
… (b)
Then: … (c)
∫ ∫ ∫ … (ii)
∫ ∑ … (iii)
Where and zi are the weights and Quadrature points for the integration domain (-1,
1).
83
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Compute the integral, ∫ using Gaussian two point formula.
Solution:
[ ( ) ( )] [ √ √ ]
√ √
/Home Work/
Compute the integral, ∫ using GL-2-Point Method. [Ans: 0.9984]
And
∫ ∑
84
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Use Gauss Legendre three-point formula to evaluate the following integral:
∫ .
Solution:
Then:
∫ ∑
, then:
and
So,
= 200.40143
85
Page
Prepared By
Er. Shree Krishna Khadka
ROMBERG INTEGRATION
In conclusion, what we have found that, the accuracy of a numerical integration
process can be improved in two ways:
1. By increasing the number of subintervals (i.e. by decreasing ‘h’): this decreases the
magnitude of error terms. Here, the order of the method is fixed.
2. By using higher order methods: this eliminates the lower order error terms. Here,
the order of the method is varied and, therefore, this method is known as variable
order approach.
The variable order method involves combining two estimates of a given order to
obtain a third estimate of higher order. The method that incorporates this process (i.e.
Richardson’s Extrapolation) to the trapezoidal rule is called Romberg Integration.
Example:
Compute the integral: ∫ using Romberg Integration, take h = 0.5, 0.25,
and 0.125
Solution:
Case I: For h = 0. 5
86
Page
Prepared By
Er. Shree Krishna Khadka
Case II: For h = 0.25
Let,
Finally, we have to refine the integration using Romberg Integration for I’ and I’’ as:
87
Page
Prepared By
Er. Shree Krishna Khadka
Assignment 5
Full Marks: 45
Pass Marks: 25
Grace Mark: 5
Time(‘t’ sec) 5 6 7 8 9
Temp(‘T’ OC) 10.0 14.5 19.5 25.5 32.0
( )
16. Evaluate by Gauss Integration, the integral, ∫ for n = 2. [5]
√
17. Use Romberg Integration to evaluate the integral, ∫ for h =
[5]
e/2 and e/4.
88
Page
Prepared By
Er. Shree Krishna Khadka
`
Contents:
o Introduction
o Method of Solving System of Linear Equations
o Elimination/Direct Method
Gauss Elimination Method
Gauss Elimination with Pivoting
Gauss Jordan Method
Triangular Factorization Method
Singular Value Decomposition
o Iterative Method
Jacobi Iteration Method
Gauss Seidel Method
89
Page
Prepared By
Er. Shree Krishna Khadka
INTRODUCTION: MATRICES & SYSTEM OF LINEAR EQUATIONS
Matrices occur in a variety of problems of interest; e.g. in the solution of linear
algebraic system, solution of partial and ordinary differential equations and Eigen
value problems. In this chapter, we introduce the matrices, through the theory o linear
transformations.
A linear equation involving two variables ‘x’ and ‘y’ has the standard form, ax + by = c,
where a, b and c are real numbers such that (a and b) 0. This equation becomes non
linear if any of the variables ( x or y) have the exponent other than one.
e.g. 4x + 4y = 15 and 3u – 2v = -0.5 are the examples of linear equations, whereas 2x –
xy + y = 2 and x + √ = 6 are the examples of non linear equations.
… (i)
-------------------------------------------------
-------------------------------------------------
Existence of Solution
In solving systems of equations, we are interested in identifying values of the variables
that satisfy all equations in the system simultaneously. If we have given an arbitrary
system of equations, it is difficult to say whether the system has solution or not. There
may be four possibilities that the system has:
Prepared By
Er. Shree Krishna Khadka
i) Systems with Unique Solution
For example: x + 2y = 9 and 2x – 3y = 4 has a solution (x, y) = (5, 2). Since no other
pair of values of x and y would satisfy the equation, the solution is said to be
unique.
iii) System has Solutions but not Unique (i.e. infinite solution)
For example: -2x + 3y = 6 and 4x – 6y = -12 has many different solutions. We can
see that these are two different forms of the same equation and, therefore, they
represent the same line. Such equations are called dependent equations.
Graphically, if two lines appear almost parallel, then we can say the system is ill-
conditioned, since it is hard to decide just at which point they intersect.
If these two lines are almost parallel, their slopes must be nearly equal.
i.e.
Where, equation (i) is the determinant of the coefficient matrix A. This shows that
the determinant of all ill-conditioned system is very small ore nearly equal to zero.
91
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Solve the following equations:
2x + y = 25
2.001x + y = 25.01
And thereby discuss the effect of ill conditioning.
Solution:
On conclusion, a small change in one of the coefficients has resulted in a large change
in the result. If we substituted these values back into the equations, we get the
residuals as: R1 = 0 and R2 = 0.01. This illustrates the effect of round off errors on ill
conditioned systems.
1. Elimination/Direct Method
It reduces the given system of equations to a form from which the solution can be
obtained by simple substitution. We will discuss the following elimination
method.
2. Iterative Method
Iterative approach, as usual, involves assumption of some initial values which
are then refined repeatedly till they reach some accepted level of accuracy. We
will discuss following iterative methods in this chapter.
Prepared By
Er. Shree Krishna Khadka
SOLUTION BY ELIMINATION
Elimination is a method of solving simultaneous linear equations. It involves
elimination of a term containing one of the unknowns in all but one equation. One
such step reduces the order of equation by one. Repeated elimination leads finally to
one equation with one unknown.
Rule:
a) An equation can be multiplied or divided by a constant.
b) One equation can be added or subtracted from another equation.
c) Equations can be written in any order.
Example:
Solve the following 3X3 system using Gauss Elimination Method.
3x + 2y + z = 10
2x +3y + 2z = 11
x + 2y + 3z = 14
Solution:
Representing the above system of three simultaneous equation in Standard Matrix
Form: i.e AX = B
[ ][ ] [ ] [ ]
[ ] [ ]
[ ]
Prepared By
Er. Shree Krishna Khadka
Limitation of Basic GEM and its Overcome:
Let us try another example, to solve the following system of 3-simultaneous equations,
given by:
3x + 6y + z = 16
2x + 4y + 3z = 13
x + 3y + 2z = 9
i.e. [ ][ ] [ ] [ ]
[ ]
Here, the elimination procedure breaks down since, A22 = 0. So, second row cannot be
normalized. Therefore, the procedure fails. One way to overcome this problem is to
interchange this row with another row below it which does not have a zero element in
that position. Then, we will have:
[ ]
i.e. , for j = 1, 2, … , n
If akk = 0; kth row cannot be normalized. Therefore, the procedure fails as in the above
case. And of course, to overcome this problem is to interchange this row with another
row below it which does not have a zero element in that position. But, there may be
more than one non-zero values in the kth column below the element akk. So, the
question is: which one of them is to be selected? It can be proved that round off error
would be reduced if the absolute value of the pivot element is large. Therefore, it is
suggested that the row with zero pivot element should be interchanged with the row
having the largest (absolute) coefficient in that position.
94
In general, the reordering of equations is done to improve accuracy, even if the pivot
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Solve the following system of linear equation by Gauss Elimination with
Pivoting: 2x + 2y + z = 6
4x + 2y + 3z = 4
x – y +z = 0
Solution:
i.e. [ ][ ] [ ] [ ]
1. Original System, 4 in the first column below 2 is the largest absolute value among
all. So, by interchanging first and second row, we will get the following modified
original system with first row as a PIVOT after interchanged.
[ ]
2. Now, applying the Basic GEM, we will get the first derived system as below:
[ ]
3. Here, the largest absolute value is: 3/2 below 1. So, interchanging second and third
row to have a modified first derived system as below with second row as a PIVOT
after interchanged.
[ ]
4. Again applying Basic GEM, we will get the second and final derived system as:
[ ]
Prepared By
Er. Shree Krishna Khadka
Gauss Jordan Method:
This method also uses the process of elimination of variables. But, the variable is
eliminated from all other rows (both below and above). This process thus eliminates
all the off-diagonal terms producing a diagonal matrix rather than a triangular matrix.
Further, all rows are normalized by dividing them by their pivot elements.
Example:
Solve by Gauss Jordan Method:
2x + 4y -6z = -8
x + 3y + z = 10
2x - 4y – 2z = -12
Solution:
i.e. [ ][ ] [ ] [ ]
[ ]
[ ]
[ ]
[ ]
[ ]
96
Page
Prepared By
Er. Shree Krishna Khadka
Triangular Factorization Method
Since, the system of linear equation can be expressed in the matrix form as: AX = B. So,
here in the triangular factorization method, the coefficient matrix A of a system of
linear equations can be factorized or decomposed into two triangular matrices L and
U such that: A = LU …. (i).
[ ]
[ ]
Once, A is factorized into L and U, the system of equations AX = B can be expressed by:
(LU)X = B, i.e. L(UX) = B … (ii)
LY = B …. (iii)
The elements of L and U can be determined by comparing the elements of the product
o L and U with those of A. This is done by assuming the diagonal elements of L or U to
be unity.
o The decomposition with L having unit diagonal values is called the Dolittle LU
Decomposition.
o The decomposition with U having unit diagonal elements is called the Crout LU
97
Decomposition.
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Solve the system of three simultaneous linear equations by using Dolittle LU
Decomposition Method.
3x + 2y + z = 10
2x + 3y + 2z = 14
x + 2y + 3z = 14
Solution:
Using Dolittle LU Decomposition, we have:
[ [ ] [ ][ ]
[ ] [ ]
Thus we have: [ ] [ ]
z = 3, y = 2 and x = 1.
Page
Prepared By
Er. Shree Krishna Khadka
SINGULAR VALUE DECOMPOSITION
Since, we used LU Decomposition only for a square matrix A. But a similar
decomposition is also possible for a rectangular matrix, which is given by Singular
Value Decomposition. This method is of great importance in matrix theory since it is
useful in finding the generalized inverse of a singular matrix and has several image
processing applications.
Let A be an (mxn) real matrix with m n. Then, the matrices ATA and AAT are non-
negative, symmetric and have identical Eigen values, say . We can then obtain the ‘n’
ortho-normalized Eigen vectors, say Xn of ATA such that:
(ATA)Xn = Xn … (i)
(AAT)Yn = Yn … (ii)
It follows that the Eigen vectors of AAT, i.e. Yn are given by:
… (iv)
√
Example:
Solution:
We have:
|ATA – |=0
Prepared By
Er. Shree Krishna Khadka
|[ ] [ ]|
|[ ]|
4. [ ][ ] [ ] [ ][ ] [ ]
[ ] [ ]
√ √
[ ][ ] [ ] [ ][ ] [ ]
[ [ ] [ ][ ][ ]
Page
Prepared By
Er. Shree Krishna Khadka
SOLUTION BY ITERATION
Solution by direct method poses some problems when the systems grow larger or
when most of the coefficients are zero. They require prohibitively large number of
floating point operation and therefore, not only time consuming but also severely
affect the accuracy of the solution due to round off errors. Iterative methods provide
an alternative for this and also ill conditioned systems can be solved by this method
without facing the problem of round off errors.
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
-------------------------------------------------
Now, we can compute x1, x2… xn by using initial guesses for these values. These new
values are again used to compute the next set of x values. The process can continue till
we obtain a desired level of accuracy in the x values.
101
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Obtain the solution of the following system using the Jacobi Iteration Method.
2x + y + z = 5
3x + 5y + 2z = 15
2x + y + 4z = 8
Solution:
Rewriting the above equation in the form:
x = (5 - y -z)/2
y = (15 – 3x – 2z)/5
z = (8 – 2x – y)/4
If we assume initial values of x, y and z to be zero, then going by iteration we will get
the following results:
n x y Z
0 0 0 0
1 2.5 3 2
2 0 0.7 0
3 2.15 3 1.825
4 0.0875 1.225 0.175
5 … … …
The process can be continued till the value of x reach a desired level of accuracy.
Prepared By
Er. Shree Krishna Khadka
Example:
Obtain the solution of the following system using the Jacobi Iteration Method.
2x + y + z = 5
3x + 5y + 2z = 15
2x + y + 4z = 8
Solution:
Rewriting the above equation in the form:
x = (5 - y -z)/2
y = (15 – 3x – 2z)/5
z = (8 – 2x – y)/4
If we assume initial values of x, y and z to be zero, then going by iteration we will get
the following results:
n x y Z
0 0 0 0
1 2.5 1.5 0.4
2 1.6 1.9 0.7
3 1.2 2 0.9
4 1.1 2 1
5 1 2 1
Hence, x = 1, y = 2 and z = 1.
103
Page
Prepared By
Er. Shree Krishna Khadka
Assignment 6
Full Marks: 50
Pass Marks: 25
2w +2x + y + 2z = 7
w - 2x - z = 2
3w - x -2y – z = 3
w - 2z = 0 [7]
2x + y – z = -1
x -2y + 3z = 9
3x – y + 5z = 14
21. Determine the Eigen Values and corresponding Eigen Vectors for the
matrix: A = [ ]. [5]
Prepared By
Er. Shree Krishna Khadka
`
Numerical Solution of
Ordinary Differential Equations
Contents:
o Introduction
o Initial Value Problems
o Solution by Taylor’s Series Method
o Euler’s Method
o Heun’s Method
o Runge Kutta Method
o Predictor Corrector Method
o Solution of Simultaneous & Higher Order Equations
o Boundary Value Problem
o Finite Difference Method
o Shooting Method
105
Page
Prepared By
Er. Shree Krishna Khadka
INTRODUCTION: DIFFERENTIAL EQUATIONS
Most of the real time physical systems are expressed in terms of rate of change. The
Mathematical models that describe the state of such systems are often expressed in
terms of not only certain system parameters but also their derivatives. Such model
which used differential calculus to express relationship between variables is known as
differential equation.
The general form of the ordinary differential equation is: F(x, y, y’, y’’, … yn) = 0.
Where, ‘x’ is independent variable, y is dependent and y’, y’’ … are derivatives of ‘y’
with respect to ‘x’.
Prepared By
Er. Shree Krishna Khadka
Order and Degree of Ordinary Differential Equation
The order of a differential equation is the highest derivative that appears in the
equation. When the equation contains only a first derivative, it is called a first
order differential equation. On the other hand, the degree of a differential equation
is the power of the highest order derivative.
For example:
On the other side, equations avoiding the above rules are known to be non linear
equations. For example: y’’ + 3y’ = 2y + x2 is a 2nd order 1st degree linear equation.
But the equation y’’ + (y’)2 = 1 and y’ = -ay2 are non linear equations.
On the other part, if the values of the constants are known, then on substitution of
these values in the general solution, a unique solution is obtained which is known
as particular solution.
Prepared By
Er. Shree Krishna Khadka
SOLUTION BY TAYLOR’S SERIES METHOD
Let us consider a differential equation in the form: y’ = f(x, y) with the initial condition
y(0) = y(x = 0) = y(x0) = y0. If y(x) is the exact solution, then we can expand a function
y(x) about a point x = x0 using Taylor’s Theorem of Expansion.
... (i)
Now, we must repeatedly differentiate f(x, y) implicitly with respect to x and evaluate
them at x0. Then equation (i) gives a power series of y.
Example:
From the Taylor’s Series for y(x), find y(0.1) correct to four decimal places if
y(x) satisfies: y’ = x – y2 and y(0) = 1.
Solution:
The Taylor’s Series for y(x) is given by:
We have:
y’(x) = x – y2 y’(0) = -1
y’’(x) = 1 - 2yy’ y’’(0) = 3
y’’’(x) = -2yy’’-2y’2 y’’’(0) = -8
yiv(x) = -2yy’’’ – 6y’y’’ yiv(0) = 34
yv(x) = -2yyiv – 8y’y’’’ – 6y’’2 yv(0) = -186 and so on…
Now: for the value of y(0.1) correct up to four decimal place, it is found that the terms
up to x4 should be considered, then we will have: y(0.1) = 0.9138 with the truncation
of (31/20)x5 0.00005.
/Home Work/
Given the differential equation: y’’ – xy’ – y = 0 with the conditions y(0) = 1 and
y’(0), use Taylor’s Series Method to determine the value of y(0.1).
108
Page
Prepared By
Er. Shree Krishna Khadka
EULER’S METHOD: (1ST ORDER RUNGE KUTTA METHOD)
The solution of differential equation by Taylor’s Series Method gives the equation in
the form of power series. We will now discuss the methods which give the solution in
the form of a set of tabulated values. Euler’s Method is one of the simplest one-step
methods and it has limited application because of its low accuracy.
True Values
y(x) Actual Solution
F(x)
y2
Errors
y0
y1
x
x0 x1 x2
h h
Let us consider the first two terms of the Taylor’s Series Expansion as:
If we have given the differential equation y’(x) = f(x, y) with the initial condition by
y(x0) = y0. Then: y’(x0) = f(x0, y0).
Hence, equation (i) becomes: y(x) = y(x0) + f(x0, y0).(x – x0)
And also : y(x1) = y(x0) + f(x0, y0).( x1 – x0)
i.e. : y1 = y0 + f(x0, y0).h
Similarly, : y2 = y1 + f(x1, y1).h
In general, : yi+1 = yi + f(xi, yi).h … (ii)
Example:
Given the equation y’ = 3x2 + 1 with y(1) = 2, estimate y(2) bye Euler’s Method
using (i) h = 0.5 and (ii) h = 0.25.
109
Page
Prepared By
Er. Shree Krishna Khadka
Solution:
Case I: For h = 0.5
y(1) = 2
y(1.5) = 2 + 0.5[3(1.0)2 + 1] = 4.0
y(2.0) = 4.0 + 0.5[3(1.5)2 + 1] = 7.875
Since, Euler’s Method does not require any differentiation and is easy to implement on
computers. However, it major weakness is large truncation errors. This is due to its
linear characteristic because it uses only the first two terms of the Taylor’s Series. So,
Heun’s Method is considered to be an improvement to Euler’s Method.
In Euler’s Method, the slope at the beginning of the interval is used to extrapolate yi to
yi+1 over the entire interval by the formula:
yi+1 = yi + m1h … (i)
An alternative is use the line which is parallel to the tangent at the point (xi+1, y(xi+1))
to extrapolate from yi, to yi+1 as shown in the figure by the formula:
yi+1 = yi + m2h … (ii)
y(x)
F(x)
y2
y1
y0
y1'
x
x0 x1 x2
h h
Prepared By
Er. Shree Krishna Khadka
The estimate given by equation (ii) appears to be overestimated.
Now, a third approach is to use a line whose slope is the average of the slope at the
end points of the interval. Then:
yi+1 = yi + … (iii)
As shown in figure, this gives a better approximation to yi+1. This approach is known
as Heun’s Method. Now from equations (i) and (ii), equation (iii) becomes:
yi+1 = yi + [ [ …(iv)
Here, the term yi+1 is appearing on both sides of the equation (iv) and therefore, yi+1
cannot be evaluated until the value of yi+1 inside the function is available.
This value can be predicted using the Euler’s Formula given in equation (i). So, finally,
equation (iv) becomes:
yi+1 [ …(v)
Hence, equation (v) is called improved version of Euler’s Method. It is also classified as
a one – step Predictor Corrector Method. Equation (i) is known as the predictor
equation whereas equation (v) is known as corrector equation.
Example:
Given the equation: y’ = 2y/x. Estimate y(2) using Heun’s Method at h = 0.25.
Solution:
y' = f(x, y) = 2y/x : For: x0 = 0, y0 = 2 : h= 0.25
Iteration: 1
m1 = (2X2)/1 = 4.0 ye(1.25) = 2 + 0.25(4.0) = 3.0
m2 = (2X3.0)/1.25 = 4.8 y(1.25) = 2 + (0.25)/2(4.0 + 4.8) = 3.1
Iteration: 2
m1 = (2X3.1)/1.25 = 4.96 ye(1.5) = 3.1 + 0.25(4.96) = 4.34
m2 = (2X4.34)/1.5 = 5.79 y(1.5) = 3.1 + (0.25)/2(4.96 + 5.79) = 4.44
Iteration: 3
m1 = (2X4.4)/1.5 = 5.92 ye(1.75) = 4.44 + 0.25(5.92) = 5.92
m2 = (2X5.92)/1.75 = 6.77 y(1.75) = 4.44 + (0.25)/2(5.92 + 6.77) = 6.03
Iteration: 4
m1 = (2X6.03)/1.75 = 6.89 ye(2) = 6.03 + 0.25(6.89) = 7.75
m2 = (2X7.75)/2 = 7.75 y(2) = 6.03 + (0.25)/2(6.89 + 7.75) = 7.86
111
Prepared By
Er. Shree Krishna Khadka
FOURTH ORDER RUNGE KUTTA METHOD
It is also a family of one step methods used for numerical solution of initial value
problems. It is also based on the general form of the extrapolation equation:
y i+1 = yi + mh …(i)
Where, ‘m’ represents the slope that is weighted averages of the slopes at various
points in the interval ‘h’. Runge Kutta (RK) methods are known by their order. For
example, an RK method is called rth order RK method when slopes at ‘r’ points are
used to construct the weighted average slope ‘m’. In Euler’s method we used only one
slope at (xi, yi) and Heun’s method employs slopes at two end points of the interval so,
they are called first-order and second-order RK method.
Higher the order better would be the accuracy of estimates. Therefore, selection of
order for using RK methods depends on the problem under consideration.
So, in 4th order RK method, we use four slopes and they are given by:
( )
( )
… (ii)
Example
Given y’(x) = x2 + y2, y(0) =0 using 4th order RK method, estimate y(0.4), take h =
0.2
Solution:
Prepared By
Er. Shree Krishna Khadka
For iteration 1, (i =0)
( ) ( ) ( )
( ) ( ) ( )
( ) ( )
( )
( ) ( )
( )
113
Page
Prepared By
Er. Shree Krishna Khadka
SIMULTANEOUS FIRST ORDER DIFFERENTIAL EQUATIONS
Mathematical models of many applications involve a system of several first order
differential equations. They may be represented as follows:
…………………………………………………………
…………………………………………………………
These equations should be solved for y1(x), y2(x) … yn(x) over interval (a, b).
&
( )
( )
Then:
… (i)
( )
( )
114
Then:
… (ii)
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Find y(0.1) and z(0.1) from the system of equations: y’ =x +z and z’ = x – y2 with
y(0) = 2, z(0) = 1 and h = 0.1
Solution:
We have, x0 = 0, y0 = 2, z0 = 1 and h = 0.05
Similarly,
m3 = 0.84 l3 = -4.22
m4 = 0.687 l4 = -4.244
Finally,
And
115
Page
Prepared By
Er. Shree Krishna Khadka
SOLUTION OF ORDINARY DIFFERENTIAL EQUATION AS A BOUNDARY VALUE PROBLEM:
We have seen that we require ‘m’ conditions to be specified in order to solve ‘m’ order
differential equation. And all the ‘m’ conditions were specified at one point, x = x0 and,
therefore we call this problem as an initial value problem. It is not always necessary to
specify the condition at one point of the independent variable. They can be specified at
different points in the interval (a, b) and, therefore, such problems are called the
boundary value problems. A large number of problems fall into this category.
In this topic, we will only discuss two special methods to solve such ordinary
differential equations they are:
a) Finite Difference Method
b) Shooting Method
… (i)
… (ii)
These are the second order equations and the accuracy of estimates can be improved
by using higher order equations. The interval (a, b) is divided into ‘n’ sub-intervals,
each of width ‘h’. Then:
xi = x0 + ih = a + ih
yi = y(xi) = y(a + ih)
y0 = y(a)
yn = y(a + nh) = y(b)
Now, the difference equation is written for each of the interval points i = 1 to (n-1). If
the differential equation is linear, it has (n-1) unknowns y1, y2… yn-1, which can be
solved by any of the elimination methods. Smaller the size of ‘h’, more the sub-
intervals and, therefore, more are the equations to be solved. However, a smaller ‘h’
116
Prepared By
Er. Shree Krishna Khadka
Example:
Given the equation: y’’ = with y(0) = 0 and y(1) = 0. Estimate the values of
y(x) at x = 0.25, 0.5 and 0.75
Solution:
We have: h = 0.25 and
y0 = y(0) = 0
y1 = y(0.25)
y2 = y(0.5)
y3 = y(0.75)
y4 = y(1) = 0
We also have:
y1 = y(0.25) = -0.1175
y2 = y(0.5) = -0.1684
y3 = y(0.75) = -0.1391
117
Page
Prepared By
Er. Shree Krishna Khadka
SHOOTING METHOD:
In shooting method, the given boundary value problem is first converted into an
equivalent initial value problem and then solved using any of the methods discussed
in the previous chapter.
In order to solve this set as an initial value problem, we need two conditions at x = a.
We have one condition y(a) = A and, therefore, require another condition for z at x = a.
Let us assume: z(x0) = z(a) = M1(Just a guess but represent the slope y’(x) at x =a)
Thus, the problem is reduced to a system of first order equation with the initial
conditions as:
Now, with z(x0) = z(a) = M3, we can again obtain the solution of y(x).
118
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Using shooting method, solve the equation: y’’ = 6x2, with y(0) = 1 and y(1) = 2 in
the interval (0, 1) for y(0.5) taking h = 0.5
Solution:
We have given:
For x0(=x(a)) = 0, y0(=y(0)) = 1,
For xn(=x(b)) = 1, y0(=y(1)) = 2 = B and h = 0.5
Assume: y’ = z = f1(x, y, z)
Then: y’’ = z’ = 6x2 = f2(x, y, z)
Therefore:
y2 = y(1) = y1 + hf1(x1, y1, z1) = 1.75 + 0.5X1.5 = 2.50 = B1
Therefore:
y2 = y(1) = y1 + hf1(x1, y1, z1) = 1.25 + 0.5X0.5 = 1.50 = B2
M = 1 = z(0)
Prepared By
Er. Shree Krishna Khadka
Assignment 7
Full Marks: 40
Pass Marks: 20
24. Given the differential equation y’’ – xy’ – y = 0 with initial conditions
y(0) = 1 and y’(0) = 0, use Taylor’s series method to determine the
value of y(0.1). [5]
25. Use Euler’s method to solve the differential equation y’ = - y' with the
initial condition y(0) = 1 with step size 0.01 and find the value of
y(0.04). [5]
26. Solve the differential equation 10y’’ + (y’)2 + 6x = 0 with y(0) = 1 and
y’(0) = 0 by Heun’s method to estimate y(0.2) using h = 0.1
[7]
27. Use 4th order Runge Kutta method to estimate y(0.5) of the differential
equation y’ = y + _/y with y(0) = 1. Take h = 0.25. [5]
Prepared By
Er. Shree Krishna Khadka
`
Numerical Solution of
Partial Differential Equations
Contents:
o Introduction
o Finite Difference Approximation
o Solution of Elliptic Equations
o Laplace’s Equation
o Poisson’s Equation
o Solution Parabolic Equation
o Solution of Hyperbolic Equation
o Finite Difference Method
o Shooting Method
121
Page
Prepared By
Er. Shree Krishna Khadka
INTRODUCTION: PARTIAL DIFFERENTIAL EQUATION
Where u(x, y) denotes the temperature at point (x, y) and f(x, y) is the heat source.
Here, the rate of change of a variable is expressed as a function of variables and
parameters. Although most of the differential equations may be solved analytically in
their simplest form, analytical techniques fail when the models are modified to take
into account the effect of other conditions of real life situations. In all such cases,
numerical approximation of the solution may be considered as a possible approach.
If we represent the dependent variable as ‘f’ and the two independent variables as ‘x’
and ‘y’, then we will have three possible second order partial derivatives:
Then we can write a second order equation involving two independent variables in
general form as:
… (i)
Where the coefficients a, b and c may be constants or function of ‘x’ and ‘y’. Depending
on the values of these coefficients equation (i) can be classified into one of the three
types of equations, namely:
Prepared By
Er. Shree Krishna Khadka
FINITE DIFFERENCE APPROXIMATION
In finite difference method, we replace derivatives that occur in the partial differential
equation by their finite difference equivalents. We then write the difference equation
corresponding to each ‘grid point’ (where derivative is required) using functional
values at the surrounding grid points. Solving these equations simultaneously gives
the values for the function at grid point.
xi+1 = xi + h
y
yi+1 = yi + k
yj+1
k
yj
yj-1
yj-2
x
xi-2 xi-1 xi xi+1 xi+2
h
Fig: Two Dimensional Finite Difference Grid
If the function f(x) has continuous fourth derivative, then its first and second
derivatives are given by the following central difference approximations.
When ‘f’ is a function of two variables ‘x’ and ‘y’, the partial derivatives of ‘f’ with
respect to ‘x’ (or ‘y’) are the ordinary derivatives of ‘f’ with respect to ‘x’ (or ‘y’) when
‘y’ (or ‘x’) does not change. So, we can use above equation to determine derivatives
with respect to ‘x’ and in the ‘y’ direction. Thus, we have:
123
( ) ( )
Page
( )
Prepared By
Er. Shree Krishna Khadka
( ) ( )
( )
( ) ( )
( )
( ) ( )
( )
( ) ( ) ( ) ( )
( )
Laplace Equation:
The general second order partial differential equation (i), when a = 1, b = 0, c = 1 and
F(x, y, fx, fy) = 0 becomes:
… (ii) { ( )}
The operator is called the Laplacian Operator and equation (ii) is called Laplace’s
Equation. To solve the Laplace’s Equation on a region in the xy-plane, we subdivide
the region as shown in the figure below. Consider the portion of the region near (xi, yi).
We have to approximate: .
y
h f1
yj+1
f4 f5 f2
yj
k
f3
yj-1
x
xi-1 xi xi+1
Fig: Solution of Laplace’s Equation
124
Replacing the second order derivatives by their finite difference equivalents at point
Page
Example:
Consider a steel plate of size 15X15 cm. If two of the sides are held at 100oC and
the other two sides are held at 0oC. What is the steady state value of
temperature at interior knots, assuming a grid size of 5X5 cm.
5
100 100
f1 f2
100
0
5
f3 f4
100 0
0 0
Solution:
At point 1:
f2 + f3 + 100 + 100 – 4f1 = 0 f2 + f3 - 4f1 + 200 = 0 … (i)
At point 2:
f1 + f4 + 100 + 0 – 4f2 = 0 f1 - 4f2 + f4 + 100 = 0 … (ii)
At point 3:
f1 + f4 + 100 + 0 – 4f3 = 0 f1 - 4f3 + f4 + 100 = 0 … (iii)
At point 4:
f3 + 0 + 0 + f2 – 4f4 = 0 f2 + f3 - 4f4 = 0 f2 = 4f4 - f3 … (iv)
Putting the values of of f2 from equation (iv) into equations (i) and (ii), we get:
Now, solving equations (vi), (vii) and (viii) we will get: f1 = 75, f3 = 50 and f4 = 25
Putting f3 and f4 in equation (iv), we get: f2 = 50.
Page
Prepared By
Er. Shree Krishna Khadka
Poisson’s Equation
The general second order partial differential equation, when a = 1, b = 0, c = 1 and F(x,
y, fx, fy) = g(x, y) becomes:
… (iii) { ( )}
Equation (ii) is called Poisson’s Equation. Now, Laplace’s equation may be modified to
solve Poisson’s Equation. Then the finite difference formula for soving Poisson’s
Equation takes the form:
Example:
Solve the Poisson’s Equation over the square domain and
with f = 0 on the boundary and h = 1.
y
f1 f2
0
0
f3 f4
x
0
Solution:
At point 1: 0 + 0 + f2 + f3 – 4f1 = 2(1)2(2)2 f2 + f3 - 4f1 = 8 … (i)
At point 2: 0 + 0 + f1 + f4 – 4f2 = 2(2)2(2)2 f1 - 4f2 + f4 = 32 … (ii)
At point 3: 0 + 0 + f1 + f4 – 4f3 = 2(1)2(1)2 f1 - 4f3 + f4 = 2 … (iii)
At point 4: 0 + 0 + f2 + f3 – 4f4 = 2(2)2(1)2 f2 + f3 - 4f4 = 8 … (iv)
f1 = -22/4 f2 = -43/4
f3 = -13/4 f4 = -22/4
126
Page
Prepared By
Er. Shree Krishna Khadka
SOLUTION OF PARABOLIC EQUATIONS
Elliptic equations describe the problems that are time independent. Such problems
are known as steady state problems. But we come across problems that are not steady
state. This means that the function is dependent on both space and time. Parabolic
equations, for which b2 – 4ac = 0 describe the problems that depend on space and time
variables. The popular case for parabolic type equation is the study of heat flow in one
dimensional direction in an insulated rod. Such problems are governed by both
boundary and initial conditions.
f(x, t)
Insulation
Rod
f(0, t) f(L, t)
x=0 x x=L
If ‘f’ represent the temperature at any point in rod whose distance from the left end is
‘x = 0’ to ‘x = L’. Heat is flowing from left to right under the influence of temperature
gradient. The temperature f(x, t) in the rod at the position ‘x’ and time ‘t’, is governed
by the heat equation:
… (i)
Equation (i) can be written as: K.fxx(x, t) = ft(x, t) … (ii), where K = K1/(K2K3)
The initial condition will be the initial temperatures at all points along the rod i.e. f(x,
0) = f(x) for 0 x L.
The boundary conditions f(0, t) and f(L, t) describe the temperature at each end of the
rod as functions of time. If they are held constant, then:
We can solve the heat equation given by equation (ii) using finite difference formula
as below:
Page
Prepared By
Er. Shree Krishna Khadka
y
h
f1
yj+1
f4 f2
τ
f3
yj
yj-1
x
xi-1 xi xi+1
i.e. ( )
i.e.
i.e. [ ]
For, ,
i.e.
Example:
Solve the equation: 2fxx(x, t) = ft(x, t) for 0 < t < 1.5 and 0 < x < 4.
Given, f(x, 0) = 50(4 – x) for 0 < x < 4;
f(0, t) = 0 for 0 < t < 1.5;
f(4, t) = 0 for 0 < t < 1.5.
Take h = 1.
Solution:
Prepared By
Er. Shree Krishna Khadka
Now constructing the grid with h = 1 and = 0.25
t h=1
12.5 12.5 12.5
1.50
12.5 25 12.5
1.25
t\x 0.0 1.0 2.0 3.0 4.0
25 25 25 0.00 0 150 100 50 0
0.10
0.25 0 50 100 50 0
τ= 0.25 0.50 0 50 50 50 0
25 50 25
0 0.75 0
0.75 0 25 50 25 0
50 50 50 1.00 0 25 25 25 0
0.50
1.25 0 12.5 25 12.5 0
50 100 50 1.50 0 12.5 12.5 12.5 0
0.25
0 150 100 50 0
x
1 2 3 4
f =f(x, t)
x
x=0 x=L
The lateral displacement of string ‘f’ varies with time ‘t’ and distance ‘x’ along the
string. The displacement f(x, t) is governed by the wave equation:
… (i)
Where, T is the tension in the string and is the mass per unit length. Hyperbolic
problems are also governed by both boundary and initial conditions, if time is one of
129
the independent variables. Two boundary conditions for the vibrating string problem
under consideration are:
Page
Prepared By
Er. Shree Krishna Khadka
f(0, t) = 0 for 0 t b and f(L, t) = 0 for 0 t b
Now, we can solve the heat equation given by equation (ii) using finite difference
formula as below:
y
h
f1
yj+1
f4 f0
τ
yj f2
yj-1 f3
x
xi-1 xi xi+1
So, at point f0
i.e. ( ) ( )
i.e.
i.e. [ ]
For, ,
i.e.
This can be also written in coordinate form as:
130
( ) …(ii)
Page
Prepared By
Er. Shree Krishna Khadka
Starting Values
Here, we need two row of starting values, corresponding to j = 1 and j = 2 in order to
compute the values at the third row. First row is obtained using the condition: f(x, 0 )
= f(x). The second row can be obtained using the second initial condition as given by:
ft(x, 0) = g(x)
As we know: (for t = 0 only). By this, substituting the value
of fi, -1 in equation (ii) for j = 0, we will get at t = t1:
( )
As for many cases: gi = 0, therefore: ( )
Example:
Solve the wave equation: 4fxx = ftt for 0 , take h = 1.
Given: f(0, t) = 0 and f(5, t) = 0
f(x, 0) = x(5 – x)
ft(x, 0) = 0 = gi
Solution:
So, for: ,
t
h=1
-3 -5 -5 -3
2.00
τ= 0.5
-1 -2 -2 -1 t\x 0.0 1.0 2.0 3.0 4.0 5.0
1.50
0.00 0 4 6 6 4 0
1 2 2 1 0 0.50 0 3 5 5 3 0
0
1.00
1.00 0 1 2 2 1 0
3 5 5 3 1.50 0 -1 -2 -2 -1 0
0.50
2.00 0 -3 -5 -5 -3 0
0 4 6 6 4 0
x
1 2 3 4 5
131
Page
Prepared By
Er. Shree Krishna Khadka
Assignment 8
Full Marks: 30
Pass Marks: 15
Grace Mark: 4
32. Estimate the values at grid points of the following equation using
Bender Schmidt Recurrence Equation. Assume h = 1.
a) 0.5fxx – ft = 0
Given: f(0, t) = -5, f(5, t) = 5 [8]
f(x, 0) = -5, for x: [0, 2.5]
= 5, for x: [2.5, 5]
33. Solve the following wave equation using finite difference method.
4fxx = ftt
Given:
f(0, t) = 0 and f(1, t) = 0
f(x, 0) = sin( ) + sin(2 ) [8]
ft(x, 0) = 0
Prepared By
Er. Shree Krishna Khadka
`
Numerical Solution of
Integral Equations
Contents:
o Introduction
o Method of Degenerate Kernels
o Method of Generalized Quadrature
o Chebyshev Series Method
o The Cubic Spline Method
o Assignment 9
133
Page
Prepared By
Er. Shree Krishna Khadka
INTRODUCTION:
Any equation in which the unknown function appears under the integral sign is known
as an integral equation. General integral equation of first and second kind can be
represented by:
∫ … (i)
∫ …. (ii)
Here, the limits of integrals are constants; therefore it is called Fredholm Integral
Equation of first and second kinds respectively. In each case, f(x) is unknown and
occurs to the first degree but and the Kernel K(x, t) are known functions.
If the constant ‘b’ in above equations is replaced by ‘x’, the variable of integration, the
equations are called Volterra Integral Equation given by:
∫ …. (iii)
If the kernel: K(x, t) is bounded and continuous, then the integral equation is said to be
non-singular. If the range of integration is infinite, or if the kernel violates the above
conditions, then the equation is said to be singular.
To solve an integral equation of any type is to find the unknown function satisfying that
equation. In this chapter we deal with the Fredholm Integral Equation, particularly
those of the second kind since, it occurs quite frequently in practice.
134
Page
Prepared By
Er. Shree Krishna Khadka
METHOD OF DEGENERATE KERNELS
This method is important in the theory of integral equations but does not seem to be
much useful in the numerical work, since the kernel is unlikely to have the simple
form in practical problems. In general, however, it is possible to take a partial sum of
Taylor’s series for the kernel.
∫ …(i)
∑ …(ii)
∫ ∑
∑ ∫ … (iii)
Let us suppose: ∫
∑ ∫ … (iv)
Hence, the coefficients Ai are determined from equations (iv) and (iii), which will give
a system of ‘n’ equations with ‘n’ unknowns A1, A2 … An. When Ai are determined,
equation (iv) gives f(x).
135
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Solution:
Comparing the given integral equation with the original equation, we get:
∫ ( )
∫ ∫
… (ii)
∫ ∫ { }
… (iii) ∫
Again:
∫ ∫ { }
… (iv)
Prepared By
Er. Shree Krishna Khadka
METHOD OF USING GENERALIZED QUADRATURE
∫ … (i)
∫ ∑ … (ii)
Where Am and xm are the weights and abscissa, respectively. Consequently eqn (ii) can
be written as:
∑ … (iii)
Where t1, t2 … , tn are the points in which the interval (a, b) is subdivided. Further
equation (iii) must hold for all values of ‘x’ in the interval (a, b); in particular, it must
hold for x = t1, x = t2, … , x = tn. Hence we obtain:
∑ for i = 1, 2, … , n … (iv)
Which is a system of ‘n’ linear equations in the ‘n’ unknowns f(t1), f(t2) … f(tn). When
the f(ti) are determined, equation (iii) gives an approximation for f(x).
137
Page
Prepared By
Er. Shree Krishna Khadka
Example:
Solve: ∫
Solution:
Here, K(x, t) = (x + t)
The integral term can be directly approximated by the Quadrature Formula. For the
numerical solution, we divide the range [0, 1] into two equal subintervals so that h =
0.5. Let us apply composite trapezoidal rule to approximate the integral term, we
obtain:
{ ( ) } … (i)
{ ( ) }
{ ( ) }
{ ( ) }
… (a)
c) And for x = t2 = 1
… (c)
Now, using these values in equation (i), we get the solution as:
{ ( ) ( )( ) ( )}
i.e. { ( ) ( )( ) ( )}
Note: Since, the integrand is a second degree polynomial in‘t’ so, if we implement the
138
composite Simpson’s 1/3 rule, it will give the exact solution i.e. f(x) = x - 1.
Page
Prepared By
Er. Shree Krishna Khadka
CHEBYSHEV SERIES METHOD & CUBIC SPLINE METHOD
Chebyshev Series Method: The Fredholm Integral Equation can also be manipulated
by Chebyshev Series Method, which is somewhat laborious. For example the integral
equation of type:
∫ ; where
- can be solved. However, this method can give better accuracy than the trapezoidal
method but for the smaller values of d, this method is unsuitable. Because, for example
with 32 subdivisions and d = 0.0001, the value obtained for x = 0 is 0. 04782
compared to the true value of 0.50015 that means: somewhat large fluctuation in the
results.
Cubic Spline Method: In contrast with the previous methods, cubic spline method
can be applied when the values of d are small. However, for large value of d, the
convergence would rather slowly to give the exact solution.
The spline method for the numerical solution of Fredholm Integral Equations is
potentially useful. Its application to more complicated problems will have to be
examined together with estimation to error in the method. It seems probable that the
condition of continuity of the kernel may be relaxed, and the advantage to be achieved
by using unequal intervals may also be explored. Finally the solution obtained by the
spline method can be improved upon by regarding it as the initial iterate in an
iterative method of higher order convergence.
139
Page
Prepared By
Er. Shree Krishna Khadka
Assignment 9
Full Marks: 30
Pass Marks: 15
Grace Marks: 4
140
Page
Prepared By
Er. Shree Krishna Khadka
Programming
Exercises
Contents:
o Horner’s Method
o Bisection Method
o Regular Falsi Method
o Newton Raphson Method
o Secant Method
o Fixed Point Iteration
o Linear Interpolation
o Lagrange Interpolation
141
Page
Prepared By
Er. Shree Krishna Khadka
LAB 1
------------------------------------------------------------------------------------
HORNER’S METHOD OF FINDING POLYNOMIAL AT GIVE VALUE
------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,i;
float x, a[10],p;
printf("--------------------------------------------------------------\n");
printf("HORNER'S METHOD OF FINDING THE POLYNOMIAL VALUE AT GIVEN POINT\n");
printf("--------------------------------------------------------------\n\n");
printf("\nINPUT DEGREE OF POLYNOMIAL:\t");
scanf("%d", &n);
printf("\nINPUT POLYNOMIAL COEFFICENTS WITH ORDER a[%d] to a[0]:\t", n);
for(i=n; i>=0; i--)
scanf("%f", &a[i]);
printf("\nTHE POLYNOMIAL IS:\t");
for(i=n; i>=0; i--)
{
printf("%f(x^%d) ",a[i],i);
}
printf("\n\nINPUT VALUE OF 'X' (EVALUATION POINT):\t");
scanf("%f", &x);
p=a[n];
for(i=n-1; i>=0; i--)
{
p=p*x+a[i];
}
printf("\nTHE POLYNOMIAL VALUE: f(x) = %f at x = %f\t", p,x);
}
OUTPUT
142
Page
Prepared By
Er. Shree Krishna Khadka
LAB 2
-------------------------------------------------------------------------------
SOLUTION OF A GIVEN EQUATION BY BISECTION METHOD
-------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float xn,xp,xm,a,b,c,d;
int count;
begin:
printf("Enter Bracketing Values:\t");
scanf("%f%f",&xn,&xp);
a=F(xn);
b=F(xp);
if((a*b)>0)
{
printf("Entered Values Didnot Bracket The ROOT\n");
goto begin;
}
else
{
count=1;
printf("\ncount\t xn\t\t xp\t\t xm\t\t F(xm)\n");
iteration:
xm=((xn+xp)/2);
c=F(xm);
printf("\n%d\t %f\t %f\t %f\t %f\t", count, xn, xp, xm, F(xm));
if(c==0)
{
printf("\n\nROOT: %f\t", xm);
printf("\nITERATION: %d\t", count);
}
else
{
if(c<0)
143
xn=xm;
else
Page
xp=xm;
Prepared By
Er. Shree Krishna Khadka
d=fabs((xn-xp)/xn);
if(d<EPS)
{
xm=((xn+xp)/2);
printf("\n\nROOT: %f\t", xm);
printf("\nITERATION: %d\t", count);
}
else
{
count=count++;
goto iteration;
}
}
}
}
OUTPUT
144
Page
Prepared By
Er. Shree Krishna Khadka
LAB 3
-----------------------------------------------------------------------------------
SOLUTION OF GIVEN EQUATION BY REGULAR FALSI METHOD
-----------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define EPS 0.000001
#define F(x) x*log(x)-1
void main()
{
float a,b,c,d,e,fa,fb;
int count;
begin:
printf("Enter Bracketing Values:\t");
scanf("%f%f",&a,&b);
fa=F(a);
fb=F(b);
if((fa*fb)>0)
{
printf("Entered Values Didnot Bracket The ROOT\n");
goto begin;
}
else
{
count=1;
printf("\ncount\t a\t\t b\t\t c\t\t F(c)\n");
iteration:
c=((a*fb)-(b*fa))/(fb-fa);
e=F(c);
printf("\n%d\t %f\t %f\t %f\t %f\t", count, a, b, c, e);
if(e==0)
{
printf("\n\nROOT: %f\t",c);
printf("\nITERATION: %d\t", count);
printf("\nFunction Value: %f\t", F(c));
}
else
{
if(e<0)
145
a=c;
else
Page
b=c;
Prepared By
Er. Shree Krishna Khadka
d=fabs((b-a)/b);
if(d<EPS)
{
c=((a*fb)-(b*fa))/(fb-fa);
OUTPUT
146
Page
Prepared By
Er. Shree Krishna Khadka
LAB 4
----------------------------------------------------------------------------------------
SOLUTION OF GIVEN EQUATION BY NEWTON RAPHSON METHOD
----------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int count;
float x0, xn, fx,fn,fdx,e;
printf("\n");
printf("----------------------------\n");
printf("TITLE: NEWTON RAPHSON METHOD\n");
printf("----------------------------\n\n");
printf("--------------------------------------------------------------------------\n");
printf("OBJECTIVE: TO FIND THE SOLUTION OF GIVEN EQUATION BY NEWTON RAPHSON METHOD\n");
printf("--------------------------------------------------------------------------\n\n");
printf("\n\n");
count=1;
printf("Count\tx0\t\tx1\t\tError\t\tFunction Value\N");
begin:
fx=F(x0);
fdx=FD(x0);
xn=x0-(fx/fdx);
fn=F(xn);
e=fabs((xn-x0)/xn);
147
printf("\n%d\t%f\t%f\t%f\t%f",count,x0,xn,e,fn);
Page
Prepared By
Er. Shree Krishna Khadka
if(e<EPS)
{
printf("\n\n");
printf("\nRoot = %f\t", xn);
printf("\nFunction Value = %f\t", F(xn));
printf("\nIteration = %d\t", count);
}
else
{
x0=xn;
count++;
goto begin;
}
}
OUTPUT
148
Page
Prepared By
Er. Shree Krishna Khadka
LAB 5
------------------------------------------------------------------------
SOLUTION OF GIVEN EQUATION BY SECANT METHOD
------------------------------------------------------------------------
#include<stdio.h>
#include<math.h>
#include<conio.h>
#define EPS 0.000001
#define F(x) (x)*(x)+4*(x)-10
void main()
{
int count;
float x1,x2,x3,f1,f2,f3;
printf("\n");
printf("-----------------------\n");
printf("TITLE: SECANT METHOD\n");
printf("-----------------------\n\n");
printf("---------------------------------------------------------------------\n");
printf("OBJECTIVE: TO FIND THE SOLUTION OF GIVEN EQUATION BY SECANT METHOD\n");
printf("---------------------------------------------------------------------\n\n");
printf("\nInput two starting values (x1 & x2):\t");
scanf("%f%f", &x1, &x2);
f1=F(x1);
f2=F(x2);
count=1;
printf("\nCount\t\tx1\t\tx2\t\tx3\t\tf(x3)\n");
begin:
x3=(f2*x1-f1*x2)/(f2-f1);
f3=F(x3);
printf("\n%d\t\t%f\t%f\t%f\t%f",count,x1,x2,x3,f3);
if(fabs((x3-x2)/x3)<EPS)
{
printf("\n\nRoot = %f\t", x3);
printf("\nFunction Value at %f\t = %f\t", x3, F(x3));
printf("\nNo of Iteration = %d\t", count);
}
else
{
x1=x2;
149
f1=f2;
x2=x3;
Page
f2=F(x3);
Prepared By
Er. Shree Krishna Khadka
count++;
goto begin;
}
}
OUTPUT
150
Page
Prepared By
Er. Shree Krishna Khadka
LAB 6
-----------------------------------------------------------------------------------------------
SOLUTION OF GIVEN EQUATION BY FIXED POINT ITERATION METHOD
-----------------------------------------------------------------------------------------------
#include<stdio.h>
#include<math.h>
#include<conio.h>
#define EPS 0.000001
//#define G(x) pow(x,2)-5 //#define G(x) 5/x //#define G(x) pow(x,2)+x-5
#define G(x) (pow(x,2)+5)/(2*(x))
void main()
{
int count;
float x0, x, e, f;
printf("\n");
printf("-----------------------------------\n");
printf("TITLE: FIXED POINT ITERATION METHOD\n");
printf("-----------------------------------\n\n");
printf("-------------------------------------------------------------------------------\n");
printf("OBJECTIVE: TO FIND THE SOLUTION OF GIVEN EQUATION BY FIXED PNT ITERATION METHOD\n");
printf("-------------------------------------------------------------------------------\n\n");
printf("\nInput Initial Estimate(x0):\t");
scanf("%f", &x0);
count=1;
printf("\nitn\tx0\t\tx1\t\tError\t\tF(x)");
printf("\n");
iteration:
x=G(x0);
e=fabs((x-x0)/x);
f=G(x);
printf("\n%d\t%f\t%f\t%f\t%f",count,x0,x,e,f);
if(e>EPS)
{
x0=x;
count = count++;
goto iteration;
}
151
else
{
Page
Prepared By
Er. Shree Krishna Khadka
printf("\nFunction value: %f\t", G(x));
printf("\nIteration: %d\t", count);
}
}
OUTPUT
152
Page
Prepared By
Er. Shree Krishna Khadka
LAB 7
-----------------------------------------------------
LINEAR INTERPOLATION TECHNIQUES
-----------------------------------------------------
#include<stdio.h>
#include<math.h>
#include<conio.h>
#define F(x) sqrt(x)
void main()
{
float x1, x2, fx1, fx2, fx, f, x, e;
printf("\n-------------------------------------\n");
printf("TITLE: LINEAR INTERPOLATION TECHNIQUE\n");
printf("-------------------------------------\n\n");
printf("-------------------------------------------------------------------------------\n");
printf("OBJECTIVE: TO FIND THE FUNCTIONAL VALUE AT GIVEN PNT USING LINEAR INTERPOLATION\n");
printf("-------------------------------------------------------------------------------\n\n");
printf("\nFunction F(x): sqrt(x)\n");
printf("\nAt Which Point You Want To Evaluate Function (x):\t");
scanf("%f", &x);
x1 = x-1; x2 = x+1;
fx1 = F(x1); fx2 = F(x2);
f = fx1 + (x-x1)*(fx2-fx1)/(x2-x1);
fx = F(x); e = fabs(f-fx);
printf("\nInterpolating Points (x1, x2):(%f, %f)", x1, x2);
printf("\nEvaluation Point (x):%f", x);
printf("\nFunctional Value F(x):%f", f);
printf("\nError From Exact value (Error):%f", e);
}
OUTPUT
153
Page
Prepared By
Er. Shree Krishna Khadka
LAB 8
--------------------------------------------------------
LAGRANGE INTERPOLATION TECHNIQUE
--------------------------------------------------------
#include<stdio.h>
#include<math.h>
#include<conio.h>
#define F(x) sqrt(x)
void main()
{
int n, i, j;
float x[10], y[10], lbp, lp, xp, sum;
printf("\n-----------------------------------------\n");
printf("TITLE: LAGRANGE'S INTERPOLATION TECHNIQUE\n");
printf("-----------------------------------------\n\n");
printf("-------------------------------------------------------------------------------\n");
printf("OBJECTIVE: TO FIND THE FUNCNL VALUE AT GIVEN PNT USING LAGRANGE INTERPOLATION\n");
printf("-------------------------------------------------------------------------------\n\n");
printf("\nEnter The Number Of Data Points (n):\t");
scanf("%d", &n);
printf("\nEnter Data Points & Values (x[i], y[i]):\t");
for(i=1; i<=n; i++)
scanf("%f%f", &x[i], &y[i]);
printf("\nAt Which Point You Want To Evaluate Function (xp):\t");
scanf("%f", &xp);
sum = 0;
for(i=1; i<=n; i++)
{
lbp = 1;
for(j=1; j<=n; j++)
{
if(i!=j)
lbp = lbp*(xp-x[j])/(x[i]-x[j]);
}
sum = sum + lbp*y[i];
}
lp = sum;
printf("\n--------------------");
printf("\nInterpolating Points\n");
printf("--------------------\n");
printf("\nx[i]\t\ty[i]\n");
for(i=1; i<=n; i++)
154
}
Prepared By
Er. Shree Krishna Khadka
OUTPUT
155
Page
Prepared By
Er. Shree Krishna Khadka