Numerical Analysis - Introduction and Error

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 45

MS2201

Numerical Analysis

Dr. Ir. Rachman Setiawan


Engineering Design Centre
(Mechanical Design Lab.)
Faculty of Mechanical and Aerospace Engineering
E-mail: r.setiawan@itb.ac.id
Lectures
Schedule
 Wednesday 13.00 – 14.50 WIB (9137)

Evaluation
 Quiz (min. 6x +/- 20 min.) 15%
 Homework/Assignment 20%
 Mid-test 30%
 Final test 35%

Reference Book
Steven C. Chapra dan Raymond P. Canale, “Numerical Methods for
Engineers”, Fourth ed., Mc Graw Hill International Ed., 2002.

R Setiawan 2
Lectures
Etcetera
 Two-hour Lecture:
 2 parts
 Break between parts
 Tolerance Limit: Students: 10 min.; Lecturer: 15 min.
 Attendance is registered through SIX

R Setiawan 3
Lectures
Syllabus
 Introduction to Numerical Analysis
 Errors & Taylor Series
 Roots of Equations & Polynomials
 Matrices & System of Algebraic Equations
 Numerical Integration & Differentiation

 Optimization
 Curve Fittings: Regression, Interpolation
 Ordinary Differential Equations
 Partial Differential Equations

R Setiawan 4
Intro. to Numerical Analysis
Motivation

https://www.youtube.com/watch?v=zssG3n19_yE

R Setiawan 5
Intro. to Numerical Analysis
Motivation

R Setiawan 6
Intro. to Numerical Analysis
Motivation

162 N 991 N 1900 N 2200 N

2580 N 2970 N 3190 N 3450 N

R Setiawan 7
Intro. to Numerical Analysis
Definition

Numerical analysis is:


A method of analysis that consists of techniques to
solve mathematical equations with arithmetical
calculation

R Setiawan 8
Intro. to Numerical Analysis
Methods in Engineering Problem Solving

Problem/
Reality

Simulation/ Empirical/
Theory experiments

Computer aid

Analytical
Solution
Computer aid Numerical
Solution
Computer aid

R Setiawan 9
Intro. to Numerical Analysis
History

R Setiawan 10
Intro. to Numerical Analysis

R Setiawan 11
Intro. to Numerical Analysis

R Setiawan 12
Intro. to Numerical Analysis
Objectives
 To provide students with a sound introduction to some
numerical methods to solve practical engineering problems
 To introduce programming language(s) to students, or
enhance student’s programming skills

R Setiawan 13
Programming Basics
Why programming?
 To translate mathematical algorithm in numerical methods
into a language that computers understand

Mathematical model

Arithmetical model
Physical problems

Algorithm
Numerical solution

Computer Program
R Setiawan 14
3. Programming Basics
3.4 Communications
 Algorithm: a set of steps to instruct a computer to perform
a certain task
 Flow-chart: a visual/graphical representation of an
algorithm
 Pseudo-code: an alternative approach to express an
algorithm that bridges the gap between flow-chart and
computer code

R Setiawan 17
Programming Basics
 Comparison among the three:

1. Ask Inputs Inputs


Inputs
2. Perform
DO
Instruction 1 to
Instruction 1
inputs
Instruction 1 IF condition THEN store
3. If condition
ELSE instruction 1
satisfied then
ENDDO
store the result of N Condition
instruction 1
?
4. If condition not
satisfied then Y
redo instruction 1
with the input of store
the previous
output from
instruction 1

R Setiawan 18
No Symbol Meaning
1 Process

2 Input / Output

3 Selection

4 Sub program

5 Start/end terminal
6 Connector
7 Direction of process
8 Manual process

9 Page separator

10 Data storage

R Setiawan 19
Programming Basics
Logical Representation
 Sequence
Unless directed otherwise, the computer code is inplemented
one instruction at a time

Instruction 1

Instruction 2

Instruction 3

R Setiawan 22
Programming Basics

 Selection
A means to split the program’s flow into branches based on the
outcome of a logical condition

R Setiawan 23
Programming Basics
 Repetition
A means to perform a certain task for a number of times until a
certain condition is met.

R Setiawan 24
Programming Basics
Programming Language
 Fortran
 C++
 Visual Basic Application (VBA)
 Matlab/SciLab
 Java
 Phyton

* Homework
Build a flow chart to estimate ex and try to calculate, and
compare with the computer solution

hint:

R Setiawan 25
Errors
How computers identify numbers
Sources of error
How to minimize numerical errors

R Setiawan 26
Errors
Definition of Error
Error is the discrepancy between the true value and the approximate
value (in this case, generated from computational analysis)

27
Errors
 Precision  how close the measurement/computational
results among each other
 Accuracy  how close the overall results to the true value
 Referring to the graph before:
 Figure a: precision LOW; accuracy LOW
 Figure b: precision LOW; accuracy HIGH
 Figure c: precision HIGH; and accuracy LOW
 Figure d: precision HIGH; accuracy HIGH

R Setiawan 28
Errors
Formulation for Error

xt : True value
x : Approximate value
xi : Current approximate value
xi-1 : Previous approximate value
et : True percentage relative error
ea : Approximate percentage relative error

xt  x
et  100%
xt
xi  xi 1
e 
i
a 100%
xi

R Setiawan 29
Errors
Errors could occur at every level of numerical method

Error on Num method


Human Error

Human Error Human Error

Human Error
Error on Computing

R Setiawan 30
Errors
Classification

Computers Num. Method Human


-Round-off -Truncation -Modelling/Formulation err.
-Chopping -Data uncertainty
-Blunder

R Setiawan 31
Error: Round-off & Chopping
Numbers in Computer
 Before discussing Error due to computer, it is better to
discuss How Numbers are Represented in Computer.
 Types of number represented by Computer:
 Base-n
 n digits
 Example Base-10:
(8 x 104) + (6 x 103) + (4 x 102) + (0 x 101) + (9 x 100)=86,409
 Example Base-2:
1010112 =
(1x25)+(0x24)+(1x23)+(0x22)+(1x21)+(1x20)
=(1x32)+(0x16)+(1x8)+(0x4)+(1x2)+(1x1)
=32 + 0 + 8 + 0 + 2 + 1 = 4310

R Setiawan 32
Error: Round-off & Chopping
 Floating point
 x = (±)m × be
 (±) = Sign
 m = Mantissa,
 b = Base-number
 e = Signed exponent
 Example:

1 0 1 1 0 1 1 1 0 0 1

Sgn of Magnitude
number of exponent Magnitude
of mantissa
Sgn of
exponent

R Setiawan 33
Error: Round-off & Chopping
 Floating point
 x = (±)m × be
 (±) = Sign
 m = Mantissa,
 b = Base-number
 e = Signed exponent
 Example:
 +0,2345 × 10-2 = 0,002345

1 0 1 1 0 1 1 1 0 0 1
???

b=2
e = + (1 x 22 + 1 x 21 + 0 x 20) = +6
m = - (1 x 211 + 1 x 210 + 1 x 29 + 0 x 28 + 0 x 27 + 1 x 26) =
- (2048 + 1024 + 512 + 0 + 0 + 64) = -3648

R Setiawan 34
Error: Round-off & Chopping

Learn Ex. 3.5, and solve For 11-bit floating point:


 what is the smallest positive number
 What is the interval between numbers

Double-Precision Floating Point (64-bit)

R Setiawan 35
Error: Round-off & Chopping
Characteristics of Numbers in Computer
 Limited range of quantities
 Finite number of quantities within range
 Interval between numbers

Error (computer)

Chopping Round-off

(please refer to Discussion following Ex. 3.4 and 3.5)


R Setiawan 36
Error: Round-off & Chopping
Round-off and Chopping

p
3.141592654……

3.1416 (Round-off)

3.1415 (Chopping)

R Setiawan 37
Error: Truncation

Taylor Series
 Truncation error is related with How numerical methods
work
 Review:
Functions / Formulae  Approximate relationship
 Solved with arithmetical/algebraic operations

 Example: df  x  f  xi 1   f  xi 
 f '  xi  
dx x  xi xi 1  xi

 One popular approach is Taylor Series

R Setiawan 38
Error: Truncation
 Taylor Series Expansion used in Numerical analysis:

f ' '  xi  2 f ' ' '  xi  3


f  xi 1   f  xi   f ' xi h  h  h  ...
2! 3!
f n   xi  n
 h  Rn
n!
f n 1   n 1
Rn  h
n  1!  Remainder (nth term)
h   xi 1  xi   Step size, constant for Numerical Method
(can be adaptable in more advanced Num.
Meth’s).

  a value of x that lies between xi and xi+1

R Setiawan 39
Error: Truncation
 The original series has infinite number of terms
 In the application of Numerical methods, it would not
be possible  Truncated
 The truncated series is now consisting of Error, that is
no other than, the Remainder (Rn). But now it is called
Truncation Error

Rn  O h n 1 
 It would not be possible nor necessary to know exactly
the truncation error is,
 But it is sufficient to know that the truncation error is
proportional to (step size)n+1

R Setiawan 40
Error: Truncation
 The remainder itself has infinite terms,

f ' '  xi  2 f ' ' '  xi  3


f  xi 1   f xi   f '  xi h  h  h  ...
2! 3!
f  xi  m f
m   m 1
 xi  m 1 f  xi  n
n 
 h  h  ...  h
m! m  1! 

n  1!
 
Rm
therefore needed to be truncated:

m = finite number of term

Rm 
f xi  h m1
m 1
n = infinite number of term
m  1! Rm = Remainder after m term

R Setiawan 41
Error: Truncation
Example
f ' '  xi  2 f ' ' '  xi  3 f n   xi  n
f  xi 1   f  xi   f '  xi h  h  h  ...  h
 After Truncation:
2! 3! n  1!
f  xi 1   f  xi   f '  xi h  R1
f  xi 1   f  xi  R1
 f '  xi   
 h    h
First-order Truncation error
approximation

First-derivative
(Approximated)

R Setiawan 42
Error: Truncation
Error Propagation
 Error can propagate through mathematical functions
 For Functions of a Single Variable, the estimate error of
the function, f ~
x  due to error of variable x, x  ~
x

f  ~
x   f  x   f ~
x
 f ' ~x x  ~x

R Setiawan 43
Error: Truncation
 For Multivariable Functions

f ~ f ~ f ~
f  x1 , x1 ,..., xn  
~ ~ ~ x1  x2  ...  xn
x1 x 2 xn

 Example 4.6

R Setiawan 44
Error: Truncation
Stability and Condition
 Another application of Error propagation in Numerical Method is
Stability
 Computation is numerically unstable if the effect of the error of
input values are grossly magnified by the Numerical Method
 And the quantity that represents the stability is Condition:
x f ' ~
~ x
Condition Number 
f ~ x
 Condition number 1  relative error in function is identical to
that of the variable.
 Condition number > 1  relative error of the variable is amplified
 Condition number < 1  relative error of the variable is
attenuated
 Table 4.3 & Example 4.7

R Setiawan 45
Error: Truncation
Numerical Error
 The total numerical error is the Summation of the
Truncation and Round-off errors

R Setiawan 46
Error: Truncation
 There is no Systematic and General approach
 But here are a number of practical programming
guidelines:
 Use extended-precision arithmetic
 Avoid subtracting two nearly equal numbers, by
rearranging or reformulate the problem
 Predict numerical error
 Verification / Validation with known (theoretical/empirical)
result
 Tuning on some parameters, like step size, weighting
factors, coefficients etc.

R Setiawan 47
Error
Human Errors
 Assumption/Formulation Error
 Data Uncertainty/Error
 Blunder

R Setiawan 48
Error
Characteristics of Numerical Methods
 Number of initial guess
 Rate of convergence
 Stability
 Accuracy & Precision
 Breadth of application
 Special Requirements
 Programming efforts required

How numbers are represented

How numerical method works

R Setiawan 49

You might also like