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
Instructions for Laboratory
Page
No
3
Laboratory Course Syllabus
4
Experiment -1
Introduction to MATLAB (Part-A)
8
Experiment- 2
Introduction to MATLAB (Part-B)
11
Experiment- 3
15
Experiment -5
Iterative Processes For Root Finding
(Iterative Method, Aitken’s ∆² Acceleration Method, Bisection
Method)
Solutions to Non-Linear Equations
(Secant Method & Regula Falsi Method)
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) &
Numerical Integration (Based on Simple Trapezium Rule)
27
Experiment -9
Numerical Integration By Simpson's 1/3, 3/8th Rule & Romberg
Integration
30
Experiment- 10
Solution of system of Linear Equations By
A direct method (LU Decomposition),
An indirect method (Jacobi or Gauss Seidel Method)
Experiment- 4
19
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
Numerical Technique Laboratory
5
Name of
Course
Course Code
6
Trimester and Summer, 2021
7
Year
Pre-requisites
EEE 301, EEE 406, Math 101, Math 301
8
Status
Core EEE Course
9
Credit Hours
1.5
10 Section
EEE 404/EEE 302
Eve
11 Class Hours
12 Class Location Room: B-908 (Simulation Lab.)
13 Course website
14 Name (s)
of
Academi
c staff /
Instructo
r(s)
Shahriar Mahmud Kabir
15 Contact
kabir@eee.green.edu.bd
16 Office
Room # 507, Building-B
17 Counselling
Hours
18 Text Book
Wednesday 6:00-8:00 PM
19 Reference
20 Equipment &
Aids
Steven C. Chapra & Raymond P. Canale, Numerical Methods for Engineers,
Sixth Edition
•Applied Numerical Methods with MATLAB (for Engineers & Scientists)
(Special Indian Edition),
Steven C. Chapra
•Numerical Methods,
S. Balachandra Rao, C.K.Shantha
Bring your notebook and calculator. Equipment will be provided in the
laboratory and MATLAB R2020a software is installed in the respective
laboratory computers. Do collect the software named ‘MATLAB R2020a´
for home practice.
Page |5
21 Course
Rationale
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
and how to analyse them. It is a pre-requisite for many other courses in
EEE.
22 Course
Description
Numerical Technique Lab. is an attractive course for the arenas control
system, communication, solid-state design, robotics, mechatronics,
Aeronautics etc. Its applications are quite widely seen. This course will
discuss in advance level about the fundamental and primitive ideas of control
system, signals, systems and a brief application about them in Digital domain.
The course is designed to provide the background of the following topics
23 Course
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
After the end of this course, the students will be able to:
24 Learning
Outcomes
25 Teaching
Methods
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.
Lecture, Laboratory hardware and software experiments, Project
Developments.
Page |6
26 Topic Outline
Class
Topics Or
CLOs
1
Assignments
Introduction
to MATLAB (PartA)
1,2,4
2
3
4
5
3
Laboratory
Experiment
1,2,3,4
Laboratory
Experiment
1,2,3,4
Laboratory
Experiment
1,2,3,4
Laboratory
Experiment
Introduction to MATLAB (Part-B)
Iterative Processes For Root
Finding (Iterative Method,
Aitken’s ∆² Acceleration
Method, Bisection Method)
Solutions to Non-Linear Equations
(Secant Method & Regula Falsi
Method)
Interpolation by NewtonGregory forward difference
formula
Reading Activities
Reference
Laboratory
Experiment
1,2,3,4
6
Interpolation by Newton-Gregory
backward difference formula
7
MID TERM EXAMINATION
Quiz, Lab
test, Viva
8
Numerical Differentiation
Laboratory
Experiment
(Based on Newton-Gregory Forward
1,2,3,4
& Backward Differences)
9
Numerical Differentiation (Based
on Lagrange Interpolation) &
1,2,3,4
Laboratory
Experiment
Laboratory
Experiment
Numerical Integration (Based on
Simple Trapezium Rule)
10
11
12
Numerical Integration By
Simpson's 1/3, 3/8th Rule &
Romberg Integration
Solution of system of Linear
Equations By a direct method
(LU Decomposition) & an
indirect method (Jacobi or
Gauss Seidel Method)
FINAL TERM
EXAMINATION (Written Lab
Exam, Viva, Performance Test)
13
Project presentation
1,2,3,4
1,2,3,4
Laboratory
Experiment
Laboratory
Experiment
Quiz, Lab
test, Viva
1,2,3,4
Presentation
and Report
Submission
Page |7
27
Assessment
Methods
28 Grading Policy
29 Additional
Course Policies
Assessment Types
Attendance
Lab Report
project/experimental/quiz/simulation test
VIVA
Final Exam
Total
Letter Grade
A+ (Plus)
A (Plain)
A- (Minus)
B+ (Plus)
B (Plain)
B- (Minus)
Marks %
80-100
75-79
70-74
65-69
60-64
55-59
Grade Point
4.00
3.75
3.50
3.25
3.00
2.75
Marks
10%
20%
25%
15%
30%
100%
Letter Grade
C+ (Plus)
C (Plain)
D (Plain)
F (Fail)
I*
W*
Marks%
50-54
45-49
40-44
<40
-
Grade Point
2.50
2.25
2.00
0.00
Incomplete
Withdrawal
1. Lab Reports: Report on previous Experiment must be submitted
before the beginning of new experiment. A bonus may be obtained if a
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
30
Additional Info.
1. Academic Calendar Summer 2021:
http://www.green.edu.bd/academics/academic-calendar
2. Academic Information and Policies:
http://www.green.edu.bd/academics/academic-rules-a-regulations
3. Grading and Performance Evaluation:
http://www.green.edu.bd/academics/academic-rules-a-regulations
4. Proctorial Rules: http://www.green.edu.bd/administrator/proctorsoffice
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.
2.
Desktop PC
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.
2.
Desktop PC
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
2
3
1
2
3
1
2
3
1
2
3
1
2
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
𝑊 = [55
−70
− 12
95
5
30
200 ]
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:
𝑥
|e𝑎 | = | 𝑖+1
−𝑥𝑖
𝑥𝑖+1
| 100%
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
and, namely xmid =
xlow + xup
. 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 (
1x10-4
𝑥𝑢𝑝 −𝑥𝑙𝑜𝑤
2
) has been reduced to a size < tolerance. Tips: tolerance shall be
P a g e | 23
List of Equipment:
1.
2.
Desktop PC
Software MATLAB R2020a
Procedure:
Iterative Process Steps:
1.
2.
3.
4.
The first step choice an initial approximation 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = 𝑥𝑜𝑙𝑑
Evaluate 𝑓(𝑥) equation and determine the value of 𝑓(𝑥𝑜𝑙𝑑 )
Let 𝑥𝑛𝑒𝑤 = 𝑓(𝑥𝑜𝑙𝑑 )
𝑥
−𝑥𝑜𝑙𝑑
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
1
2
3
4
5
6
7
8
9
10
.
.
.
42
𝒙𝒏𝒆𝒘
0.000000000000000
1.000000000000000
0.540302305868140
0.857553215846393
0.654289790497779
0.793480358742566
0.701368773622757
0.763959682900654
0.722102425026708
0.750417761763761
0.731404042422510
.
.
.
0.739085108473799
%𝒆𝒓𝒓𝒐𝒓
100
85.081571768092545
36.994894790888438
31.066268846098438
17.541778660452646
13.133117495954123
8.192959743667133
5.796581817655344
3.773276457436351
2.599619121364808
.
.
.
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.
2.
3.
4.
The first step choice an initial approximation 𝑥𝑖𝑛𝑖𝑡𝑖𝑎𝑙 = 𝑥1
Evaluate 𝑓(𝑥) equation and determine the values 𝑥2 = 𝑓(𝑥1 ) , 𝑥3 = 𝑓(𝑥2 )
Determine the value of ∆𝑥2 = 𝑥3 − 𝑥2
Determine the value of ∆2 𝑥1 = 𝑥3 − 2𝑥2 + 𝑥1
(∆𝑥 )2
5. Determine the value of 𝐴𝑖𝑡𝑘𝑒𝑛, 𝑎 = 𝑥3 − ∆2 𝑥2
6. Check accuracy = |𝑎 − 𝑥3 |
1
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
1
2
3
4
5
6
7
8
9
10
.
.
.
42
𝑨𝒊𝒕𝒌𝒆𝒏′ 𝒔 𝑹𝒐𝒐𝒕 (𝒂)
𝒙𝒏𝒆𝒘
0.000000000000000
1.000000000000000
0.540302305868140
0.857553215846393
0.654289790497779
0.793480358742566
0.701368773622757
0.763959682900654
0.722102425026708
0.750417761763761
0.731404042422510
.
.
.
0.739085108473799
0.685073357326045
0.738660156167714
0.739085106356719
0.739085133215161
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 𝑥𝑚𝑖𝑑𝑛𝑒𝑤 =
6.
7.
8.
9.
𝑥𝑢𝑝 + 𝑥𝑙𝑜𝑤
𝑥𝑢𝑝 − 𝑥
2
𝑙𝑜𝑤
Check 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 =
2
If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 > 1 then change 𝑥𝑚𝑖𝑑𝑜𝑙𝑑 = 𝑥𝑚𝑖𝑑𝑛𝑒𝑤 and repeat steps (2) to (6)
Continue evaluating steps (2) to (6) until difference has been reduced to a value < 1
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) 𝑥 = (4) [(2𝑥 2 − 1)/(𝑥 − 1)] ; 𝑥0 = 0.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
That is x = xup −
f ( xup )( xlow − 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
𝑥1 = 𝑥0 −
𝑓(𝑥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 )
f ( x k −1 ) − 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 ) ,
x k +1 = x k −
f ( 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.
2.
Desktop PC
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.
5.
6.
7.
Find 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 = |𝑥2 − 𝑥1 |
If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 > 1 then repeat steps (2) to (4)
Continue evaluating steps (2) to (4) until difference has been reduced to a value < 1
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
4.
5.
6.
7.
2
Find 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 = |𝑥3 − 𝑥2 |
If 𝑑𝑖𝑓𝑓𝑒𝑟𝑒𝑛𝑐𝑒 > 1 then repeat steps (2) to (4) and change 𝑥1 = 𝑥2 , 𝑥2 = 𝑥3
Continue evaluating steps (2) to (4) until difference has been reduced to a value < 1
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!
ℎ2 +…………..(1)
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
2!
3!
𝑘 (𝑘 − 1)(𝑘 − 2)(𝑘 − 3) 4
+
∆ 𝑓0
4!
𝑘 (𝑘 − 1)(𝑘 − 2)(𝑘 − 3)(𝑘 − 4) 5
+
∆ 𝑓0
5!
𝑓𝑥 = 𝑓0 + 𝑘∆𝑓0 +
𝑓(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!
ℎ2 −…………..(1)
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.
2.
Desktop PC
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
2!
3!
𝑘 (𝑘 + 1)(𝑘 + 2)(𝑘 + 3) 4
+
∇ 𝑓5
4!
𝑘 (𝑘 + 1)(𝑘 + 2)(𝑘 + 3)(𝑘 + 4) 5
+
∇ 𝑓5
5!
𝑓𝑥 = 𝑓5 + 𝑘 ∇𝑓5 +
𝑓(4.12) = 17.391338127360001 (𝐴𝑛𝑠)
Steps:
1.
2.
3.
4.
At first create initial approximation matrix 𝑖, 𝑥𝑖 & 𝑓𝑖
Evaluate the matrices ∇𝑓𝑖 , ∇2 𝑓𝑖 , ∇3 𝑓𝑖 , ∇4 𝑓𝑖 & ∇5 𝑓𝑖 as required to solve the equation
Write MATLAB expression of the formula 𝑓𝑥 with inputs 𝑥, 𝑥𝑛 , ℎ, 𝑘
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 NewtonGregory backward difference formula.
3. Familiar with the merits and demerits of numerical differentiation by NewtonGregory 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!
ℎ2 +…………..(1)
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 − 𝑓𝑖
The second order forward difference ∆ 𝑓𝑖 is defined as
2
∆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
2!
3!
𝑘 (𝑘 − 1)(𝑘 − 2)(𝑘 − 3) 4
+
∆ 𝑓0
4!
𝑘 (𝑘 − 1)(𝑘 − 2)(𝑘 − 3)(𝑘 − 4) 5
+
∆ 𝑓0
5!
𝑓𝑥 = 𝑓0 + 𝑘∆𝑓0 +
𝑓(4.12) = 17.391338127360001
Now, [ From, "Numerical Methods" by S.Balachandra Rao, Equation - 5.5 ]
P a g e | 45
𝑑
𝑑 (𝑓𝑥 ) 𝑑𝑘 1 𝑑 (𝑓𝑥 )
(𝑓𝑥 ) =
∙
= ∙
𝑑𝑥
𝑑𝑘 𝑑𝑥 ℎ 𝑑𝑘
𝑑
𝑑
(𝑘(𝑘 − 1))
(𝑘 (𝑘 − 1)(𝑘 − 2))
1
𝑑
𝑑𝑘
𝑑𝑘
′
2
∴ 𝑓𝑥 = [ (𝑘 ) ∙ ∆𝑓0 +
∙ ∆ 𝑓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.
2.
3.
4.
At first create initial approximation matrix 𝑖, 𝑥𝑖 & 𝑓𝑖
Evaluate the matrices ∇𝑓𝑖 , ∇2 𝑓𝑖 , ∇3 𝑓𝑖 , ∇4 𝑓𝑖 & ∇5 𝑓𝑖 as required to solve the equation
′
Write MATLAB expression of the formula 𝑓𝑥 with inputs 𝑥, 𝑥𝑛 , ℎ, 𝑘
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
A
O
π/4
One Strip
Two Strip
The above formula is called the Trapezium Rule.
X
P a g e | 50
List of Equipment:
1.
2.
Desktop PC
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
𝑓 = 𝑒 −𝑥
1.0000
0.9900
0.9608
0.9139
0.8521
0.7788
0.6977
0.6126
0.5273
X
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
2
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
ℎ = 𝑛 2 0 = 2 = 0.4, for two strip
𝑥 −𝑥
0.8−0
𝑥𝑛 −𝑥0
4
0.8−0
ℎ = 𝑛4 0 =
ℎ=
8
=
8
= 0.2, for four strip
= 0.1, for eight strip
For one strip (i.e. h=0.8),
𝐼11 =
ℎ
0.8
(𝑓0 + 𝑓1 ) =
(1 + 0.5273) = 0.6109
2
2
For two strip (i.e. h=0.4),
𝐼21 =
ℎ
0.4
(𝑓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
𝝅/𝟒
Ans. 0.6704, 0.6980, 0.7048, 0.7065
∫𝒐 𝒄𝒐𝒔𝒙𝒅𝒙 up to eight strips.
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
t3
dt.
0 et − 1
(t ) =
x
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
f ( x)dx = 3 ( f + 4 f + f )
1
2
3
x1
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
( fi + 4 fi +1 + fi + 2 )
i =1,3,5,..., n −1 3
f ( x)dx =
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
f ( x)dx = 8 ( f + 3 f + 3 f + f )
1
2
3
4
x1
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 i + 3 f i +1 + 3 f i + 2 + f i +3 )
i =1,4,7,..., n − 2 3
f ( x)dx =
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.
2.
Desktop PC
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
𝑓 = 𝑒 −𝑥
1
0.9901
0.9608
0.9139
0.8521
0.7788
0.6977
0.6126
0.5273
X
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
2
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
ℎ = 𝑛 2 0 = 2 = 0.4, for two strip
𝑥 −𝑥
0.8−0
𝑥𝑛 −𝑥0
4
0.8−0
ℎ = 𝑛4 0 =
ℎ=
8
=
8
= 0.2, for three strip
= 0.1, for four strip
For one strip (i.e. h=0.8),
𝐼11 =
ℎ
0.8
(𝑓0 + 𝑓1 ) =
(1 + 0.5273) = 0.6109
2
2
For two strip (i.e. h=0.4),
𝐼21 =
ℎ
0.4
(𝑓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
𝐼𝑗1 (𝑗 = 1,2,3,4)
𝐼11 = 0.6109
𝐼21 = 0.6463
𝐼31 = 0.6549
𝐼41 = 0.6570
h
0.8
0.4
0.2
0.1
Now From Romberg’s Formula:
𝐼𝑗𝑛 =
𝐼22 =
4𝑛−1 𝐼𝑗(𝑛−1) − 𝐼(𝑗−1)(𝑛−1)
; 𝑗 = 𝑛, 𝑛 + 1, …
4𝑛−1 − 1
4𝐼21 − 𝐼11
,
3
𝐼33 =
𝐼32 =
4𝐼31 − 𝐼21
,
3
42 𝐼32 − 𝐼22
,
15
𝐼43 =
𝐼42 =
4𝐼41 − 𝐼31
3
42 𝐼42 − 𝐼32
15
43 𝐼43 − 𝐼33
𝐼44 =
63
ℎ2
𝐼11
𝐼21
𝐼31
𝐼41
ℎ4
ℎ6
ℎ8
𝐼22
𝐼32
𝐼42
𝐼33
𝐼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
2
3
4
5
6
7
1
𝑥
1
0.5
0.33
0.25
0.2
0.17
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
2
3
4
5
6
7
𝑓(𝑥) =
1
0.5
0.33
0.25
0.2
0.17
0.14
1
𝑥
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)
𝑥
−𝑥
𝑥𝑛 −𝑥0
3
ℎ = 𝑛+1𝑛 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
𝝅/𝟒
Ans. I22=0.7072, I33=0.7071, I44=0.7071
∫𝒐 𝒄𝒐𝒔𝒙𝒅𝒙 up to eight strips.
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
a
A = 21
...
aM 1
a12
a22
...
aM 2
a1N
... a2 N
... ...
... aMN
...
x1
x
x= 2
..
xN
b1
b
b= 2
..
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)
a
a
a
a
(a21 − 11 a21 ) x1 + (a22 − 12 a21 ) x2 + (a23 − 13 a21 ) x3 = (a24 − 14 a21 )
a11
a11
a11
a11
Let,
a21
= k2 , then
a11
(a21 − k2 a11 ) x1 + (a22 − k2 a12 ) x2 + (a23 − k 2 a13 ) x3 = (a24 − k 2 a14 )
Similarly multiplying equation (A) by
a31
= 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
2
for i = (n − 1) to 1 in step of -1 do
P a g e | 65
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
It should be noted that interchange of equations does not affect the solution.
P a g e | 66
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
pk
3
for m = (k + 1) to n in steps of 1 do
4
if ( amk max) then
5
max amk
6
pm
7
endif
endfor
8
if ( p ~ = k )
for q = k to (n + 1) in steps of 1 do
9
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:
7 + x2k − x3k
x =
4
21 + 4 x1k +1 + x3k
x2k +1 =
8
15 + 2 x1k +1 − x2k +1
x3k +1 =
5
k +1
1
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
jk
List of Equipment:
1.
2.
Desktop PC
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) GaussJordan elimination with pivoting
2 x1 + 4 x2 − 6 x3 = −4
(A)
x1 + 5 x2 + 3x3 = 10
x1 + x2 + 6 x3 = 7
(B)
− x1 + 2 x2 + 9 x3 = 2
x1 − 2 x2 + 3x3 = 10
x1 + 3x2 + 2 x3 = 5
4 x1 + 8 x2 + 4 x3 = 8
(C)
x1 + 5 x2 + 4 x3 − 3 x4 = −4
x1 + 4 x2 + 7 x3 + 2 x4 = 10
x1 + 3 x2 − 2 x4 = −4
4. Solve the following equations using Gauss-Seidel iteration process:
(A)
8 x1 − 3x2 = 10
− x1 + 4 x2 = 6
(B)
5 x1 − x2 + x3 = 10
(C)
2 x1 + 8 x2 − x3 = 11
− x1 + x2 + 4 x3 = 3
4 x − y = 15
x + 5y = 9
2 x + 8 y − z = 11
(D)
5 x − y + z = 10
−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
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )