0% found this document useful (0 votes)
212 views68 pages

Eee404 - Eee302 - Lab Sheet Gub

This document contains the laboratory manual for the Numerical Analysis course at Green University of Bangladesh. It includes 10 experiments covering topics like MATLAB introduction, root finding methods, solving non-linear equations, interpolation, numerical differentiation, and solving systems of linear equations. The laboratory instructions, syllabus, and contents listing are provided along with brief descriptions and objectives of each experiment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views68 pages

Eee404 - Eee302 - Lab Sheet Gub

This document contains the laboratory manual for the Numerical Analysis course at Green University of Bangladesh. It includes 10 experiments covering topics like MATLAB introduction, root finding methods, solving non-linear equations, interpolation, numerical differentiation, and solving systems of linear equations. The laboratory instructions, syllabus, and contents listing are provided along with brief descriptions and objectives of each experiment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

Page |1

Green University of Bangladesh


Department of Electrical and Electronic Engineering

EEE-404/EEE-302
Numerical Analysis Laboratory Manual

Student ID
Student Name
Section
Name of the Program
Name of the Department
Page |2

CONTENTS Page
No
Instructions for Laboratory 3

Laboratory Course Syllabus 4

Experiment -1 Introduction to MATLAB (Part-A) 8

Experiment- 2 Introduction to MATLAB (Part-B) 11

Experiment- 3 Iterative Processes For Root Finding 15


(Iterative Method, Aitken’s ∆² Acceleration Method, Bisection
Method)
Experiment- 4 Solutions to Non-Linear Equations 19
(Secant Method & Regula Falsi Method)
Experiment -5 Interpolation by Newton-Gregory forward difference formula

Experiment- 6 Interpolation by Newton-Gregory backward difference formula 23

Experiment- 7 Numerical Differentiation


(Based on Newton-Gregory Forward & Backward Differences)
Experiment -8 Numerical Differentiation (Based on Lagrange Interpolation) & 27
Numerical Integration (Based on Simple Trapezium Rule)
Experiment -9 Numerical Integration By Simpson's 1/3, 3/8th Rule & Romberg 30
Integration
Experiment- 10 Solution of system of Linear Equations By
A direct method (LU Decomposition),
An indirect method (Jacobi or Gauss Seidel Method)
Page |3

INSTRUCTIONS FOR LABORATORY

The experiments are designed to illustrate about different arenas control system,
communication, solid-state design, robotics, mechatronics, Aeronautics etc. Conduct the
experiments with interest and an attitude of learning.

Students should come with thorough preparation for the experiment to be conducted.

Students should come with proper dress code.

Students will not be permitted to attend the laboratory unless they bring the practical record
fully completed in all respects pertaining to the experiment conducted in the previous class.

Work quietly and carefully (the whole purpose of experimentation is to develop logic for
MATLAB programming!) and equally share the work with your partners.

Be honest in developing and representing your program. If a particular MATLAB output


appears wrong repeat the program carefully.

All presentations of programs, outputs and graphs calculations should be neatly and carefully
done.

Graphs should be carefully drawn by MATLAB program. Always label graphs and the axes
and display units in the program.

If you finish early, spend the remaining time to complete the laboratory report writing. Come
equipped with calculator, scales, pencils etc.

Handle instruments with care. Report any breakage or faulty equipment to the Instructor.
Shutdown your computer you have used for the purpose of your experiment before leaving
the Laboratory.
Page |4

GREEN UNIVERSITY OF BANGLADESH (GUB)


COURSE SYLLABUS

1 Faculty Faculty of Science & Engineering

2 Department Department of EEE

3 Programme BSEEE [B.Sc. in Electrical & Electronic Engineering]

4 Name of Numerical Technique Laboratory


Course
5 Course Code EEE 404/EEE 302
6 Trimester and Fall, 2020

Year
7 Pre-requisites EEE 301, EEE 406, Math 101, Math 301

8 Status Core EEE Course

9 Credit Hours 1.5

10 Section Day

11 Class Hours Monday, 8:30-03:00 PM; Tuesday, 8:30-03:00 PM

12 Class Location Room: B-908 (Simulation Lab.)

13 Course website
14 Name (s) Shahriar Mahmud Kabir
of
Academi
c staff /
Instructo
r(s)
15 Contact [email protected]

16 Office Room # 507, Building-B


17 Counselling Monday 3:00-4:00 PM, Tuesday 3:00-4:00 PM
Hours
18 Text Book Steven C. Chapra & Raymond P. Canale, Numerical Methods for Engineers,
Sixth Edition
•Applied Numerical Methods with MATLAB (for Engineers & Scientists)
19 Reference (Special Indian Edition),
Steven C. Chapra
•Numerical Methods,
S. Balachandra Rao, C.K.Shantha

20 Equipment & Bring your notebook and calculator. Equipment will be provided in the
Aids laboratory and MATLAB R2020a software is installed in the respective
laboratory computers. Do collect the software named ‘MATLAB R2020a´
for home practice.
Page |5

EEE 404 is one of the fundamental courses for EEE students. It aims to give
students the practical idea about statistical problem solving such as pdf, cdf
21 Course and how to analyse them. It is a pre-requisite for many other courses in
Rationale EEE.

Numerical Technique Lab. is an attractive course for the arenas control


system, communication, solid-state design, robotics, mechatronics,
22 Course Aeronautics etc. Its applications are quite widely seen. This course will
discuss in advance level about the fundamental and primitive ideas of control
Description system, signals, systems and a brief application about them in Digital domain.

The course is designed to provide the background of the following topics

1. Explain basic features configurations and applications of some


signals in digital domain.
23 Course 2. Familiar with the practical implementation of digital signals.
Objectives 3. Explain different digital systems and their properties.
4. Explain a system through difference equation in digital domain.
5. Manipulate frequency response of a system in digital domain.
6. Justify the system transfer function through different
transformation techniques in digital domain.
7. Recognize the applications of Time and Frequency domain analysis
and advanced signal processing aspects

After the end of this course, the students will be able to:
1. Explain different signals and systems in digital domain.
2. Explain features, configurations of various systems in digital
24 Learning domain.
Outcomes 3. Utilize system properties through Time-domain analysis and
Frequency-domain analysis in digital domain.
4. Measure system transfer function from the different
transformations analysis in digital domain.
5. Explain the applications of different transformations analysis in
digital domain.
6. Recognize these concepts on courses like Advanced Numerical
Methods, Control Systems, communication theory etc.

25 Teaching Lecture, Laboratory hardware and software experiments, Project


Methods Developments.
Page |6

26 Topic Outline
Class Topics Or CLOs Reading Activities
Reference
1 Assignments
Introduction to MATLAB (Part- Laboratory
A) 1,2,4 Experiment

2 Introduction to MATLAB (Part-B) Laboratory


3 Experiment
3 Iterative Processes For Root Laboratory
Finding (Iterative Method, 1,2,3,4 Experiment
Aitken’s ∆² Acceleration
Method, Bisection Method)
4 Solutions to Non-Linear Equations Laboratory
(Secant Method & Regula Falsi 1,2,3,4
Experiment
Method)
5 Interpolation by Newton- Laboratory
Gregory forward difference 1,2,3,4 Experiment
formula
6 Interpolation by Newton-Gregory 1,2,3,4 Laboratory
backward difference formula Experiment
7 MID TERM EXAMINATION Quiz, Lab
test, Viva

8 Numerical Differentiation Laboratory


Experiment
(Based on Newton-Gregory Forward
& Backward Differences) 1,2,3,4

9 Numerical Differentiation (Based Laboratory


on Lagrange Interpolation) & 1,2,3,4 Experiment
Numerical Integration (Based on
Simple Trapezium Rule)

10 Numerical Integration By Laboratory


Simpson's 1/3, 3/8th Rule & Experiment
Romberg Integration 1,2,3,4

11 Solution of system of Linear Laboratory


Equations By a direct method Experiment
(LU Decomposition) & an 1,2,3,4
indirect method (Jacobi or
Gauss Seidel Method)
12 FINAL TERM Quiz, Lab
EXAMINATION (Written Lab test, Viva
Exam, Viva, Performance Test)

13 Presentation
1,2,3,4
Project presentation and Report
Submission
Page |7

Assessment Types Marks


Attendance 10%
Lab Report 10%
27 Assessment Continuous Lab Performance 25%
Methods
VIVA 25%
Final Exam 30%
Total 100%

Letter Grade Marks % Grade Point Letter Grade Marks% Grade Point
A+ (Plus) 80-100 4.00 C+ (Plus) 50-54 2.50
Grading Policy A (Plain) 75-79 3.75 C (Plain) 45-49 2.25
28 A- (Minus) 70-74 3.50 D (Plain) 40-44 2.00
B+ (Plus) 65-69 3.25 F (Fail) <40 0.00
B (Plain) 60-64 3.00 I* - Incomplete
B- (Minus) 55-59 2.75 W* - Withdrawal

1. Lab Reports: Report on previous Experiment must be submitted


29 Additional before the beginning of new experiment. A bonus may be obtained if a
Course Policies student submits a neat, clean and complete lab report.

2. Examination: There will be a mid-term exam and final exam both of


which will be closed book.

3. Unfair means policy: In case of copying/plagiarism in any of the


assessments, the students involved will receive zero marks. Zero
Tolerance will be shown in this regard. In case of severe offences,
actions will be taken as per university rule.

4. Counseling: Students are expected to follow the counseling hours


posted. In case of emergency/unavoidable situations, students can e-mail
me to make an appointment. Students are regularly advised to check the
eLMS course page for updates/materials.

5. Policy for Absence in Class/Exam: If a student is absent in the class


for anything other than medical reasons, he/she will not receive
attendance. If a student misses a class for genuine medical reasons,
he/she must submit an application with the supporting documents
(prescription/medical report). He/she will then have to follow the
instructions given by the instructor for make-up. In case of absence in
the mid/final exam for medical grounds, the student must also get his/her
application forwarded by the head of the department before a make-up
exam can be taken.

It is recommended that the students inform the instructor beforehand


through mail if they feel that they will miss a class/evaluation due to
medical reasons.
Page |8

1. Academic Calendar Fall 2020:


http://www.green.edu.bd/academics/academic-calendar
2. Academic Information and Policies:
30 http://www.green.edu.bd/academics/academic-rules-a-regulations
Additional Info. 3. Grading and Performance Evaluation:
http://www.green.edu.bd/academics/academic-rules-a-regulations
4. Proctorial Rules: http://www.green.edu.bd/administrator/proctors-
office
Page |9

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 10

Experiment No. 1:
Name of the Experiment: Introduction to MATLAB (Part A)

Objectives:
1. Explain basic features configurations and applications of some signals in digital
domain.
2. Familiar with the practical implementation of digital signals.
3. Explain different digital systems and their properties.
4. Explain a system through difference equation in digital domain.
5. Manipulate frequency response of a system in digital domain.
6. Justify the system transfer function through different transformation techniques in
digital domain.
7. Recognize the applications of Time and Frequency domain analysis and advanced
signal processing aspects

Learning Outcome: After completing this experiment the students will be able to:
1. Explain different signals and systems in digital domain.
2. Explain features, configurations of various systems in digital domain.
3. Utilize system properties through Time-domain analysis and Frequency-domain
analysis in digital domain.
4. Measure system transfer function from the different transformations analysis in digital
domain.
5. Explain the applications of different transformations analysis in digital domain.
6. Recognize these concepts on courses like Advanced Numerical Methods, Control
Systems, communication theory etc.

Theory:
Starting MATLAB:
• You can start MATLAB R2020a on Microsoft Windows Platform (Win7/Win10) by
double clicking the MATLAB shortcut icon on your windows desktop or simply click
MATLAB R2020a from the start menu.
• As an alternative method, click on the Start button then type matlab in the ‘search
field’ then press Enter. MATLAB will start immediately.
• After MATLAB starts, you can change the directory in which MATLAB saves your
MATLAB files. To do this, click on ‘…’ button then select the new location.

Desktop Tools:
1) The Command Window: To enter variables, execute commands and to run M-files.
2) Menus:
▪ File: from the file menu, you can create a new M-file, figure…etc. You can also
open any file and you can access the preferences of MATLAB.
▪ Edit: cut, copy, paste...etc.
▪ Desktop: to control the desktop of MATLAB.
Tip: to restore the default desktop go to Desktop →Desktop Layout→default
▪ Window: to get access to the windows/files e.g. the open M-files documents.
3) The Current Directory Browser: any files you want to run must either be in the
current directory or on search path. The current directory browser enables you to
browse all the files saved in the current directory. You can run, rename, delete…etc.
4) Command History: in the command history you can view the previously used
functions and copy and execute selected lines.
P a g e | 11

5) Lunch Pad: provides easy access to tools, demos, and documentations.


6) Help Browser: to search and view documentations for all your MathWorks products.
7) Workspace Browser: the MATLAB workspace consists of the set of variables
(named arrays) built up during a MATLAB session and stored in memory. To
view the workspace and information about each variable, use the Workspace
Browser, or use the commands who and whos.
8) Array Editor: double click on a variable in the Workspace Browser to see it in the
Array Editor.
9) Editor/Debugger: to create and debug M-files.

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a

Procedure:

First Steps in MATLAB:


When MATLAB starts, the special >> prompt (the command line) appears, MATLAB is
ready to receive your commands. Try to compute c=a+b, where a=10, and b=20.

MATLAB Command:
>> a=10; b=20; c=a+b

Try The Followings:

>> x=[1:10]
>> x=[1:1:10]
>> x=[1:2:10] %[start:step:stop]
>> y=linspace(0,10,5) %linspace(start,stop,no.of data)
>> t=2*pi*50 % t=2πf
>> sin(30*pi/180) % sin(300)
>> asin(1/2)*180/pi %sin-1(1/2)
>> 10*exp(-2) % 10e-2
>> 9e-5 %9x10-5
>> date
>> calendar
>> (log10(10))^4 %(log10(10))4
>> (log2(5))^4 %(log2(5))4
>> (log(10))^4 %(loge(10))4
>> x=0:2:16; y=2*x;
>> t=linspace(0,2*pi,100);
>> x=sin(t);
>> y=cos(t);
>> plot(x)
>> plot(y)
>> plot(x,y)
>> subplot(3,1,1)
>> plot(x)
P a g e | 12

>> subplot(3,1,2)
>> plot(y)
>> subplot(3,1,3)
>> plot(x,y)
>> plot(x,'-r')
>> hold on
>> plot(y,'-.b')
>> hold on
>> plot(x,y,':k')
>> legend('Sin','Cos','Circle',0)

Report Question:

Solve the followings by MATLAB,

A. sin(2250) + cot(300) + tan-1(1/2) + 10e-10 + 9x10-2 + (log1010)3 + (loge10)5


Ans: 93.4064

B. Think about A and B are the last two digits of your Class Roll:

sin(AB0) + cot(BA0) + tan-1(B/A) + Be-BA + Ax10-A + (log10B)AB + (logeBA)A

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 13

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 14

Experiment No. 2:
Name of the Experiment: Introduction to MATLAB (Part B)

Objectives:
1. Explain basic features configurations and applications of some signals in digital
domain.
2. Familiar with the practical implementation of digital signals.
3. Explain different digital systems and their properties.
4. Explain a system through difference equation in digital domain.
5. Manipulate frequency response of a system in digital domain.
6. Justify the system transfer function through different transformation techniques in
digital domain.
7. Recognize the applications of Time and Frequency domain analysis and advanced
signal processing aspects

Learning Outcome: After completing this experiment the students will be able to:
1. Explain different signals and systems in digital domain.
2. Explain features, configurations of various systems in digital domain.
3. Utilize system properties through Time-domain analysis and Frequency-domain
analysis in digital domain.
4. Measure system transfer function from the different transformations analysis in digital
domain.
5. Explain the applications of different transformations analysis in digital domain.
6. Recognize these concepts on courses like Advanced Numerical Methods, Control
Systems, communication theory etc.

Theory:

−File:

M-files provide an easy way to write and excite your commands and programs. For a large
number of commands and complex problem-solving M-files is a must. It allows you to place
P a g e | 15

MATLAB command in a simple text file and then tell MATLAB to open the file and execute
the commands exactly as it would if you typed them at the MATLAB Command Window.

M-Files must end with the extension ‘.m’. For example, homework1.m

There are many ways to load M-file Editor:


1. -Click on start  programs  MATLAB  R2020a  M-file Editor
2-From the MATLAB, chose New from the Home tab and select Script.

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a

Procedure:

Matrix Operations:
To type a matrix into MATLAB you must:
▪ Begin with a square bracket [.
▪ Separate elements in a row with commas or spaces.
▪ Use a semicolon (;) to separate rows
▪ End the matrix with another square bracket].

Example-1:

a=[1,-2,0;10,-6,2;1,11,-9] or a=[1 -2 0; 10 -6 2; 1 11 -9]

Addition, Subtraction, Multiplication and Division:

Example-2:
A=[1 10 200 ; -50 0 -20 ; 44 25 60 ];
B=[1 15 -32 ; 14 20 20 ; 2 5 3];
C=[1 1 1 ; 25 -6 -6; 14 89 300];
A+B+C
A+B-C
A+B-C-10
A/C
A*B*C
2*A
A^2 % A*A
A.^2 % element wise square

Matrix Generator:

Example-3:
zeros(3,3)
ones(3,2)
rand(3,3)
P a g e | 16

Row Index and Column Index:

Example-4:
B=[0 20 90; 12 -34 45]
B(2,3)
B(1,2)
B(2,2)

Transpose, Determinant & Inverse of a Matrix:

Example-5:
W=[1 2 3; -4 -5 -6; 0 1 0]
W' %Transpose
det(W) %Determinant
inv(W) %Inverse

Control Statement

For Loop

Execute statements specified number of times

For index = expression


Statement group x
End

Where: expression is a matrix, usually the expression is something like m:n or m:i:n
where m is the beginning value, n the ending value and i is the increment.

Example-6:
The following statements will find the squares of all integers starting from
1 to10 with increment i = 2, the code would be

for i = 1:2:10
x = i^2
end

The output of this code: x = 1, 9,25,49,81.

Nested For Loop

Example-7:
m=3;
n=5;
for i=1:m
for j=1:n
f(i,j)=i;
P a g e | 17

end
end
f

The output of this code: f = 1 1 1 1 1


2 2 2 2 2
3 3 3 3 3

While Loop
Repeatedly execute statements while condition is true

Example-8:
i=1
d=0
while i<5 % i>1
d=i+1
i=d
end
disp('loop ended')
d
i

The output of this code: d=5, i = 5

Relation Operators with IF Else Statement:


MATLAB has six relational operators to make logical operations; these operators are
shown in the following table

Rational operator description

< Less than.


<= Less than or equal.
> Greater than.
>= Greater than or equal to.
== Equal to.
~= Not equal to.

Example-9:
a=5;
b=6;
if a~=b
disp('unequal')
else
disp('equal')
P a g e | 18

end

Logical Operators with IF Else Statement:


Symbol Meaning
& AND
| OR
˜ NOT

Example-10:
x=4; y=6;
if x<1 & y<1
z=0
elseif x>1 & y<1
z=1
elseif x>1 | y<1
z=2
end

The output of this code: z = 2

Solving a set of Linear Equations:

If a system of n linear equations in n unknowns can be expressed in form


Ax = b
Where A is an n x n matrix, and b is a column vector then, the solution to this system of
equations can be expressed as
x = A-1 b

Where A-1 is the matrix inverse of A. In MATLAB, this system of equations can be
accomplished by the left division (\).

Example-11:
Consider the following system of equations

3x+10y-z=0
-2x+y-10z=-2
x+y-z=3
This system of equations can be solved in MATLAB with the following code:

A=[3 10 -1;-2 1 -10; 1 1 -1];


b=[0;-2;3];
x=inv(A)*b
x=A\b
or

syms x y z
[x,y,z]=solve([3*x+10*y-z==0,-2*x+y-10*z==-2,x+y-z==3],[x,y,z])

The output of this code: x = 3.5000, -1.1111, -0.6111


P a g e | 19

Report Question:

A. Try the following commands for the matrix ‘W’

10 − 12 30
𝑊 = [55 95 200 ]
−70 5 2

A=W(3,2)
B=W(1,1)
C=W(3,3)
D=W(2,2)
E=A+B
𝐹 = √𝑙𝑛|𝐶 − 𝐷| + sin(𝐵)

Ans: A =5, B =10, C =2, D =95, E =15, F =1.5850

B. Solve the following system of equations:

17x1+2x2+1x3+5x4=4
5x1+6x2+7x3+1x4=-1
9x1-10x2+11x3+12x4=10
13x1+14x2+15x3-9x4 = 6

Ans: x1 = 0.5353, x2 = -0.9497, x3 = 0.3914, x4 = -0.7184

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 20

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 21

Experiment No. 3:
Name of the Experiment: Iterative Processes for Root Finding (Iterative
Method, Aitken’s ∆² Acceleration Method, Bisection Method)

Objectives:
1. Explain basic features configurations and applications of some signals in digital
domain.
2. Familiar with the practical implementation of Iterative Method.
3. Familiar with the practical implementation of Aitken’s ∆² Acceleration Method.
4. Familiar with the practical implementation of Bisection Method.
5. Explain different digital systems and their properties.
6. Explain a system through difference equation in digital domain.
7. Manipulate frequency response of a system in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Middle Term Breaking Method
2. Define Fixed Point Iteration to Root Finding
3. Define Iterative Process to Locate the System Root.
4. Define Aitken’s ∆² Acceleration Method to Locate the System Root.
5. Define Bisection Process to Locate the System Root.

Theory:

Iterative Process

At first we have to introduce with MATLAB function declaration & function handler.

Example-1:

A formula can be developed for simple fixed-point iteration by arranging the function 𝑓(𝑥) =
0 so that 𝑥 is on the left hand side of the equation:
𝑥 = 𝑔(𝑥) (1)
Eq. (1) can be used to compute a new estimate 𝑥𝑖+1 as expressed by the iterative formula
𝑥𝑖+1 = 𝑔(𝑥𝑖 ) (2)
The approximate error for this eq. (2) can be determined using the error estimator:
𝑥𝑖+1 −𝑥𝑖
|e𝑎 | = | | 100%
𝑥𝑖+1
P a g e | 22

Aitken's Method for Acceleration (Δ2Method):


According to the theory class

(∆𝑥𝑛 )2
𝐴𝑖𝑡𝑘𝑒𝑛, 𝛼 = 𝑥𝑛+1 −
∆2 𝑥𝑛−1

Here,
∆𝑥𝑛 = 𝑥𝑛+1 − 𝑥𝑛

∆2 𝑥𝑛−1 = 𝑥𝑛+1 − 2𝑥𝑛 + 𝑥𝑛−1

Bisection method:

The Bisection method is one of the simplest procedures for finding root of a function in a
given interval. The procedure is straightforward. The approximate location of the root is first
determined by finding two values that bracket the root (a root is bracketed or enclosed if the
function changes sign at the endpoints). Based on these a third value is calculated which is
closer to the root than the original two value. A check is made to see if the new value is a
root. Otherwise a new pair of bracket is generated from the three values, and the procedure is
repeated.

Fig. 1: Bisection Method

Consider a function d ( x) and let there be two values of x , xlow and xup ( xup > xlow ),
bracketing a root of d ( x) . The first step is to use the brackets xlow and xup to generate a third
value that is closer to the root. This new point is calculated as the mid-point between xlow
xlow + xup
and, namely xmid = . The method therefore gets its name from this bisecting of two
2
values. It is also known as interval halving method. Test whether xmid is a root of d ( x) by
evaluating the function at xmid . If xmid is not a root, then check if d ( xlow ) and d ( xmid ) have
opposite signs i.e. d ( xlow ) . d ( xmid ) <0, root is in left half of interval. Or if d ( xlow ) and d ( xmid )
have same signs i.e. d ( xlow ) . d ( xmid ) >0, root is in right half of interval. Continue subdividing
𝑥𝑢𝑝 −𝑥𝑙𝑜𝑤
until interval width ( ) has been reduced to a size < tolerance. Tips: tolerance shall be
2
1x10-4
P a g e | 23

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a

Procedure:

Iterative Process Steps:

1. The first step choice an initial approximation 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = 𝑥𝑜𝑙𝑑


2. Evaluate 𝑓(𝑥) equation and determine the value of 𝑓(𝑥𝑜𝑙𝑑 )
3. Let 𝑥𝑛𝑒𝑤 = 𝑓(𝑥𝑜𝑙𝑑 )
𝑥 −𝑥
4. Check %𝑒𝑟𝑟𝑜𝑟 = | 𝑛𝑒𝑤 𝑜𝑙𝑑 | ∗ 100%
𝑥𝑛𝑒𝑤
5. If %𝑒𝑟𝑟𝑜𝑟 > 1% , then put 𝑥𝑜𝑙𝑑 = 𝑥𝑛𝑒𝑤 and repeat steps (2) to (4)
6. Continue evaluating steps (2) to (4) until %𝑒𝑟𝑟𝑜𝑟 has been reduced to a value  1
7. If %𝑒𝑟𝑟𝑜𝑟 < 1% , then 𝑅𝑜𝑜𝑡 = 𝑥𝑛𝑒𝑤 and stop evaluating iterations.

Example: Use simple fixed-point iteration to locate the root of 𝑓(𝑥) = cos(𝑥) ;
Solution: The function can be separated directly and expressed in the form of eq. (2) as
𝑥𝑖+1 = cos(𝑥𝑖 )
Example_Ans:
𝒊𝒕𝒆𝒓𝒂𝒕𝒊𝒐𝒏 𝒙𝒏𝒆𝒘 %𝒆𝒓𝒓𝒐𝒓
0 0.000000000000000
1 1.000000000000000 100
2 0.540302305868140 85.081571768092545
3 0.857553215846393 36.994894790888438
4 0.654289790497779 31.066268846098438
5 0.793480358742566 17.541778660452646
6 0.701368773622757 13.133117495954123
7 0.763959682900654 8.192959743667133
8 0.722102425026708 5.796581817655344
9 0.750417761763761 3.773276457436351
10 0.731404042422510 2.599619121364808
. . .
. . .
. . .
42 0.739085108473799 8.317141693569484e-06
Thus, each iteration brings the estimate to the true value of the root: 0.739085108473799
On the 42th iteration.

Aitken's Method for Acceleration (Δ2Method) Steps:

1. The first step choice an initial approximation 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = 𝑥1


2. Evaluate 𝑓(𝑥) equation and determine the values 𝑥2 = 𝑓(𝑥1 ) , 𝑥3 = 𝑓(𝑥2 )
3. Determine the value of ∆𝑥2 = 𝑥3 − 𝑥2
4. Determine the value of ∆2 𝑥1 = 𝑥3 − 2𝑥2 + 𝑥1
(∆𝑥2 )2
5. Determine the value of 𝐴𝑖𝑡𝑘𝑒𝑛, 𝑎 = 𝑥3 −
∆ 2 𝑥1
6. Check accuracy = |𝑎 − 𝑥3 |
P a g e | 24

7. If 𝑎𝑐𝑐𝑢𝑟𝑎𝑐𝑦 > 1 , then put 𝑥1 = 𝑎 and repeat steps (2) to (6)


8. Continue evaluating steps (2) to (6) until accuracy has been reduced to a value < 1
9. If 𝑎𝑐𝑐𝑢𝑟𝑎𝑐𝑦 < 1 , then Aitken’s 𝑅𝑜𝑜𝑡 = 𝑎 and stop evaluating iterations.

Example_Ans:
𝒊𝒕𝒆𝒓𝒂𝒕𝒊𝒐𝒏 𝒙𝒏𝒆𝒘 𝑨𝒊𝒕𝒌𝒆𝒏′ 𝒔 𝑹𝒐𝒐𝒕 (𝒂)
0 0.000000000000000
1 1.000000000000000 0.685073357326045
2 0.540302305868140 0.738660156167714
3 0.857553215846393 0.739085106356719
4 0.654289790497779 0.739085133215161
5 0.793480358742566
6 0.701368773622757
7 0.763959682900654
8 0.722102425026708
9 0.750417761763761
10 0.731404042422510
. .
. .
. .
42 0.739085108473799
Thus, Aitken’s Acceleration Process brings the estimate closer to the true value of the
root: 0.739085133215161 on the 4th iteration

Bisection method Steps:

1. The first step choice the initial approximations 𝑥𝑢𝑝 and 𝑥𝑙𝑜𝑤
𝑥 +𝑥
2. Determine the value of 𝑥𝑚𝑖𝑑𝑜𝑙𝑑 = 𝑢𝑝 𝑙𝑜𝑤
2
3. Determine the values 𝑓(𝑥𝑙𝑜𝑤 ) & 𝑓(𝑥𝑚𝑖𝑑𝑜𝑙𝑑 )
4. Check if 𝑓(𝑥𝑙𝑜𝑤 ) ∗ 𝑓(𝑥𝑚𝑖𝑑𝑜𝑙𝑑 ) > 0 then change 𝑥𝑙𝑜𝑤 = 𝑥𝑚𝑖𝑑𝑜𝑙𝑑
OR if 𝑓(𝑥𝑙𝑜𝑤 ) ∗ 𝑓(𝑥𝑚𝑖𝑑𝑜𝑙𝑑 ) < 0 then change 𝑥𝑢𝑝 = 𝑥𝑚𝑖𝑑𝑜𝑙𝑑
𝑥𝑢𝑝 + 𝑥𝑙𝑜𝑤
5. Determine the value of 𝑥𝑚𝑖𝑑𝑛𝑒𝑤 =
2
𝑥 −𝑥
6. Check 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 = 𝑢𝑝 𝑙𝑜𝑤
2
7. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 > 1 then change 𝑥𝑚𝑖𝑑𝑜𝑙𝑑 = 𝑥𝑚𝑖𝑑𝑛𝑒𝑤 and repeat steps (2) to (6)
8. Continue evaluating steps (2) to (6) until difference has been reduced to a value < 1
9. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 < 1 then 𝑅𝑜𝑜𝑡 = 𝑥𝑚𝑖𝑑𝑛𝑒𝑤 and stop evaluating iterations.

Bisection Fig 1_Ans: -0.754821777343750

Report Question:

1. Write MATLAB Program of Iterative and Aitken’s Δ2 Method for the following systems:
a) 2𝑥 − 𝑙𝑜𝑔10 (𝑥) − 7 = 0; 𝑥0 = 0.34
1/3
b) 𝑥 = −(1 − 𝑥) ; 𝑥0 = −1.2
c) 2𝑥 2 + 3𝑥 − 1 = 0 ; 𝑥0 = 0.29
1
d) 𝑥 = ( ) [(2𝑥 2 − 1)/(𝑥 − 1)] ; 𝑥0 = 0.4
4
e) 𝑥 − 𝑒 −𝑥 = 0 ; 𝑥0 = 0.56
P a g e | 25

2. Write MATLAB Program of Bisection Method for the following systems:


a) 𝑥 5 + 𝑥 + 1 = 0; 𝑥𝑢𝑝 = 5, 𝑥𝑙𝑜𝑤 = −5
b) 3𝑥 3 + 5𝑥 2 + 𝑥 − 1 = 0; 𝑥𝑢𝑝 = 6, 𝑥𝑙𝑜𝑤 = −7
c) 𝑥 3 − 3𝑥 − 5 = 0; 𝑥𝑢𝑝 = 5, 𝑥𝑙𝑜𝑤 = −5
d) 𝑥 3 − 0.39𝑥 2 − 10.5𝑥 + 11.0 = 0; 𝑥𝑢𝑝 = 5, 𝑥𝑙𝑜𝑤 = −5

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 26

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 27

Experiment No. 4:
Name of the Experiment: Solutions to Non-Linear Equations (Secant Method
& Regula Falsi Method)

Objectives:
1. Familiar with the practical implementation of Precision of Root Finding for a System.
2. Familiar with the practical implementation of Regula Falsi Method.
3. Familiar with the practical implementation of Newton Raphson Method.
4. Familiar with the practical implementation of Secant Method.
5. Explain a system through difference equation in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Precision of Root Finding for a System.
2. Define Regula Falsi Method.
3. Define Newton Raphson Method.
4. Define Secant Method.

Theory:

Regula Falsi Method

A shortcoming of the bisection method is that, in dividing the interval from xlow to xup into
equal halves, no account is taken of the magnitude of f ( xlow ) and f ( xup ) . For example, if
f ( xlow ) is much closer to zero than f ( xup ) , it is likely that the root is closer to xlow than to
xup . An alternative method that exploits this graphical insight is to join f ( xlow ) and f ( xup )
by a straight line. The intersection of this line with the x axis represents an improved
estimate of the root. The fact that the replacement of the curve by a straight line gives the
false position of the root is the origin of the name, method of false position, or in Latin,
Regula Falsi. It is also called the Linear Interpolation Method.

Using similar triangles, the intersection of the straight line with the x axis can be estimated
f ( xlow ) f ( xup )
as =
x − xlow x − xup
P a g e | 28

f ( xup )( xlow − xup )


That is x = xup −
f ( xlow ) − f ( xup )
This is the False Position formulae. The value of x then replaces whichever of the two initial
guesses, xlow or xup , yields a function value with the same sign as f (x) . In this way, the
values of xlow and xup always bracket the true root. The process is repeated until the root is
estimated adequately.

Newton-Raphson method

Newton–Raphson method, named after Isaac Newton and Joseph Raphson, is a method for
finding successively better approximations to the roots (or zeroes) of a real-valued function.
It is one example of a root-finding algorithm.

𝑥: 𝑓(𝑥) = 0

The Newton–Raphson method in one variable is implemented as follows:

The method starts with a function f defined over the real numbers x, the function's derivative
f ′, and an initial guess x0 for a root of the function f. If the function satisfies the assumptions
made in the derivation of the formula and the initial guess is close, then a better
approximation x1 is

𝑓(𝑥0 )
𝑥1 = 𝑥0 −
𝑓 ′ (𝑥0 )

Geometrically, (x1, 0) is the intersection of


the x-axis and the tangent of the graph of f at
(x0, f (x0)).

The process is repeated as

𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 −
𝑓 ′ (𝑥𝑛 )

Until a sufficiently accurate value is


reached.

The Secant Method:

The secant method can be coded so that


only one new function evaluation is
required per iteration. The formula for
the secant method is the same one that
was used in the Regula Falsi method,
except that the logical decisions regarding
how to define each succeeding term are
different.
P a g e | 29

In the Secant method, the derivative can be approximated by a backward finite divided
difference, as in the figure,

f ( x k −1 ) − f ( x k )
f ( x k ) 
x k −1 − x k

Using Newton-Raphson method,


f ( xk )
x k +1 = x k −
f ( x k )
Substituting f ( x k ) ,
f ( x k )( x k −1 − x k )
x k +1 = x k −
f ( x k −1 ) − f ( x k )

Notice that the approach requires initial estimates of 𝑥𝑘 , 𝑥𝑘−1 .

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a

Procedure:

Regula Falsi Method Steps:

1. At first choice initial approximation 𝑥1 (bigger one) and 𝑥2 (smaller one)


2. Evaluate 𝑓(𝑥) equation and determine the values 𝑓(𝑥1 ) & 𝑓(𝑥2 )
𝑓(𝑥 )∗(𝑥2 −𝑥1 )
3. Determine the value, 𝑥 = 𝑥1 − 1 )−𝑓(𝑥 )
𝑓(𝑥2 1
4. Check if |𝑓(𝑥1 )| < |𝑓(𝑥2 )| then change 𝑥2 = 𝑥1 , 𝑥1 = 𝑥
if |𝑓(𝑥1 )| > |𝑓(𝑥2 )| then change 𝑥1 = 𝑥2 , 𝑥2 = 𝑥
5. Find 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 = |𝑥1 − 𝑥2 |
6. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 > 1 then repeat steps (2) to (5)
7. Continue evaluating steps (2) to (5) until difference has been reduced to a value < 1
8. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 < 1 then 𝑅𝑜𝑜𝑡 = 𝑥 and stop evaluating iterations.

Newton-Raphson method Steps:

1. At first choice initial approximation 𝑥1


2. Evaluate 𝑓(𝑥) equation and determine the values 𝑓(𝑥1 ) & 𝑓 ′ (𝑥1 )
𝑓(𝑥 )
3. Determine the value, 𝑥2 = 𝑥1 − ′ (𝑥1 )
𝑓 1
4. Find 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 = |𝑥2 − 𝑥1 |
5. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 > 1 then repeat steps (2) to (4)
6. Continue evaluating steps (2) to (4) until difference has been reduced to a value < 1
7. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 < 1 then 𝑅𝑜𝑜𝑡 = 𝑥2 and stop evaluating iterations.
P a g e | 30

The Secant Method Steps:

1. At first choice initial approximation 𝑥1 (bigger one) and 𝑥2 (smaller one)


2. Evaluate 𝑓(𝑥) equation and determine the values 𝑓(𝑥1 ) & 𝑓(𝑥2 )
𝑓(𝑥 )∗(𝑥1 −𝑥2 )
3. Determine the value, 𝑥3 = 𝑥2 − 2 )−𝑓(𝑥 )
𝑓(𝑥1 2
4. Find 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 = |𝑥3 − 𝑥2 |
5. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 > 1 then repeat steps (2) to (4) and change 𝑥1 = 𝑥2 , 𝑥2 = 𝑥3
6. Continue evaluating steps (2) to (4) until difference has been reduced to a value < 1
7. If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 < 1 then 𝑅𝑜𝑜𝑡 = 𝑥3 and stop evaluating iterations.

Report Question:

1. Write MATLAB Program of Regula Falsi, Secant, Newton-Raphson Methods for the
following systems: (here, 𝑥1 , 𝑥2 for Regula Falsi and Secant; 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 for Newton-Raphson)
a) 𝑥 5 + 𝑥 + 1 = 0; 𝑥1 = 5, 𝑥2 = −5 & 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = −0.8
b) 3𝑥 3 + 5𝑥 2 + 𝑥 − 1 = 0; 𝑥1 = 6, 𝑥2 = −7 & 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = −0.7
c) 𝑥 3 − 3𝑥 − 5 = 0; 𝑥1 = 5, 𝑥2 = −5 & 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = 2
d) 𝑥 3 − 0.39𝑥 2 − 10.5𝑥 + 11.0 = 0; 𝑥1 = 5, 𝑥2 = −5 & 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = 1.8

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 31

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 32

Experiment No. 5:
Name of the Experiment: Interpolation by Newton-Gregory forward
difference formula

Objectives:
1. Familiar with the practical implementation of Precision of Root Finding for a System.
2. Familiar with the practical implementation of Interpolation by Newton-Gregory
forward difference formula.
3. Familiar with the Merits and Demerits of Interpolation by Newton-Gregory forward
difference formula.
4. Explain a system through difference equation in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Precision of Root Finding for a System.
2. Define Interpolation by Newton-Gregory forward difference formula.

Theory:

We are familiar with the analytical method of finding the derivative of a function when the
functional relation between the dependent variable y and the independent variable x is
known. However, in practice, most often functions are defined only by tabulated data, or the
values of y for specified values of x can be found experimentally. Also in some cases, it is not
possible to find the derivative of a function by analytical method. In such cases, the analytical
process of differentiation breaks down and some numerical process have to be invented. The
process of calculating the derivatives of a function by means of a set of given values of that
function is called numerical differentiation. This process consists in replacing a complicated
or an unknown function by an interpolation polynomial and then differentiating this
polynomial as many times as desired.

Forward Difference Formula:

All numerical differentiation are done by expansion of Taylor series

𝑓′′(𝑥𝑖 )
𝑓(𝑥𝑖−1 ) = 𝑓(𝑥𝑖 ) + 𝑓′(𝑥𝑖 )ℎ + ℎ2 +…………..(1)
2!

From (1)

𝑓(𝑥𝑖+1 )−𝑓(𝑥𝑖 )
𝑓′(𝑥𝑖 ) ≅ + 𝑂(ℎ)……………..(2)

Where, O (h) is the truncation error, which consists of terms containing h and higher order
terms of h.
𝑓(𝑥 )−𝑓(𝑥𝑖 )
Total or True error = |𝑓 ′ (𝑥) − 𝑖+1 |………………..(3)

Newton- Gregory Forward Difference Approach:

Very often it so happens in practice that the given data set (𝑥𝑖 , 𝑦𝑖 ), 𝑖 = 0,1,2, … , 𝑛 correspond
to a sequence {𝑥𝑖 } of equally spaced points. Here we can assume that
P a g e | 33

𝑥𝑖 = 𝑥0 + 𝑖ℎ, 𝑖 = 0,1,2, … , 𝑛

where 𝑥0 is the starting point (sometimes, for convenience, the middle data point is taken as
𝑥0 and in such a case the integer 𝑖 is allowed to take both negative and positive values.) and
ℎ is the step size. Further it is enough to calculate simple differences rather than the
divided differences as in the non-uniformly placed data set case. These simple differences
can be forward differences (∆𝑓𝑖 ) or backward differences (∇𝑓𝑖 ). We will first look at forward
differences and the interpolation polynomial based on forward differences.

The first order forward difference ∆𝑓𝑖 is defined as

∆𝑓𝑖 = 𝑓𝑖+1 − 𝑓𝑖
The second order forward difference ∆2 𝑓𝑖 is defined as

∆2 𝑓𝑖 = ∆𝑓𝑖+1 − ∆𝑓𝑖
The third order forward difference ∆3 𝑓𝑖 is defined as

∆3 𝑓𝑖 = ∆2 𝑓𝑖+1 − ∆2 𝑓𝑖
The fourth order forward difference ∆4 𝑓𝑖 is defined as

∆4 𝑓𝑖 = ∆3 𝑓𝑖+1 − ∆3 𝑓𝑖

The kth order forward difference ∆𝑘 𝑓𝑖 is defined as

∆𝑘 𝑓𝑖 = ∆𝑘−1 𝑓𝑖+1 − ∆𝑘−1 𝑓𝑖

This is known as Newton-Gregory forward difference interpolation polynomial. For


convenience while constructing (10) one can first generate a forward difference table and use
the ∆𝑘 𝑓𝑖 from the table. Suppose we have data set (𝑥𝑖 𝑓𝑖 ), 𝑖 = 0,1,2,3,4 then forward
difference table looks as follows:

List of Equipment:

1. Desktop PC
P a g e | 34

2. Software MATLAB R2020a

Procedure:

Given the following data, estimate 𝑓(4.12) using Newton-Gregory forward difference
interpolation polynomial:

Solution:
Here we have six data points i.e. 𝑖 = 0,1,2,3,4,5 Let us first generate the forward difference
table.

Here,

We have Newton-Gregory forward difference interpolation formula

𝑘(𝑘 − 1) 2 𝑘(𝑘 − 1)(𝑘 − 2) 3


𝑓𝑥 = 𝑓0 + 𝑘∆𝑓0 + ∆ 𝑓0 + ∆ 𝑓0
2! 3!
𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3) 4
+ ∆ 𝑓0
4!
𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3)(𝑘 − 4) 5
+ ∆ 𝑓0
5!

𝑓(4.12) = 17.391338127360001(𝐴𝑛𝑠)

Steps:

1. At first create initial approximation matrix 𝑖, 𝑥𝑖 & 𝑓𝑖


P a g e | 35

2. Evaluate the matrices ∆𝑓𝑖 , ∆2 𝑓𝑖 , ∆3 𝑓𝑖 , ∆4 𝑓𝑖 & ∆5 𝑓𝑖 as required to solve the equation


3. Write MATLAB expression of the formula 𝑓𝑥 with inputs 𝑥, 𝑥0 , ℎ, 𝑘
4. Determine the value, 𝑓(4.12) using MATLAB Program

Report Question:

1. Determine the value, 𝑓(4.12)using MATLAB Program for Newton-Gregory forward


difference interpolation formula for the following systems, where h=1.
a) 𝑖 = 1,2,3,4; 𝑥𝑖 = 𝑖 + 1; 𝑓𝑖 = (𝑥𝑖 2 + 1) Ans. 17.9744
b) 𝑖 = 2,4,8,12; 𝑥𝑖 = 𝑖/2; 𝑓𝑖 = (𝑥𝑖 2 + |𝑥𝑖 |) Ans. 45.0826

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 36

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 37

Experiment No. 6:
Name of the Experiment: Interpolation by Newton-Gregory backward
difference formula

Objectives:
1. Familiar with the practical implementation of Precision of Root Finding for a System.
2. Familiar with the practical implementation of Interpolation by Newton-Gregory
backward difference formula.
3. Familiar with the Merits and Demerits of Interpolation by Newton-Gregory backward
difference formula.
4. Explain a system through difference equation in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Precision of Root Finding for a System.
2. Define Interpolation by Newton-Gregory backward difference formula.

Theory:

We are familiar with the analytical method of finding the derivative of a function when the
functional relation between the dependent variable y and the independent variable x is
known. However, in practice, most often functions are defined only by tabulated data, or the
values of y for specified values of x can be found experimentally. Also in some cases, it is not
possible to find the derivative of a function by analytical method. In such cases, the analytical
process of differentiation breaks down and some numerical process have to be invented. The
process of calculating the derivatives of a function by means of a set of given values of that
function is called numerical differentiation. This process consists in replacing a complicated
or an unknown function by an interpolation polynomial and then differentiating this
polynomial as many times as desired.

Backward Difference Formula:

All numerical differentiation are done by expansion of Taylor series

𝑓′′(𝑥𝑖 )
𝑓(𝑥𝑖−1 ) = 𝑓(𝑥𝑖 ) − 𝑓′(𝑥𝑖 )ℎ + ℎ2 −…………..(1)
2!

From (1)

𝑓(𝑥𝑖 )−𝑓(𝑥𝑖−1 )
𝑓′(𝑥𝑖 ) ≅ + 𝑂(ℎ)……………..(2)

Where, O (h) is the truncation error, which consists of terms containing h and higher order
terms of h.
𝑓(𝑥+ℎ)−𝑓(𝑥)
Total or True error = |𝑓 ′ (𝑥) − |………………..(3)

Newton- Gregory Backward Difference Approach:

The first order backward difference ∇𝑓𝑖 is defined as

∇𝑓𝑖 = 𝑓𝑖 − 𝑓𝑖−1
P a g e | 38

The second order backward difference ∆2 𝑓𝑖 is defined as

∇2 𝑓𝑖 = ∇𝑓𝑖 − ∇𝑓𝑖−1
The third order backward difference ∇3 𝑓𝑖 is defined as

∇3 𝑓𝑖 = ∇2 𝑓𝑖 − ∇2 𝑓𝑖−1
The fourth order backward difference ∇4 𝑓𝑖 is defined as

∇4 𝑓𝑖 = ∇3 𝑓𝑖 − ∇3 𝑓𝑖−1

The kth order backward difference ∇𝑘 𝑓𝑖 is defined as

∇𝑘 𝑓𝑖 = ∇𝑘−1 𝑓𝑖 − ∇𝑘−1 𝑓𝑖−1

This is known as Newton-Gregory backward difference interpolation polynomial. For


convenience while constructing (10) one can first generate a backward difference table and
use the ∇𝑘 𝑓𝑖 from the table. Suppose we have data set (𝑥𝑖 𝑓𝑖 ), 𝑖 = 0,1,2,3,4 then backward
difference table looks as follows:

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a

Procedure:

Given the following data, estimate 𝑓(4.12) using Newton-Gregory backward difference
interpolation polynomial:

Solution:
Here we have six data points i.e. 𝑖 = 0,1,2,3,4,5 Let us first generate the backward difference
table (next page).
P a g e | 39

Here,

We have Newton-Gregory backward difference interpolation formula

𝑘(𝑘 + 1) 2 𝑘(𝑘 + 1)(𝑘 + 2) 3


𝑓𝑥 = 𝑓5 + 𝑘∇𝑓5 + ∇ 𝑓5 + ∇ 𝑓5
2! 3!
𝑘(𝑘 + 1)(𝑘 + 2)(𝑘 + 3) 4
+ ∇ 𝑓5
4!
𝑘(𝑘 + 1)(𝑘 + 2)(𝑘 + 3)(𝑘 + 4) 5
+ ∇ 𝑓5
5!

𝑓(4.12) = 17.391338127360001 (𝐴𝑛𝑠)

Steps:

1. At first create initial approximation matrix 𝑖, 𝑥𝑖 & 𝑓𝑖


2. Evaluate the matrices ∇𝑓𝑖 , ∇2 𝑓𝑖 , ∇3 𝑓𝑖 , ∇4 𝑓𝑖 & ∇5 𝑓𝑖 as required to solve the equation
3. Write MATLAB expression of the formula 𝑓𝑥 with inputs 𝑥, 𝑥𝑛 , ℎ, 𝑘
4. Determine the value, 𝑓(4.12) using MATLAB Program

Report Question:

1. Write MATLAB Program of Newton-Gregory backward difference interpolation formula


for the following systems
a) 𝑖 = 1,2,3,4; 𝑥𝑖 = 𝑖 + 1; 𝑓𝑖 = (𝑥𝑖 2 + 1) Ans. 17.9744
b) 𝑖 = 2,4,8,12; 𝑥𝑖 = 𝑖/2; 𝑓𝑖 = (𝑥𝑖 2 + |𝑥𝑖 |) Ans. 7.1914
P a g e | 40

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 41

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 42

Experiment No. 7:
Name of the Experiment: Numerical Differentiation
(Based on Newton-Gregory Forward & Backward Differences)

Objectives:
1. Familiar with the practical implementation of numerical differentiation for a System.
2. Familiar with the practical implementation of numerical differentiation by Newton-
Gregory backward difference formula.
3. Familiar with the merits and demerits of numerical differentiation by Newton-
Gregory backward difference formula.
4. Explain a system through difference equation in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Precision of numerical differentiation for a System.
2. Define numerical differentiation by Newton-Gregory backward difference formula.

Theory:

We are familiar with the analytical method of finding the derivative of a function when the
functional relation between the dependent variable y and the independent variable x is
known. However, in practice, most often functions are defined only by tabulated data, or the
values of y for specified values of x can be found experimentally. Also in some cases, it is not
possible to find the derivative of a function by analytical method. In such cases, the analytical
process of differentiation breaks down and some numerical process have to be invented. The
process of calculating the derivatives of a function by means of a set of given values of that
function is called numerical differentiation. This process consists in replacing a complicated
or an unknown function by an interpolation polynomial and then differentiating this
polynomial as many times as desired.

Forward Difference Formula:

All numerical differentiation are done by expansion of Taylor series

𝑓′′(𝑥𝑖 )
𝑓(𝑥𝑖−1 ) = 𝑓(𝑥𝑖 ) + 𝑓′(𝑥𝑖 )ℎ + ℎ2 +…………..(1)
2!

From (1)

𝑓(𝑥𝑖+1 )−𝑓(𝑥𝑖 )
𝑓′(𝑥𝑖 ) ≅ + 𝑂(ℎ)……………..(2)

Where, O (h) is the truncation error, which consists of terms containing h and higher order
terms of h.
𝑓(𝑥 )−𝑓(𝑥𝑖 )
Total or True error = |𝑓 ′ (𝑥) − 𝑖+1 |………………..(3)

Newton- Gregory Forward Difference Approach:

Very often it so happens in practice that the given data set (𝑥𝑖 , 𝑦𝑖 ), 𝑖 = 0,1,2, … , 𝑛 correspond
to a sequence {𝑥𝑖 } of equally spaced points. Here we can assume that
P a g e | 43

𝑥𝑖 = 𝑥0 + 𝑖ℎ, 𝑖 = 0,1,2, … , 𝑛

where 𝑥0 is the starting point (sometimes, for convenience, the middle data point is taken as
𝑥0 and in such a case the integer 𝑖 is allowed to take both negative and positive values.) and
ℎ is the step size. Further it is enough to calculate simple differences rather than the
divided differences as in the non-uniformly placed data set case. These simple differences
can be forward differences (∆𝑓𝑖 ) or backward differences (∇𝑓𝑖 ). We will first look at forward
differences and the interpolation polynomial based on forward differences.

The first order forward difference ∆𝑓𝑖 is defined as

∆𝑓𝑖 = 𝑓𝑖+1 − 𝑓𝑖
2
The second order forward difference ∆ 𝑓𝑖 is defined as

∆2 𝑓𝑖 = ∆𝑓𝑖+1 − ∆𝑓𝑖
The third order forward difference ∆3 𝑓𝑖 is defined as

∆3 𝑓𝑖 = ∆2 𝑓𝑖+1 − ∆2 𝑓𝑖
The fourth order forward difference ∆4 𝑓𝑖 is defined as

∆4 𝑓𝑖 = ∆3 𝑓𝑖+1 − ∆3 𝑓𝑖

The kth order forward difference ∆𝑘 𝑓𝑖 is defined as

∆𝑘 𝑓𝑖 = ∆𝑘−1 𝑓𝑖+1 − ∆𝑘−1 𝑓𝑖

This is known as Newton-Gregory forward difference interpolation polynomial. For


convenience while constructing (10) one can first generate a forward difference table and use
the ∆𝑘 𝑓𝑖 from the table. Suppose we have data set (𝑥𝑖 𝑓𝑖 ), 𝑖 = 0,1,2,3,4 then forward
difference table looks as follows:

List of Equipment:

1. Desktop PC
P a g e | 44

2. Software MATLAB R2020a

Procedure:

Given the following data, estimate 𝑓 ′ (4.12) using Newton-Gregory forward difference
interpolation polynomial:

Solution:
Here we have six data points i.e. 𝑖 = 0,1,2,3,4,5 Let us first generate the forward difference
table.

Here,

We have Newton-Gregory forward difference interpolation formula

𝑘(𝑘 − 1) 2 𝑘(𝑘 − 1)(𝑘 − 2) 3


𝑓𝑥 = 𝑓0 + 𝑘∆𝑓0 + ∆ 𝑓0 + ∆ 𝑓0
2! 3!
𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3) 4
+ ∆ 𝑓0
4!
𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3)(𝑘 − 4) 5
+ ∆ 𝑓0
5!

𝑓(4.12) = 17.391338127360001
Now, [ From, "Numerical Methods" by S.Balachandra Rao, Equation - 5.5 ]
P a g e | 45

𝑑 𝑑(𝑓𝑥 ) 𝑑𝑘 1 𝑑(𝑓𝑥 )
(𝑓𝑥 ) = ∙ = ∙
𝑑𝑥 𝑑𝑘 𝑑𝑥 ℎ 𝑑𝑘

𝑑 𝑑
1 𝑑 (𝑘(𝑘 − 1)) (𝑘(𝑘 − 1)(𝑘 − 2))
∴ 𝑓𝑥′ = [ (𝑘) ∙ ∆𝑓0 + 𝑑𝑘 ∙ ∆2 𝑓0 + 𝑑𝑘 ∙ ∆3 𝑓0
ℎ 𝑑𝑘 2 6
𝑑
(𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3))
+ 𝑑𝑘 ∙ ∆4 𝑓0
24
𝑑
(𝑘(𝑘 − 1)(𝑘 − 2)(𝑘 − 3)(𝑘 − 4))
+ 𝑑𝑘 ∙ ∆5 𝑓0 ]
120

1 1 1 1 1 3 11 1
𝑓𝑥′ = [∆𝑓0 + (𝑘 − ) ∆2 𝑓0 + ( 𝑘 2 − 𝑘 + ) ∆3 𝑓0 + ( 𝑘 3 − 𝑘 2 + 𝑘 − ) ∆4 𝑓0
ℎ 2 2 3 6 4 12 4
1 4 1 3 7 2 5 1 5
+ ( 𝑘 − 𝑘 + 𝑘 − 𝑘 + ) ∆ 𝑓0 ]
24 3 8 6 5

𝑓 ′ (4.12) = 12.085339306666667 (Ans.)

Similarly for Newton-Gregory backward difference interpolation formula

1 1 1 1 1 3 11 1
𝑓𝑥′ = [∇𝑓0 + (𝑘 + ) ∇2 𝑓0 + ( 𝑘 2 + 𝑘 + ) ∇3 𝑓0 + ( 𝑘 3 + 𝑘 2 + 𝑘 + ) ∇4 𝑓0
ℎ 2 2 3 6 4 12 4
1 4 1 3 7 2 5 1 5
+ ( 𝑘 + 𝑘 + 𝑘 + 𝑘 + ) ∇ 𝑓0 ]
24 3 8 6 5

𝑓 ′ (4.12) = 2.153514459733333 ∗ 102 (Ans. )

Steps:

1. At first create initial approximation matrix 𝑖, 𝑥𝑖 & 𝑓𝑖


2. Evaluate the matrices ∇𝑓𝑖 , ∇2 𝑓𝑖 , ∇3 𝑓𝑖 , ∇4 𝑓𝑖 & ∇5 𝑓𝑖 as required to solve the equation

3. Write MATLAB expression of the formula 𝑓𝑥 with inputs 𝑥, 𝑥𝑛 , ℎ, 𝑘
4. Determine the value, 𝑓 ′ (4.12) using MATLAB Program

Report Question:

1. Write MATLAB Program of Numerical Differentiation for Newton-Gregory forward &


backward difference interpolation formula for the following systems
a) 𝑖 = 1,2,3,4; 𝑥𝑖 = 𝑖 + 1; 𝑓𝑖 = (𝑥𝑖 2 + 1) Ans. 8.24 (forward), 8.24 (backward)
b) 𝑖 = 2,4,8,12; 𝑥𝑖 = 𝑖/2; 𝑓𝑖 = (𝑥𝑖 2 + |𝑥𝑖 |) Ans. 26.038933(forward),
10.5189(backward)
P a g e | 46

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 47

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 48

Experiment No. 8:
Name of the Experiment: Numerical Differentiation (Based on Lagrange
Interpolation) & Numerical Integration (Based on Simple Trapezium Rule)

Objectives:
1. Familiar with the practical implementation of numerical differentiation and numerical
integration for a System.
2. Familiar with the practical implementation of numerical differentiation based on
Lagrange Interpolation for a System.
3. Familiar with the practical implementation of numerical integration based on Simple
Trapezium Rule for a System.
4. Explain a system through difference equation in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Precision of numerical differentiation and numerical integration for a System.
2. Define numerical differentiation based on Lagrange Interpolation formula.
3. Define numerical integration based on Simple Trapezium Rule formula.

Theory:

a) Lagrange Polynomial:

The Lagrange interpolating polynomial is the polynomial P ( x) of degree ( n − 1) that passes


through the n points , , ..., , and is given by

where

Written explicitly,

When constructing interpolating polynomials, there is a tradeoff between having a better fit
and having a smooth well-behaved fitting function. The more data points that are used in the
interpolation, the higher the degree of the resulting polynomial, and therefore the greater
oscillation it will exhibit between the data points. Therefore, a high-degree interpolation may
P a g e | 49

be a poor predictor of the function between points, although the accuracy at the data points
will be "perfect."

For points,

Note that the function P ( x) passes through the points , as can be seen for the case
,

b) Simple Trapezium Rule:

We know that higher order differences are negligible for small ℎ in the case of well behaved
functions.
𝑥0 +𝑘
1 ℎ
∫ 𝑦𝑑𝑥 = ℎ (𝑓0 + ∆𝑓0 ) = (𝑓1 + 𝑓0 )
2 2
𝑥0

E B
Y

O π/4 X
One Strip

Two Strip

The above formula is called the Trapezium Rule.


P a g e | 50

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a

Procedure:

a) Find 𝒇′ (𝟎. 𝟏𝟐) from the following data using Lagrange Polynomial Interpolation:

x 0.05 0.10 0.20 0.26

𝑓(𝑥) 0.05000 0.0999 0.1987 0.2571

Solution:

Using Lagrange Polynomial Interpolation we get,

(𝑥 − 𝑥2 )(𝑥 − 𝑥3 )(𝑥 − 𝑥4 ) (𝑥 − 𝑥1 )(𝑥 − 𝑥3 )(𝑥 − 𝑥4 )


𝑓(𝑥) = 𝑦1 + 𝑦
(𝑥1 − 𝑥2 )(𝑥1 − 𝑥3 )(𝑥1 − 𝑥4 ) (𝑥2 − 𝑥1 )(𝑥2 − 𝑥3 )(𝑥2 − 𝑥4 ) 2
(𝑥 − 𝑥1 )(𝑥 − 𝑥2 )(𝑥 − 𝑥4 ) (𝑥 − 𝑥1 )(𝑥 − 𝑥2 )(𝑥 − 𝑥3 )
+ 𝑦3 + 𝑦
(𝑥3 − 𝑥1 )(𝑥3 − 𝑥2 )(𝑥3 − 𝑥4 ) (𝑥4 − 𝑥1 )(𝑥4 − 𝑥2 )(𝑥4 − 𝑥3 ) 4

𝑓(𝑥) = −0.119𝑥 3 − 0.025𝑥 2 + 1.004𝑥

Differentiating 𝑓(𝑥) with respect to 𝑥 we have

𝑓 ′ (𝑥) = −0.357𝑥 2 − 0.05𝑥 + 1.004

When 𝑥 = 0.12, we get

𝑓 ′ (0.12) = 0.9927

Steps for the Lagrange Polynomial:

For a given x and f(x), two sets of (N+1) data pairs, (xi , fi), i= 0, 1, . ….. N:

Set SUM=0

DO FOR i=0 to N

Set Y=1

DO FOR j=0 to N

IF j~=i

Set Y=Y*(x-x(j))/(x(i)-x(j))
P a g e | 51

End DO(j)

Y=Y*f

SUM=SUM+Y

𝟎.𝟖 𝟐
b) Evaluate Numerically ∫𝟎 (𝒆−𝒙 )𝒅𝒙 using Simple Trapezium Rule

Table 2
2
X 𝑓 = 𝑒 −𝑥
0 1.0000
0.1 0.9900
0.2 0.9608
0.3 0.9139
0.4 0.8521
0.5 0.7788
0.6 0.6977
0.7 0.6126
0.8 0.5273

From Simple Trapezium Rule:

We know that higher order differences are negligible for small ℎ in the case of well-behaved
functions.
𝑥0 +𝑘
1
∫ 𝑦𝑑𝑥 = ℎ (𝑓0 + ∆𝑓0 )
2
𝑥0


= (𝑓 + 𝑓0 )
2 1

Here, ℎ = 𝑥𝑛 − 𝑥0 = 0.8 − 0 = 0.8, for one strip


𝑥 −𝑥 0.8−0
ℎ= 𝑛 0= = 0.4, for two strip
2 2
𝑥𝑛 −𝑥0 0.8−0
ℎ= = = 0.2, for four strip
4 4
𝑥𝑛 −𝑥0 0.8−0
ℎ= = = 0.1, for eight strip
8 8

For one strip (i.e. h=0.8),

ℎ 0.8
𝐼11 = (𝑓0 + 𝑓1 ) = (1 + 0.5273) = 0.6109
2 2
For two strip (i.e. h=0.4),

ℎ 0.4
𝐼21 = (𝑓0 + 2𝑓1 + 𝑓2 ) = (1 + 2 ∗ 0.8521 + 0.5273) = 0.6463
2 2
P a g e | 52

For four strips (i.e. h=0.2),


𝐼31 = (𝑓 + 2𝑓1 + 2𝑓2 + 2𝑓3 + 𝑓4 )
2 0
0.2
= (1 + 2 ∗ 0.9608 + 2 ∗ 0.8521 + 2 ∗ 0.6977 + 0.5273) = 0.6549
2

For eight strips (i.e. h=0.1),


𝐼41 = (𝑓 + 2𝑓1 + 2𝑓2 + 2𝑓3 + 2𝑓4 + 2𝑓5 + 2𝑓6 + 2𝑓7 + 𝑓8 )
2 0
0.1
= (1 + 2 ∗ 0.9900 + 2 ∗ 0.9608 + 2 ∗ 0.9139 + 2 ∗ 0.8521 + 2
2
∗ 0.7788 + 2 ∗ 0.6977 + 2 ∗ 0.6126 + 0.5273) = 0.6570

Steps:

1. At first evaluate initial approximation matrices 𝑥𝑖 & 𝑓𝑖


2. Evaluate the matrices 𝑓0 𝑡𝑜 𝑓8 as required to solve the equation
3. Write MATLAB expression of the formula 𝐼11 , 𝐼21 , 𝐼31 & 𝐼41

Report Question:

1. Write MATLAB Program of Numerical Differentiation for Lagrange Polynomial


interpolation formula for the following systems to find 𝑓 ′ (0.12)
a) 𝑖 = 1,2,3,4; 𝑥𝑖 = 𝑖 + 1; 𝑓𝑖 = (𝑥𝑖 2 + 1) Ans. 0.24
b) 𝑖 = 2,4,8,12; 𝑥𝑖 = 𝑖/2; 𝑓𝑖 = (𝑥𝑖 2 + |𝑥𝑖 |) Ans. 1.24

2. Write MATLAB Program of Numerical Integration using Simple Trapezium Rule for
𝝅/𝟒
∫𝒐 𝒄𝒐𝒔𝒙𝒅𝒙 up to eight strips. Ans. 0.6704, 0.6980, 0.7048, 0.7065

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 53

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 54

Experiment No. 9:
Name of the Experiment: Numerical Integration by Romberg Integration
and Simpson's 1/3rd, 3/8th Rule

Objectives:
1. Familiar with the practical implementation of numerical integration for a System.
2. Familiar with the practical implementation of numerical integration based on
Romberg Integration for a System.
3. Familiar with the practical implementation of numerical integration based on
Simpson's 1/3rd rule for a System.
4. Familiar with the practical implementation of numerical integration based on
Simpson's 3/8th rule for a System.
5. Explain a system through difference features in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Precision of numerical integration for a System.
2. Define numerical integration based on Romberg Integration formula.
3. Define numerical integration based on Simpson's 1/3rd rule formula.
4. Define numerical integration based on Simpson's 3/8th rule formula.

Theory:

There are two cases in which engineers and scientists may require the help of numerical
integration technique. (1) Where experimental data is obtained whose integral may be
required and (2) where a closed form formula for integrating a function using calculus is
difficult or so complicated as to be almost useless. For example the integral

x t3
(t ) =  dt.
0 et − 1

Since there is no analytic expression for  ( x) , numerical integration technique must be used
to obtain approximate values of  ( x) .

Formulae for numerical integration called quadrature are based on fitting a polynomial
through a specified set of points (experimental data or function values of the complicated
function) and integrating (finding the area under the fitted polynomial) this approximating
function. Any one of the interpolation polynomials studied earlier may be used.

a) Romberg Integration

In the case of Trapezoidal rule:


4𝑛−1 𝐼𝑗(𝑛−1) − 𝐼(𝑗−1)(𝑛−1)
𝐼𝑗𝑛 = ; 𝑗 = 𝑛, 𝑛 + 1, …
4𝑛−1 − 1
In the case of Simpson’s rule:

4𝑛 𝐼𝑗(𝑛−1) − 𝐼(𝑗−1)(𝑛−1)
𝐼𝑗𝑛 = ; 𝑗 = 𝑛, 𝑛 + 1, …
4𝑛 − 1
P a g e | 55

b) Simpson’s 1/3 Rule

This is based on approximating the function f(x) by fitting quadratics through sets of three
points. For only three points it can be written as:

x1 + 2 h
h

x1
f ( x)dx = ( f1 + 4 f 2 + f3 )
3

This is called second-degree Newton-Cotes formula.

It is evident that the result of integration between x1 and x1+nh can be written as

x1 + nh
h
 f ( x)dx = 
i =1,3,5,..., n −1 3
( fi + 4 fi +1 + fi + 2 )
x1

h
= ( f1 + 4 f 2 + 2 f 3 + 4 f 4 + 2 f 5 + 4 f 6 + ... 4 f n + f n +1 )
3

In using the above formula it is implied that f is known at an odd number of points (n+1 is
odd, where n is the no. of subintervals).

c) Simpson’s 3/8 Rule

This is based on approximating the function f(x) by fitting cubic interpolating polynomial
through sets of four points. For only four points it can be written as:

x1 +3h
3h

x1
f ( x)dx =
8
( f1 + 3 f 2 + 3 f3 + f 4 )

This is called third-degree Newton-Cotes formula.

It is evident that the result of integration between x1 and x1+nh can be written as

x1 + nh
h
 f ( x)dx = 
i =1,4,7,..., n − 2 3
( f i + 3 f i +1 + 3 f i + 2 + f i +3 )
x1

3h
= ( f1 + 3 f 2 + 3 f 3 + 2 f 4 + 3 f 5 + 3 f 6 + 2 f 7 + ... + 2 f n −2 + 3 f n −1 + 3 f n + f n +1 )
8

In using the above formula it is implied that f is known at (n+1) points where n is divisible
by 3.

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a
P a g e | 56

Procedure:

a) Romberg Integration
0.8 2
Using the values given in the following Table 2, find ∫0 (𝑒 −𝑥 )𝑑𝑥 by Romberg’s
integration.

Solution: Table 1
2
X 𝑓 = 𝑒 −𝑥
0 1
0.1 0.9901
0.2 0.9608
0.3 0.9139
0.4 0.8521
0.5 0.7788
0.6 0.6977
0.7 0.6126
0.8 0.5273

From Simple Trapezium Rule, we know that higher order differences are negligible for small
ℎ in the case of well behaved functions.

𝑥0 +𝑘
1
∫ 𝑦𝑑𝑥 = ℎ (𝑓0 + ∆𝑓0 )
2
𝑥0


= (𝑓 + 𝑓0 )
2 1

Here, ℎ = 𝑥𝑛 − 𝑥0 = 0.8 − 0 = 0.8, for one strip


𝑥 −𝑥 0.8−0
ℎ= 𝑛 0= = 0.4, for two strip
2 2
𝑥𝑛 −𝑥0 0.8−0
ℎ= = = 0.2, for three strip
4 4
𝑥𝑛 −𝑥0 0.8−0
ℎ= = = 0.1, for four strip
8 8

For one strip (i.e. h=0.8),


ℎ 0.8
𝐼11 = (𝑓0 + 𝑓1 ) = (1 + 0.5273) = 0.6109
2 2
For two strip (i.e. h=0.4),

ℎ 0.4
𝐼21 = (𝑓0 + 2𝑓1 + 𝑓2 ) = (1 + 2 ∗ 0.8521 + 0.5273) = 0.6463
2 2

For four strips (i.e. h=0.2),


P a g e | 57


𝐼31 = (𝑓 + 2𝑓1 + 2𝑓2 + 2𝑓3 + 𝑓4 )
2 0
0.2
= (1 + 2 ∗ 0.9608 + 2 ∗ 0.8521 + 2 ∗ 0.6977 + 0.5273) = 0.6549
2

For eight strips (i.e. h=0.1),


𝐼41 = (𝑓 + 2𝑓1 + 2𝑓2 + 2𝑓3 + 2𝑓4 + 2𝑓5 + 2𝑓6 + 2𝑓7 + 𝑓8 )
2 0
0.1
= (1 + 2 ∗ 0.9900 + 2 ∗ 0.9608 + 2 ∗ 0.9139 + 2 ∗ 0.8521 + 2
2
∗ 0.7788 + 2 ∗ 0.6977 + 2 ∗ 0.6126 + 0.5273) = 0.6570

Table 2

h 𝐼𝑗1 (𝑗 = 1,2,3,4)
0.8 𝐼11 = 0.6109
0.4 𝐼21 = 0.6463
0.2 𝐼31 = 0.6549
0.1 𝐼41 = 0.6570

Now From Romberg’s Formula:

4𝑛−1 𝐼𝑗(𝑛−1) − 𝐼(𝑗−1)(𝑛−1)


𝐼𝑗𝑛 = ; 𝑗 = 𝑛, 𝑛 + 1, …
4𝑛−1 − 1
4𝐼21 − 𝐼11 4𝐼31 − 𝐼21 4𝐼41 − 𝐼31
𝐼22 = , 𝐼32 = , 𝐼42 =
3 3 3

42 𝐼32 − 𝐼22 42 𝐼42 − 𝐼32


𝐼33 = , 𝐼43 =
15 15

43 𝐼43 − 𝐼33
𝐼44 =
63

ℎ2 ℎ4 ℎ6 ℎ8
𝐼11
𝐼21 𝐼22
𝐼31 𝐼32 𝐼33
𝐼41 𝐼42 𝐼43 𝐼44

Ans.: I22 = 0.6581, I33 = 0.6577, I44 = 0.6577

Steps:

1. At first evaluate initial approximation matrices 𝑥𝑖 & 𝑓𝑖


P a g e | 58

2. Evaluate corresponding ℎ and matrices 𝑓0 𝑡𝑜 𝑓8 as required to solve the equation


3. Write MATLAB expression of the formula 𝐼11 , 𝐼21 , 𝐼31 & 𝐼41
4. Determine 𝐼22 , 𝐼32 , 𝐼42 , 𝐼33 , 𝐼43 , 𝐼44 using MATLAB.

b) Simpson’s 1/3 Rule:

7 1
Evaluate ∫1 ( ) 𝑑𝑥 by using Simpson’s composite 1/3 rule.
𝑥

Solutiuon: Compare the values with the exact value of the integral

Table 1

X 1
𝑓(𝑥) =
𝑥
1 1
2 0.5
3 0.33
4 0.25
5 0.2
6 0.17
7 0.14

𝑥𝑛 − 𝑥0
ℎ=
𝑛−1
7
1 ℎ
∫ ( ) 𝑑𝑥 = (𝑓1 + 4𝑓2 + 2𝑓3 + 4𝑓4 + 2𝑓5 + 4𝑓6 + 𝑓7 )
𝑥 3
1

Ans.: (a) 1.9587

c) Simpson’s 3/8 Rule:

7 1
Evaluate ∫1 ( ) 𝑑𝑥 by using Simpson’s composite 3/8 rule.
𝑥

Solutiuon: Compare the values with the exact value of the integral

Table 2

X 1
𝑓(𝑥) =
𝑥
1 1
2 0.5
3 0.33
4 0.25
5 0.2
6 0.17
7 0.14
P a g e | 59

𝑥𝑛 − 𝑥0
ℎ=
𝑛−1
7
1 3ℎ
∫ ( ) 𝑑𝑥 = (𝑓 + 3𝑓2 + 3𝑓3 + 2𝑓4 + 3𝑓5 + 3𝑓6 + 𝑓7 )
𝑥 8 1
1

Ans.: 1.9661

Steps:

An algorithm for integrating a tabulated function using composite trakpezoidal rule:


Remarks: f1, f2,………, fn+1 are the tabulated values at x1, x1+h,………x1+nh (n+1 points)
1 Read 𝑥1→𝑛+1
2 n=length(x)
𝑥 −𝑥 𝑥 −𝑥
3 ℎ = 𝑛+1 0 𝑂𝑅 𝑛 0
𝑛 𝑛−1
4 Read 𝑓(𝑥) = 𝑦
5 𝑓𝑜𝑟 𝑖 = 2 𝑡𝑜 𝑛 + 1 𝑅𝑒𝑎𝑑 𝑓𝑖 𝑒𝑛𝑑 𝑓𝑜𝑟
6 𝑠𝑢𝑚1 ← (𝑓𝑖 + 𝑓𝑛+1 )
7 𝑓𝑜𝑟 𝑖 = 3 𝑡𝑜 𝑛 − 1 𝑅𝑒𝑎𝑑 𝑓𝑖 𝑒𝑛𝑑 𝑓𝑜𝑟
8 𝑠𝑢𝑚2 ← (𝑓𝑖 + 𝑓𝑛−1 )
9 𝑠𝑢𝑚 ← (𝑠𝑢𝑚1 + 𝑠𝑢𝑚2)

10 𝑖𝑛𝑡𝑒𝑔𝑟𝑎𝑙 ← . 𝑠𝑢𝑚
3

Report Question:

1. Write MATLAB Program of Numerical Integration using Romberg Integration for


𝝅/𝟒
∫𝒐 𝒄𝒐𝒔𝒙𝒅𝒙 up to eight strips. Ans. I22=0.7072, I33=0.7071, I44=0.7071

2. Write MATLAB Program of Numerical Differentiation for Simpson’s composite 1/3 &
3/8 rules for the following systems:
a) 𝑖 = 1,2,3,4; 𝑥𝑖 = 𝑖 + 1; 𝑓𝑖 = (𝑥𝑖 2 + 1) Ans. 23.6667, 11.6250
b) 𝑖 = 2,4,8,12; 𝑥𝑖 = 𝑖/2; 𝑓𝑖 = (𝑥𝑖 2 + |𝑥𝑖 |) Ans. 37.7778, 27.5000

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha
P a g e | 60

COURSE TITLE:
COURSE CODE:

EXPERIMENT NO.:
EXPERIMENT NAME:

DATE OF PERFORMANCE:
DATE OF SUBMISSION:

SUBMITTED TO: SUBMITTED BY:


Name: Name:
Designation: ID:
Department of EEE Batch No.:
Green University of Bangladesh Department of ……..
Green University of Bangladesh

REMARKS
P a g e | 61

Experiment No. 10:


Name of the Experiment: Solution of system of Linear Equations By a direct
method (LU Decomposition) and an indirect method (Jacobi or Gauss
Seidel Method)

Objectives:
1. Familiar with the practical implementation of the different techniques of finding
solution of a set of n linear algebraic equations in n unknowns.
2. Familiar with the practical implementation of LU Decomposition for system solution
of linear equations.
3. Familiar with the practical implementation of Jacobi or Gauss Seidel method for
system solution of linear equations.
4. Explain a system through difference features in digital domain.

Learning Outcome: After completing this experiment the students will be able to:
1. Define Precision of system solution for linear equations.
2. Define LU Decomposition for system solution of linear equations.
3. Define Jacobi or Gauss Seidel method for system solution of linear equations.

Theory:

Concept of linear equations and their solution


A set of linear algebraic equations looks like this:

a11 x1 + a12 x2 + ...a1N xN = b1

a21 x1 + a22 x2 + ...a2 N xN = b2 (1)

… … … …

aM 1 x1 + aM 2 x2 + ...aMN xN = bM

Here the N unknowns xj , j = 1, 2, . . .,N are related by M equations. The coefficients aij with i
= 1, 2, . . .,M and j = 1, 2, . . .,N are known numbers, as are the right-hand side quantities bi, i
= 1, 2, . . .,M.

Existence of solution
If N = M then there are as many equations as unknowns, and there is a good chance of
solving for a unique solution set of xj’s. Analytically, there can fail to be a unique solution if
one or more of the M equations is a linear combination of the others (This condition is called
row degeneracy), or if all equations contain certain variables only in exactly the same linear
combination(This is called column degeneracy). (For square matrices, a row degeneracy
implies a column degeneracy, and vice versa.) A set of equations that is degenerate is called
singular.

Numerically, at least two additional things can go wrong:


P a g e | 62

• While not exact linear combinations of each other, some of the equations may be so close to
linearly dependent that round off errors in the machine renders them linearly dependent at
some stage in the solution process. In this case your numerical procedure will fail, and it can
tell you that it has failed.

• Accumulated round off errors in the solution process can swamp the true solution. This
problem particularly emerges if N is too large. The numerical procedure does not fail
algorithmically. However, it returns a set of x’s that are wrong, as can be discovered by direct
substitution back into the original equations. The closer a set of equations is to being singular,
the more likely this is to happen.

Matrices
Equation (1) can be written in matrix form as

A·x=b (2)

Here the raised dot denotes matrix multiplication, A is the matrix of coefficients, x is the
column vector of unknowns and b is the right-hand side written as a column vector,

 a11 a12 ... a1N   x1   b1 


a a22 ... a2 N  x  b 
A =  21 x= 2 b= 2
 ... ... ... ...   ..   .. 
     
 aM 1 aM 2 ... aMN   xN  bM 

Finding Solution
There are so many ways to solve this set of equations. Below are some important methods.

(1) Using the backslash and pseudo-inverse operator

In MATLAB, the easiest way to determine whether Ax = b has a solution, and to find such a
solution when it does, is to use the backslash operator. Exactly what A \ b returns is a bit
complicated to describe, but if there is a solution to A · x = b, then A \ b returns one.
Warnings: (1) A \ b returns a result in many cases when there is no solution to A · x = b. (2)
A \ b sometimes causes a warning to be issued, even when it returns a solution. This means
that you can't just use the backslash operator: you have to check that what it returns is a
solution. (In any case, it's just good common sense to check numerical computations as you
do them.) In MATLAB this can be done as follows:

Using backslash operator:

x = A\b;

You can also use the pseudo-inverse operator:

x=inv(A)*b; % it is also guaranteed to solve Ax = b, if Ax = b has a solution.

As with the backslash operator, you have to check the result.


P a g e | 63

(2) Using Gauss-Jordan Elimination and Pivoting

To illustrate the method let us consider three equations with three unknowns:

a11 x1 + a12 x2 + a13 x3 = a14 (A)

a21 x1 + a22 x2 + a23 x3 = a24 (B)

a31 x1 + a32 x2 + a33 x3 = a34 (C)

Here the quantities bi, i = 1, 2, . . .,M’s are replaced by aiN+1, where i=1,2, ….M for simplicity
of understanding the algorithm.

The First Step is to eliminate the first term from Equations (B) and (C). (Dividing (A) by a11
and multiplying by a21 and subtracting from (B) eliminates x1 from (B) as shown below)

a11 a a a
(a21 − a21 ) x1 + (a22 − 12 a21 ) x2 + (a23 − 13 a21 ) x3 = (a24 − 14 a21 )
a11 a11 a11 a11

a21
Let, = k2 , then
a11

(a21 − k2 a11 ) x1 + (a22 − k2 a12 ) x2 + (a23 − k 2 a13 ) x3 = (a24 − k 2 a14 )

a31
Similarly multiplying equation (A) by = k3 and subtracting from (C), we get
a11

(a31 − k3a11 ) x1 + (a32 − k3a12 ) x2 + (a33 − k3a13 ) x3 = (a34 − k3a14 )

Observe that (a21 − k2 a11 ) and (a31 − k3a11 ) are both zero.

In the steps above it is assumed that a11 is not zero. This case will be considered later in this
experiment.

The above elimination procedure is called triangularization.

Procedure:

For triangularizing n equations in n unknowns:

1 for i = 1 to n and j = 1 to (n + 1) in steps of 1 do read aij endfor

2 for k = 1 to (n − 1) in steps of 1 do

3 for i = (k + 1) to n in steps of 1 do

4 u  aik / akk
P a g e | 64

5 for j = k to (n + 1) in steps of 1 do

6 aij  aij − uakj endfor

endfor

endfor

The reduced equations are:

a11 x1 + a12 x2 + a13 x3 = a14

a22 x2 + a23 x3 = a24

a32 x2 + a33 x3 = a34

The next step is to eliminate a32 from the third equation. This is done by multiplying second
equation by u = a32 / a22 and subtracting the resulting equation from the third. So, same
algorithm can be used.

Finally the equations will take the form:

a11 x1 + a12 x2 + a13 x3 = a14

a22 x2 + a23 x3 = a24

a33 x3 = a34

The above set of equations are said to be in triangular (Upper) form.

From the above upper triangular form of equations, the values of unknowns can be obtained
by back substitution as follows:

x3 = a34 / a33

x2 = (a24 − a23 x3 ) / a22

x2 = (a14 − a12 x2 − a13 x3 ) / a11

Algorithmically, the back substitution for n unknowns is shown below:

1 xn  an ( n +1) / ann
P a g e | 65

2 for i = (n − 1) to 1 in step of -1 do

3 sum  0

4 for j = (i + 1) to n in steps of 1 do

5 sum  sum + aij x j endfor

6 xi  (ai ( n +1) − sum) / aii

endfor

Pivoting

In the triangularization algorithm we have used,

u  aik / akk

Here it is assumed that akk is not zero. If it happens to be zero or nearly zero, the algorithm
will lead to no results or meaningless results. If any of the akk is small it would be necessary
to reorder the equations. It is noted that the value of akk would be modified during the
elimination process and there is no way of predicting their values at the start of the procedure.

The elements akk are called pivot elements. In the elimination procedure the pivot should not
be zero or a small number. In fact for maximum precision the pivot element should be the
largest in absolute value of all the elements below it in its column, i.e. akk should be picked
up as the maximum of all amk where, m  k

So, during the Gauss elimination, amk elements should be searched and the equation with the
maximum value of amk should be interchanged with the current position. For example if
during elimination we have the following situation:

x1 + 2 x2 + 3x3 = 4
0.3x2 + 4 x3 = 5
−8 x2 + 3 x3 = 6

As −8  0.3, 2nd and 3rd equations should be interchanged to yield:

x1 + 2 x2 + 3x3 = 4
−8 x2 + 3 x3 = 6
0.3x2 + 4 x3 = 5
P a g e | 66

It should be noted that interchange of equations does not affect the solution.

The algorithm for picking the largest element as the pivot and interchanging the equations is
called pivotal condensation.

Procedure:

For pivotal condensation

1 max  akk

2 pk

3 for m = (k + 1) to n in steps of 1 do

4 if ( amk  max) then

5 max  amk

6 pm

7 endif

endfor

8 if ( p ~ = k )

9 for q = k to (n + 1) in steps of 1 do

10 temp  akq

11 akq  a pq

12 a pq  temp

endfor

endif

(3) Using Gauss-Seidel Iterative Method

There are several iterative methods for the solution of linear systems. One of the efficient
iterative methods is the Gauss-Seidel method.

Let us consider the system of equations:


P a g e | 67

4 x1 − x2 + x3 = 7
4 x1 − 8 x2 + x3 = −21
−2 x1 + x2 + 5 x3 = 15

The Gauss-Seidel iterative process is suggested by the following equations:

k +1 7 + x2k − x3k
x =
1
4
21 + 4 x1k +1 + x3k
x2k +1 =
8
15 + 2 x1k +1 − x2k +1
x3k +1 =
5

The very first iteration, that is x20 , x30 ,.....xn0 (for n equations) are set equal to zero and x11 is
calculated. The main point of Gauss-Seidel iterative process to observe is that always the
latest approximations for the values of variables are used in an iteration step.

It is to be noted that in some cases the iteration diverges rather than it converges. Both the
divergence and convergence can occur even with the same set of equations but with the
change in the order. The sufficient condition for the Gauss-Seidel iteration to converge is
stated below.

The Gauss-Seidel iteration for the solution will converge (if there is any solution) if the
matrix A (as defined previously) is strictly diagonally dominant matrix.

A matrix A of dimension N  N is said to be strictly diagonally dominant provided that

N
akk   akj for k = 1, 2,...N
j =1
jk

List of Equipment:

1. Desktop PC
2. Software MATLAB R2020a

Report Question:

1. Given the simultaneous equations shown below (i) triangularize them (ii) use back
substitution to solve for x1 , x2 , x3 .

2 x1 + 3 x2 + 5 x3 = 23
3 x1 + 4 x2 + x3 = 14
6 x1 + 7 x2 + 2 x3 = 26
P a g e | 68

For generalization, you will have to write a program for triangularizing n equations in n
unknowns with back substitution.

2. Modify the MATLAB program written in exercise 1 to include pivotal condensation.


3. Try to solve the following systems of equations (i) Gauss-Jordan elimination (ii) Gauss-
Jordan elimination with pivoting

2 x1 + 4 x2 − 6 x3 = −4 x1 + x2 + 6 x3 = 7
(A) x1 + 5 x2 + 3x3 = 10 (B) − x1 + 2 x2 + 9 x3 = 2
x1 + 3x2 + 2 x3 = 5 x1 − 2 x2 + 3x3 = 10

4 x1 + 8 x2 + 4 x3 = 8
x1 + 5 x2 + 4 x3 − 3 x4 = −4
(C)
x1 + 4 x2 + 7 x3 + 2 x4 = 10
x1 + 3 x2 − 2 x4 = −4

4. Solve the following equations using Gauss-Seidel iteration process:

8 x1 − 3x2 = 10 4 x − y = 15
(A) (B)
− x1 + 4 x2 = 6 x + 5y = 9

5 x1 − x2 + x3 = 10 2 x + 8 y − z = 11
(C) 2 x1 + 8 x2 − x3 = 11 (D) 5 x − y + z = 10
− x1 + x2 + 4 x3 = 3 −x + y + 4z = 3

Reference Book:

1) Applied Numerical Methods with MATLAB (for Engineers & Scientists)


(Special Indian Edition),
Steven C. Chapra

2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha

You might also like