0% found this document useful (0 votes)
28 views72 pages

EE407 - Chap1

Uploaded by

mohdhaal2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views72 pages

EE407 - Chap1

Uploaded by

mohdhaal2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Numerical Methods for

Electrical Engineers (EE407)

PREPARED BY: DR. SAMIR BENDOUKHA & DR. NABIL BARHOUMI

RESPONSIBLE FOR THE COURSE: DR. NABIL BARHOUMI

EMAIL: BARHOUMI_NABIL@YAHOO.FR

LEVEL/YEAR AT WHICH THIS COURSE IS OFFERED


LEVEL 9/ YEAR 5
PRE-REQUISITES FOR THIS COURSE
CS205
L01: Introduction to EE407
2

 Overview of this lecture:

 About the course.


 Contents.
 Grade distribution.
 General guidelines.
 Course policies.

Numerical Methods for EE (EE407) | Main


Course Objectives
3

 Upon completion of this course, the student should be able to:


 Discuss the effect of numerical errors on computer accuracy.
 Design a robust algorithm for solving different engineering problems
including:
 Roots of equations.
 Solutions to systems of linear equations.
 Fourier Analysis.
 Solutions to ODE.
 Curve fitting… etc.
 Develop and implement the necessary Matlab code for the proposed
algorithms.
 Discuss potential areas of improvements in the proposed solutions.

Numerical Methods for EE (EE407) | Main


Numerical Methods for EE (EE407)
4

 Prerequisites for this course:


 CS205: Computer Programming.

 The course contains 3 credit hours:


2 lecture hours/week (2 units)
3 lab hous/week (1 unit)

 Textbook:
Chapra and Canale, Numerical Methods for Engineers, 7th
Edition, McGraw-Hill, 2015.

Numerical Methods for EE (EE407) | Main


Course Contents
5

 EE407 gives an overview of numerical methods.


 We will cover 7 chapters:
 Chapter 𝟏: Modelling, Computers, and Matlab programming.
 Chapter 𝟐: Roots and Optimization. Includes bracketing methods
such as bisection and the false position method, the fixed point
method, Newton-Raphson, Secant, Brent, and applications to
polynomials.
 Chapter 𝟑: Linear System and Curve Fitting. Includes Gauss
elimination, LU decomposition, matrix inversion, Gauss-Seidel, and
applications. It includes also the least squares linear fit (LSLF),
linear and polynomial interpolation, Newton’s method, and
applications.
 Chapter 𝟒: Numerical Differentiation and Integration. Includes
Newton-Cotes integration, Romberg integration, numerical
differentiation, and applications.

Numerical Methods for EE (EE407) | Main


Course Contents
6

 Chapter 𝟓: Fourier Analysis.


 Chapter 𝟔: Eigen Vectors.
 Chapter 𝟕: Numerical Integration of Ordinary Differential
Equations (ODEs). Includes a review of ODEs and analytic
methods as well as an introduction into numerical methods for
ODEs.

Numerical Methods for EE (EE407) | Main


Grade Distribution
7

 This course will be evaluated by:


Assessment Description Date Credit
3 quizzes at the dates shown
above. Each quiz lasts for 20 Weeks 4, 6,
Quizzes 15%
minutes and counts as 5% of the and 12
overall mark.
Mid-Term A one hour exam in the middle of
Week 8 25%
Exam the semester
11 lab sessions throughout the
Lab work / 10%
semester
A one hour laboratory exam
Lab Exam Week 16 10%
towards the end of the semester
A two and a half hour exam at the End of
Final Exam 40%
end of the semester. Term

Numerical Methods for EE (EE407) | Main


Course Policies
8

 Attendance is mandatory for all lectures and lab sessions.


 Students not attending will have to provide an excuse.
Excuses are only granted in extreme situations that can be
substantiated by the student.
 Students will be penalized for their lack of attendance.
 According to the faculty’s regulations, if a student fails to
attend 75% of the mandatory credit hours, he forfeits the
course.

Numerical Methods for EE (EE407) | Main


Course Policies
9

 The University requires each student to act with honesty


and integrity, and respect the rights of others to carrying
out all academic assignments.
 Appropriate classroom behavior means coming on time
ready to work, being awake all over the session and
avoiding disruptive side conversations. It also includes
following instructions given by instructors, and avoiding
consumption of food and beverage inside the classroom.

Numerical Methods for EE (EE407) | Main


End of Lecture!
10

Any Questions?

Numerical Methods for EE (EE407) | Main


Chapter I: Modelling, Computers,
& Matlab Programming

LECTURES:

2. MODELLING AND PROBLEM SOLVING


3. MATLAB PROGRAMMING
4. APPROXIMATIONS & ROUND-OFF ERRORS

Numerical Methods for EE (EE407) | Main


L02: Modelling & Problem Solving
12

 Outline of the lecture:

 Engineering problem solving.


 Problem solving with computers.
 Modelling of physical systems.
 Analytic solution of ODE.
 Numerical solution of ODE.
 Conservation laws for modelling.

Numerical Methods for EE (EE407) | Main


Non-Computer Problem Solving
13

 Before computers, engineering problem solving was


approached in one of three ways:
 Solutions were derived for some problems using analytical, or
exact, methods. These solutions were often useful and provided
excellent insight into the behaviour of some systems. However,
analytical solutions can be derived for only a limited class of
problems.
 Graphical solutions were used to characterize the behaviour of
systems. These graphical solutions usually took the form of
plots. Although graphical techniques can often be used to solve
complex problems, the results are not very precise and the
methods are very tedious.

Numerical Methods for EE (EE407) | Main


Non-Computer Problem Solving
14

 Calculators and slide rules


were used to implement
numerical methods
manually. These methods
are theoretically sound but
are usually slow and tedious
and involve numerical
rounding, which reduces
accuracy.
 With computers, things
became a lot easier and we
can now solve more
complicated problems.
Numerical Methods for EE (EE407) | Main
Why Study Numerical Analysis?
15

 Computers are fast and can solve very complicated


problems.
 Numerical methods can handle very large systems of
equations, nonlinearities, and geometries.
 Engineers need to use ready packed programs that involve
numerical analysis and thus must understand the basics of
numerical methods to use the programs intelligently.
 Many problems need customized programs and algorithms
such as in control.
 Numerical methods reinforce one’s understanding of
mathematics and programming/algorithms.

Numerical Methods for EE (EE407) | Main


Basics of Modelling:
16

 A mathematical model is an
equation/function that expresses a
physical system. We may write:
𝐷𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒
𝑖𝑛𝑑𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡 𝑓𝑜𝑟𝑐𝑖𝑛𝑔
=𝑓 , 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠,
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛𝑠
 The dependent variable represents the
state of the system.
 Independent variables includes time and
space.
 Parameters represent the system’s
properties and composition.
 Forcing functions are external influences.
Numerical Methods for EE (EE407) | Main
Example 1
17

 Newton’s second law of motion states that


𝐹 = 𝑚𝑎
where 𝐹 is the net force acting on a body
(𝑁), 𝑚 is the body’s mass (𝑘𝑔), and 𝑎 is its
acceleration (𝑚/𝑠 2 ).
 A parachutist is subjected to two
contradicting forces yielding the
differential equation
𝑑𝑣 𝐹
=
𝑑𝑡 𝑚
with 𝑣 𝑡 being the velocity.

Numerical Methods for EE (EE407) | Main


Example 1
18

 The net force is of the form


𝐹 = 𝐹𝐷 + 𝐹𝑈 where 𝐹𝐷 = 𝑚𝑔
with 𝑔 being the acceleration of gravity (9.81𝑚/𝑠 2 ).
 Similarly, we can write
𝐹𝑈 = −𝑐𝑣
with 𝑐 being a proportionality constant (drag coefficient, 𝑘𝑔
/𝑠).
 Substituting yields
𝑑𝑣 𝑚𝑔 − 𝑐𝑣 𝑐
= =𝑔− 𝑣
𝑑𝑡 𝑚 𝑚
 This is an ODE model of the motion of the parachutists.

Numerical Methods for EE (EE407) | Main


Example 1
19

 Solving the ODE yields


𝑔𝑚 𝑐
−𝑚𝑡
𝑣 𝑡 = 1−𝑒
𝑐
 This gives us a model of
the motion of the
parachutist with respect to
time.
 Given a mass of 68.1𝑘𝑔
and a drag coefficient of
12.5𝑘𝑔/𝑠, we have the
following velocity plot:

Numerical Methods for EE (EE407) | Main


Example 1
20

 Instead of the analytic solution,


we can use a numerical one
instead.
 We can use a finite difference
approximation of the derivative
in
𝑑𝑣 𝑐
=𝑔− 𝑣
𝑑𝑡 𝑚
which is of the form
𝑑𝑣 Δ𝑣 𝑣 𝑡𝑖+1 − 𝑣 𝑡𝑖
≈ =
𝑑𝑡 Δ𝑡 𝑡𝑖+1 − 𝑡𝑖

Numerical Methods for EE (EE407) | Main


Example 1
21

 Substituting yields
𝑐
𝑣 𝑡𝑖+1 = 𝑣ถ
𝑡𝑖 + 𝑔 − 𝑣 𝑡𝑖 𝑡𝑖+1 − 𝑡𝑖
𝑚
new value old value step size
slope

 This gives us a recursive definition


of the solution at discrete points
in time. The closer the points are
(small step size) the more
accurate our representation is.
 This produces an approximation
of the real velocity plot.

Numerical Methods for EE (EE407) | Main


Matlab Code:
22

g = 9.81;
c = 12.5;
m = 68.1;
T = [0 15];
dt = 0.001;
t = T(1):dt:T(2);
Nt = length(t);
v = zeros(1,Nt);
for n = 2:Nt
v(n) = v(n-1)+(g-c/m*v(n-1))*dt;
end
plot(t,v,'b');

Numerical Methods for EE (EE407) | Main


Conservation Laws:
23

 Most engineering models are based on conservation laws


including:
 Conservation of mass:

 Conservation of momentum:

Numerical Methods for EE (EE407) | Main


Conservation Laws:
24

 Conservation of electric charge (Kirchhoff's current law):

 Conservation of electrical energy (Kirchhoff’s voltage law):

Numerical Methods for EE (EE407) | Main


End of Lecture!
25

Any Questions?

Numerical Methods for EE (EE407) | Main


L03: Matlab Programming
26

 Outline of the lecture:

 What is a computer? What are its components?


 Algorithms and flowcharts.
 Matlab programming.
 Data types and structures.
 Arithmetic, relational, and logical operations.
 Conditional statements, loops, and functions.

Numerical Methods for EE (EE407) | Main


What is a Computer?
27

 A computer in the modern sense can be defined as: “an


electronic device which is capable of receiving information
(data) in a particular form and of performing a sequence of
operations in accordance with a predetermined but variable
set of procedural instructions (program) to produce a result
in the form of information or signals”.

Numerical Methods for EE (EE407) | Main


Algorithms
28

 Before writing a detailed program, it is important to plan


the steps necessary to achieve the desired result.
 An algorithm is the sequence of steps needed to solve a
problem.
 It can be specified as:
 Pseudocode - specifies the steps of algorithm using
essentially natural language of superimposed control structure.
 Flowchart - a traditional graphical tool with standardized
symbols. Show the sequence of steps in an algorithm.

Numerical Methods for EE (EE407) | Main


Flowcharts
29

Numerical Methods for EE (EE407) | Main


Example
30

 Recall example 1.
Start

Input
𝑴𝟏, 𝑴𝟐, 𝑴𝟑, 𝑴𝟒
 Detailed Algorithm
 Step 1: Input
𝑮(𝑴𝟏 + 𝑴𝟐 + 𝑴𝟑 + 𝑴𝟒)/𝟒
𝑀1, 𝑀2, 𝑀3, 𝑀4
 Step 2: G ← (𝑀1 + 𝑀2
+ 𝑀3 + 𝑀4)/4
N Is Y
𝑮 < 𝟓𝟎  Step 3: if (G < 50) then
Print “FAIL”
Print
“PASS”
Print
“FAIL”
else
Print “PASS”
end if
Stop

Numerical Methods for EE (EE407) | Main


Modular Programming
31

 Imagine how difficult it would be to study a textbook that


had no chapters, sections, or paragraphs. Breaking
complicated tasks or subjects into more manageable parts is
one way to make them easier to handle.
 In modular programming, we make use of conditional
statements, loops, and different types of functions.
 Many mathematical programming packages exist today
such as Excel, Matlab, Mathematica, Maple, MathCAD, and
many more.
 Throughout this course, we will write Matlab code to
implement the numerical algorithms we study.

Numerical Methods for EE (EE407) | Main


Data Types in Matlab
32

 There are seven main types of data in Matlab:

Numerical Methods for EE (EE407) | Main


Arithmetic Operations
33

 Matlab like any other programming language provides the


programmer with a range of arithmetic, relational, and
logical operators commonly used in mathematics.
 The main arithmetic operators are:
Operator Sign Example
Assignment = x = 2;
Addition + x = 2 + 3; (= 5)
Subtraction - x = 5 - 3; (= 2)
Multiplication * x = 2 * 3; (= 6)
Division / or \ x = 2 / 3; (or 3 \ 2)
Power ^ x = 3^2; (= 9)

 Note that inserting extra spaces doesn’t affect the operation.

Numerical Methods for EE (EE407) | Main


Relational Operators
34

 Relational operators are used to compare quantities and


enforce conditions in the code.
 These operators return a logical (true = 1, or false = 0).
 The following operators are allowed in Matlab:

Operator Sign Example


Equal == if(x == y)
Not equal ~= if(x ~= y)
Less than < if(x < y)
Less or equal <= if(x <= y)
Greater than > if(x > y)
Greater or equal >= if(x >= y)

Numerical Methods for EE (EE407) | Main


Logical Operators
35

 Recall the logical data type from the previous lecture (true =
1, or false = 0).
 Matlab provides a range of logical operators, including:
Operator Sign Example
Logical AND & if (.. & ..)
Logical AND with short-circuiting && if (.. && ..)
Logical OR | if (.. | ..)
Logical OR with short-circuiting || if (.. || ..)
Logical NOT ~ if (~x)
Logical exclusive or (XOR) xor if (.. xor ..)
True if all elements are nonzero all B = all(A);
True if any element is nonzero any B = any(A);

Numerical Methods for EE (EE407) | Main


Operator Precedence
36

 Also recall the operator precedence discussed earlier in the


course:

Numerical Methods for EE (EE407) | Main


Vectors and Matrices
37

 Matlab treats data in three different types:


 Scalars: single quantity, e.g. double.
 Vectors: a one-dimensional array of data (size 1 × 𝑛 or 𝑛 × 1).
 Matrices: a two-dimensional array of data (size 𝑚 × 𝑛).
 The elements in a row are separated by a comma or space,
whereas rows are separated by semicolons.
Row 1 2 1 3
−1 2 0 1 2 0 1.5
−2 1.5 0.5 −1
Column

 A matrix is said to be of size 𝑚 × 𝑛 (𝑚-by-𝑛) if it has 𝑚 rows


and 𝑛 columns.
Numerical Methods for EE (EE407) | Main
Elementwise Operations
38

 The same operations discussed in the previous lecture can


be performed on vectors and matrices.
 Elementwise operations are performed between elements of
a vector or matrix and the corresponding element from
another.
 Examples:
 x = [1, 2; 3, 4];
 y = [2, 3; 4, 2];
 X .* y = [2, 6; 12, 8]; (Elementwise)
 X * y = [10, 7; 22, 17]; (Cayley)
 Division and power can be done in the same way.

Numerical Methods for EE (EE407) | Main


Multiplication and Division by Scalar
39

 Vectors and matrices can be multiplied or divided by scalars


and the same way scalars are.
 Multiplication and Division by scalars are basically
elementwise operations.

 Examples:
 x = [1, 2; 3, 4];
 y = x * 3;
 z = x / 2;
 Results: y = [3, 6; 9, 12];
z = [0.5, 1; 1.5, 2];

Numerical Methods for EE (EE407) | Main


Matrix Multiplication
40

 In matrix multiplication, rows are multiplied by columns:


x

𝑐11 𝑐12 𝑎11 𝑎12 𝑏11 𝑏12


𝑪= 𝑐 𝑐22 = 𝑎21 𝑎22
21 𝑏21 𝑏22
 For instance: x

𝑐11 = 𝑎11 𝑏11 + 𝑎12 𝑏21


𝑐12 = 𝑎11 𝑏12 + 𝑎12 𝑏22
𝑐21 = 𝑎21 𝑏11 + 𝑎22 𝑏21
𝑐22 = 𝑎21 𝑏12 + 𝑎22 𝑏22

Numerical Methods for EE (EE407) | Main


Matrix Multiplication
41

 This is known as Cayley multiplication.


 There are other types of multiplication but Cayley is the
most important.
 If two matrices 𝑨 and 𝑩 of sizes (𝑚 × 𝑛) and (𝑘 × 𝑙),
respectively, are to be multiplied together, the condition 𝑛
= 𝑘 must be satisfied.
𝑛 𝑙 𝑙

𝑚 𝑨 x =𝑚 𝑪
𝑘=𝑛 𝑩

Numerical Methods for EE (EE407) | Main


Conditional Statements
42

 The general form of the if statement is:


 if condition
action 1;
elseif
action 2;
else
action 3;
end
 A condition yields either true or false.
 An action is a statement, or a group of statements, that will
be executed if the condition is true.
Numerical Methods for EE (EE407) | Main
Conditional Statements
43

 A switch statement can often be used in place of a nested


if-else or an if statement with many elseif clauses.
 The general form of the switch statement is:

Numerical Methods for EE (EE407) | Main


Loops in Programming
44

 Loops in programming are statements that allow other


statement(s) to be repeated multiple times.
 For instance, if a code is required to calculate the areas of
circles with diameters ranging from 0 to 3 in steps of 0.5.

 There are two main types of loops:


 Counted loops: repeats a specified number of times.
 Conditional loops: the number of times the code is to repeat is
not known apriori. Instead it adheres to a certain condition.

Main
The FOR Loop
45

 The first type of loops allowed in Matlab is the for loop,


which is a counted loop.
 The for loop requires an iterator to determine how many
times the code has repeated this far.
 The general form of the for loop is:
 for loopvar = range
action
end
 The variable loopvar is the iterator.
 Note that we commonly use i or j as iterators. However,
these are built in to denote the imaginary number −1

Numerical Methods for EE (EE407) | Main


The WHILE Loop
46

 The while statement is used as the conditional loop in


MATLAB.
 It is used to repeat an action when ahead of time it is not
known how many times the action will be repeated.
 The general form of the while statement is:
 while condition
action
end
 The action, which consists of any number of statement(s), is
executed as long as the condition is true.
 The condition is executed before the action is carried out.

Numerical Methods for EE (EE407) | Main


Functions
47

 Functions are pieces of code that take an input, perform a


certain action, and return an output.
 Matlab also allows the user to define their own functions.

Numerical Methods for EE (EE407) | Main


Types of Variables in a Function
48

 By default, any variable defined within a function is local to


that function, i.e. it is disposed of once we exit the function.
 There are two special types of variables:
 Global variables: can be shared between function without
having to pass them as arguments. They are generally
considered inefficient.
 Persistent variables: the value is not cleared so the next time
the function is called, the variable still exists and retains its
former value.
 An anonymous function is a very simple, one-line function:
fnhandle = @ (arguments) functionbody;

Main
Functions
49

 The (@) symbol is used to obtain the function handle,


which is a type of variable that can be used to refer to the
function.
 One reason for using function handles is to be able to pass
functions to other functions.
 It is possible to have a variable number of arguments, both
input and output arguments by means:
 nargin: number of input arguments.
 varargin: cell array containing the input arguments.
 nargout: number of output arguments.
 varargout: cell array containing the output arguments.

Numerical Methods for EE (EE407) | Main


Recursive Functions
50

 Recursion occurs when something is defined in terms of


itself.
 In programming, a recursive function is a function that calls
itself.
 Recursion is used very commonly in programming,
although many simple examples (including some shown in
this section) are actually not very efficient and can be
replaced by iterative methods (such as loops).
 For instance, take the factorial of a number defined as:
𝑛! = 𝑛 ∗ 𝑛 − 1 ! with 1! = 1
 This can be done through loops or recursive functions.

Numerical Methods for EE (EE407) | Main


End of Lecture!
51

Any Questions?

Numerical Methods for EE (EE407) | Main


L04: Approximations & Errors
52

 Outline of the lecture:

 Types of error.
 Significant figures.
 Accuracy and precision
 Maclaurin series.
 Number representation in computers.
 Taylor series.
 Truncation error.

Numerical Methods for EE (EE407) | Main


Significant Figures
53

 Numerical methods and programming involve two main


types of errors:
 Round-off errors: due to the fact that computers can
represent only quantities with a finite number of digits.
 Truncation error: is the discrepancy introduced by the fact
that numerical methods may employ approximations to
represent exact mathematical operations and quantities.
 Other errors that will appear when dealing with numerical
methods includes: blunders (due to a malfunction of the
computer), formulation or model errors (in the estimation
of the model), and data uncertainty (in the measurement of
data).
Numerical Methods for EE (EE407) | Main
Significant Figures
54

 Whenever we employ a number in a computation, we must


have assurance that it can be used with confidence.
 We can be confident that the speed is approximately 49𝑘𝑚
/ℎ (two digits).
 Saying that the speed is 48.8𝑘𝑚/ℎ involves the
approximated digit 8.
 Similarly, the Odometer gives us
six certain digits and the seventh
is approximated.
 We have 3 and 7significant
figures.
Numerical Methods for EE (EE407) | Main
Significant Figures
55

 It may not be straight forward to determine the number of


significant figures.
 The number 45,300 may have three, four, or five significant
digits, depending on whether the zeros are known with
confidence.
 Uncertainty can be resolved by using scientific notation,
where 4.53 × 104 , 4.530 × 104 , and 4.5300 × 104 designate
that the number is known to three, four, and five significant
figures, respectively.
 Numbers such as 𝜋, 𝑒, or 17 represent specific quantities,
they cannot be expressed exactly by a limited number of
digits. This yields round-off errors.

Numerical Methods for EE (EE407) | Main


Accuracy and Precision
56

 The errors associated with both


calculations and measurements
can be characterized with regard
to their accuracy and precision.
 Accuracy refers to how closely a
computed or measured value
agrees with the true value.
 Precision refers to how closely
individual computed or
measured values agree with each
other.

Numerical Methods for EE (EE407) | Main


Error Definitions
57

 We may define the round-off error as a true value:


𝐸𝑡 = true value − approximation
or as a normalized percentage of the true value:
𝐸𝑡
𝜀𝑡 = × 100%
true value
 Example: When measuring the lengths of a bridge and a
rivet with true values of 10,000 and 10𝑐𝑚, respectively, we
obtained the values 9,999 and 9𝑐𝑚.
 Calculate the (a) true errors, (b) and relative errors.
 Answers: (a) 𝐸𝑡,1 = 1𝑐𝑚, 𝐸𝑡,2 = 1𝑐𝑚. (b) 𝜀𝑡,1 = 0.01%, 𝜀𝑡,2
= 10%.

Numerical Methods for EE (EE407) | Main


Approximate Error
58

 In actual situations, the true value of a measurement is very


rarely available to us. Hence, we cannot known the true
errors 𝐸𝑡 and 𝜀𝑡 .
 In numerical analysis, the true error is known when the
analytic solution is available to us.
 Instead of the true error, we define an approximate error:
approximate error
𝜀𝑎 = × 100%
approximation
 As for iterative process, we have:
current approx − previous appr𝑜𝑥
𝜀𝑎 = × 100%
current approx

Numerical Methods for EE (EE407) | Main


Approximate Error
59

 Generally, the sign of the error is of no interest.


 We normally use the absolute value to get rid of the sign
and determine whether the error is below a tolerance, i.e.
𝜀𝑎 < 𝜀𝑠
 If
𝜀𝑠 = 0.5 × 102−𝑛 %
then, we can be assured that the result is correct to at least 𝑛
significant figures.

Numerical Methods for EE (EE407) | Main


Example: Maclaurin Series
60

 A function can be expanded as an infinite series.


 For instance, the exponential function can be written as
2 3 𝑛
𝑥 𝑥 𝑥
𝑒𝑥 = 1 + 𝑥 + + + ⋯ +
2 3! 𝑛!
 If we take n terms, we have an approximation of the
function.
 The error criterion that ensures the result is correct to at
least three significant figures is:
𝜀𝑠 = 0.5 × 102−3 % = 0.05%
 Hence, we want to repeat the iterative process until
𝜀𝑎 < 𝜀𝑠 = 0.05%

Numerical Methods for EE (EE407) | Main


Example: Maclaurin Series
61

 Take, for instance, the value


𝑒 𝑥 = 𝑒 0.5 = 1.648721 (2707 … )
 We have
Iteration
Approx 𝜀𝒕 𝜀𝒂
(𝑛)
1 1 39.3
2 1.5 9.02 33.3
3 1.625 1.44 7.69
4 1.645833333 0.175 1.27
5 1.648437500 0.0172 0.158
6 1.648697917 0.00142 0.0158

Numerical Methods for EE (EE407) | Main


Example: Maclaurin Series
62

x = 0.5; N = 100; sig = 3;


bound = 0.5*10^(2-sig);
true = exp(x);
approx = zeros(1,N+1);
approx(1) = 1;
et = zeros(1,N+1); ea = et;
for n = 1:100
approx(n+1) = approx(n) + x^n/factorial(n);
et(n+1) = (true - approx(n+1))/true*100;
ea(n+1) = (approx(n+1) - approx(n))/approx(n+1)*100;
if(ea(n+1) < bound)
break;
end
end

Numerical Methods for EE (EE407) | Main


Round-Off Errors
63

 Numerical round-off errors are directly related to the


manner in which numbers are stored in a computer.
 Computers use binary numbers to represent all data.
 Positive integers are direct binary
conversions.
 Integers can be represented using
the sign and magnitude method,
where the MSB represents the sign
and the rest of bits the number.

Numerical Methods for EE (EE407) | Main


Round-Off Errors
64

 𝑛 bits can represent integers in the range:


−2𝑛−1 + 1 → 2𝑛−1 − 1
 It is more common to use 2’s complement notation where
instead of two zeros, we have:
−2𝑛−1 → 2𝑛−1 − 1
 Rational numbers are represented using floating point
notation (mantissa & exponent):

Numerical Methods for EE (EE407) | Main


Truncation Errors
65

 Truncation errors are those that result from using an


approximation in place of an exact mathematical procedure.
 These are generally intentional errors that are inherent in
the numerical approximation .

 In order to understand what we mean by the truncation


error, we will consider as an example the Taylor series
expansion of functions.

Numerical Methods for EE (EE407) | Main


Taylor Series
66

 If the function 𝑓 and its first 𝑛 + 1 derivatives are


continuous on an interval containing 𝑎 and 𝑥, then the value
of the function at 𝑥 is given by
𝑓′ 𝑎 1
𝑓 ′′
𝑎
𝑓 𝑥 =𝑓 𝑎 + 𝑥−𝑎 + 𝑥−𝑎 2+⋯
1! 2!
𝑥
𝑓𝑛 𝑎 𝑥 − 𝑡 𝑛
+ 𝑥−𝑎 𝑛+න 𝑓 𝑛+1 𝑡 𝑑𝑡
𝑛! 𝑎 𝑛!
𝑅𝑛

 By ignoring the remainder term 𝑅𝑛 we have a polynomial


approximation of 𝑓 𝑥 .
 Basically, any smooth function can be approximated as a
polynomial.
Numerical Methods for EE (EE407) | Main
Taylor Series
67

 If the function is a constant, it suffices to take the first-order


approximate:
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖
 The first and second order approximates are
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖+1 − 𝑥𝑖
𝑓 ′′ 𝑥
𝑖
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 𝑥𝑖+1 − 𝑥𝑖 + 𝑥𝑖+1 − 𝑥𝑖 2
2!
 By taking a constant step ℎ, we have
𝑓 ′′ 𝑥 𝑓 𝑛 𝑥
𝑖 𝑖
𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 + 𝑓 ′ 𝑥𝑖 ℎ + ℎ2 + ⋯ ℎ𝑛 + 𝑅𝑛
2! 𝑛!
𝑓 𝑛+1 𝜉 𝑛+1
𝑅𝑛 = ℎ
𝑛+1 !
Numerical Methods for EE (EE407) | Main
Example 1
68

 Consider the polynomial


𝑓 𝑥 = −0.1𝑥 4 − 0.15𝑥 3 − 0.5𝑥 2 − 0.25𝑥 + 1.2
 Approximate the value of 𝑓 𝑥 at 𝑥𝑖+1 = 1 from 𝑥𝑖 = 0.
 We have ℎ = 1, 𝑓 𝑥𝑖 = 1.2 the true value 𝑓 𝑥𝑖+1 = 0.2.
 We also have:

𝑓 ′ 𝑥 = −0.4𝑥 3 − 0.45𝑥 2
−𝑥 − 0.25
𝑓 ′′ 𝑥 = −1.2𝑥 2 − 0.9𝑥 − 1
𝑓 3 𝑥 = −2.4𝑥 − 0.9
𝑓 4 𝑥 = −2.4

Numerical Methods for EE (EE407) | Main


Example 1
69

 We can calculate up to the fourth-order approximation.


 The fifth derivative is equal to zero and thus makes no
difference.
 Once we get to 𝑛 = 4, the remainder is equal to zero.
𝒏 Approx 𝜀𝒕 𝜀𝒂
0 𝑓 𝑥𝑖+1 ≅ 𝑓 𝑥𝑖 = 1.2 −500%
1 𝑓 𝑥𝑖+1 ≅ 1.2 + 𝑓 ′ 𝑥𝑖 ℎ = 0.95 −375% −26.32%
2 𝑓 ′′ 𝑥𝑖 2
𝑓 𝑥𝑖+1 ≅ 0.95 + ℎ = 0.45 −125% −111%
2!
3 𝑓 3 𝑥𝑖 3
𝑓 𝑥𝑖+1 ≅ 0.45 + ℎ = 0.3 −50% −50%
3!
4 𝑓 4 𝑥𝑖 4
𝑓 𝑥𝑖+1 ≅ 0.3 + ℎ = 0.2 0 −50%
4!
Numerical Methods for EE (EE407) | Main
Example 2
70

 Now, take the function 𝑓 𝑥 = cos 𝑥, which has an infinite


number of derivatives.
 Take 𝑥𝑖 = 𝜋Τ4 the true value 𝑥𝑖+1 = 𝜋Τ3.

𝒏 Derivative Approx 𝜀𝒕
0 𝑓 𝑥𝑖+1 ≅ 0.707106781 −41.4%
1 𝑓 ′ 𝑥 = − sin 𝑥 𝑓 𝑥𝑖+1 ≅ 0.521986659 −4.4%
2 𝑓 ′′ 𝑥 = − cos 𝑥 𝑓 𝑥𝑖+1 ≅ 0.497754491 0.449%
3 𝑓 3
𝑥 = sin 𝑥 𝑓 𝑥𝑖+1 ≅ 0.499869147 2.62 × 10−2 %
4 𝑓 4 𝑥 = cos 𝑥 𝑓 𝑥𝑖+1 ≅ 0.500007551 −1.51 × 10−3 %
5 𝑓 5
𝑥 = − sin 𝑥 𝑓 𝑥𝑖+1 ≅ 0.500000304 −6.08 × 10−5 %
6 𝑓 6
𝑥 = − cos 𝑥 𝑓 𝑥𝑖+1 ≅ 0.499999988 2.44 × 10−6 %

Numerical Methods for EE (EE407) | Main


Example 2
71

x1 = pi/4; x2 = pi/3; h = x2-x1;


f1 = cos(x1);
syms x; F = cos(x);
N = 7;
for n = 1:N
F = [F; diff(F(n),x)];
end
f2 = zeros(1,length(F));
f2(1) = f1;
for n = 2:length(F)
f2(n) = f2(n-1)+subs(F(n),x1)/factorial(n-
1)*h^(n-1);
end

Numerical Methods for EE (EE407) | Main


End of Lecture!
72

Any Questions?

Numerical Methods for EE (EE407) | Main

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy