Eee404 - Eee302 - Lab Sheet Gub
Eee404 - Eee302 - Lab Sheet Gub
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
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 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.
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
Year
7 Pre-requisites EEE 301, EEE 406, Math 101, Math 301
10 Section Day
13 Course website
14 Name (s) Shahriar Mahmud Kabir
of
Academi
c staff /
Instructo
r(s)
15 Contact [email protected]
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.
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.
26 Topic Outline
Class Topics Or CLOs Reading Activities
Reference
1 Assignments
Introduction to MATLAB (Part- Laboratory
A) 1,2,4 Experiment
13 Presentation
1,2,3,4
Project presentation and Report
Submission
Page |7
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
COURSE TITLE:
COURSE CODE:
EXPERIMENT NO.:
EXPERIMENT NAME:
DATE OF PERFORMANCE:
DATE OF SUBMISSION:
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
List of Equipment:
1. Desktop PC
2. Software MATLAB R2020a
Procedure:
MATLAB Command:
>> a=10; b=20; c=a+b
>> 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:
B. Think about A and B are the last two digits of your Class Roll:
Reference Book:
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:
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
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:
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
Example-4:
B=[0 20 90; 12 -34 45]
B(2,3)
B(1,2)
B(2,2)
Example-5:
W=[1 2 3; -4 -5 -6; 0 1 0]
W' %Transpose
det(W) %Determinant
inv(W) %Inverse
Control Statement
For Loop
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
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
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
Example-9:
a=5;
b=6;
if a~=b
disp('unequal')
else
disp('equal')
P a g e | 18
end
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
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:
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])
Report Question:
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(𝐵)
17x1+2x2+1x3+5x4=4
5x1+6x2+7x3+1x4=-1
9x1-10x2+11x3+12x4=10
13x1+14x2+15x3-9x4 = 6
Reference Book:
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:
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
(∆𝑥𝑛 )2
𝐴𝑖𝑡𝑘𝑒𝑛, 𝛼 = 𝑥𝑛+1 −
∆2 𝑥𝑛−1
Here,
∆𝑥𝑛 = 𝑥𝑛+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.
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:
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.
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
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.
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
Reference Book:
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:
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:
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
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 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 )
𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 −
𝑓 ′ (𝑥𝑛 )
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
List of Equipment:
1. Desktop PC
2. Software MATLAB R2020a
Procedure:
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:
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:
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.
𝑓′′(𝑥𝑖 )
𝑓(𝑥𝑖−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)
ℎ
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.
∆𝑓𝑖 = 𝑓𝑖+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 𝑓𝑖
List of Equipment:
1. Desktop PC
P a g e | 34
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,
𝑓(4.12) = 17.391338127360001(𝐴𝑛𝑠)
Steps:
Report Question:
Reference Book:
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:
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.
𝑓′′(𝑥𝑖 )
𝑓(𝑥𝑖−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)
ℎ
∇𝑓𝑖 = 𝑓𝑖 − 𝑓𝑖−1
P a g e | 38
∇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
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,
Steps:
Report Question:
Reference Book:
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:
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.
𝑓′′(𝑥𝑖 )
𝑓(𝑥𝑖−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)
ℎ
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.
∆𝑓𝑖 = 𝑓𝑖+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 𝑓𝑖
List of Equipment:
1. Desktop PC
P a g e | 44
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,
𝑓(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
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
Steps:
Report Question:
Reference Book:
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:
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:
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
,
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
List of Equipment:
1. Desktop PC
2. Software MATLAB R2020a
Procedure:
a) Find 𝒇′ (𝟎. 𝟏𝟐) from the following data using Lagrange Polynomial Interpolation:
Solution:
𝑓 ′ (0.12) = 0.9927
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
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
ℎ 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
ℎ
𝐼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
ℎ
𝐼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:
Report Question:
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:
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:
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
4𝑛 𝐼𝑗(𝑛−1) − 𝐼(𝑗−1)(𝑛−1)
𝐼𝑗𝑛 = ; 𝑗 = 𝑛, 𝑛 + 1, …
4𝑛 − 1
P a g e | 55
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
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).
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 )
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
ℎ 0.4
𝐼21 = (𝑓0 + 2𝑓1 + 𝑓2 ) = (1 + 2 ∗ 0.8521 + 0.5273) = 0.6463
2 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
ℎ
𝐼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
43 𝐼43 − 𝐼33
𝐼44 =
63
ℎ2 ℎ4 ℎ6 ℎ8
𝐼11
𝐼21 𝐼22
𝐼31 𝐼32 𝐼33
𝐼41 𝐼42 𝐼43 𝐼44
Steps:
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
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:
Report Question:
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:
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:
REMARKS
P a g e | 61
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:
… … … …
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.
• 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,
Finding Solution
There are so many ways to solve this set of equations. Below are some important methods.
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:
x = A\b;
To illustrate the method let us consider three equations with three unknowns:
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
a31
Similarly multiplying equation (A) by = k3 and subtracting from (C), we get
a11
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.
Procedure:
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
endfor
endfor
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.
a33 x3 = a34
From the above upper triangular form of equations, the values of unknowns can be obtained
by back substitution as follows:
x3 = a34 / a33
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
endfor
Pivoting
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
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:
1 max akk
2 pk
3 for m = (k + 1) to n in steps of 1 do
5 max amk
6 pm
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
There are several iterative methods for the solution of linear systems. One of the efficient
iterative methods is the Gauss-Seidel method.
4 x1 − x2 + x3 = 7
4 x1 − 8 x2 + x3 = −21
−2 x1 + x2 + 5 x3 = 15
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.
N
akk akj for k = 1, 2,...N
j =1
jk
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 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
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:
2) Numerical Methods,
S. Balachandra Rao, C.K.Shantha