Anda di halaman 1dari 73

Universiti Teknologi PETRONAS

Mechanical Engineering

MDB 3053 Numerical Methods

INTRODUCTION

Reading Assignment: Chapter 1 & 2

1
TEXT BOOK
Steven C. Chapra and Raymond P. Canale, 2014. Numerical Methods for Engineers,
International Edition 7th Edition, McGraw Hill (or any earlier editions)

2
COURSE OUTCOMES

1. Apply knowledge of numerical methods in solving


complex engineering problems

2. Analyze errors associated with the numerical


solutions to engineering problems

3. Create programming codes for application of


numerical methods to solve engineering problems

3
WHAT IS NUMERICAL METHOD?

• A technique by which mathematical problems are


formulated so that they can be solved numerically with
basic arithmetic operations which can then be
implemented in digital computers

• It usually starts with some initial value, after some


intermediate steps, it yields approximate solution which
depends on machine precision & technique used

• It can solve large, complicated problems when


analytical methods fail to provide solutions,
hence numerical method is the opposite of analytical
method
4
ANALYTICAL versus NUMERICAL METHOD

Given y  x2  3x  2
Problem: Find the minimum value of the function
above using analytical and numerical method

Analytical Method
dy
 2 x  3 0
dx
3
 x   1.5
2
d 2y Therefore x  1.5 is the minimum value
2
dx 2
• yield exact result with no error!
5
NUMERICAL METHOD

5
approximate the min point
4

y 3

0
0.0

0.4

0.8

1.2

1.6

2.0

2.4

2.8

3.2

3.6

4.0
-1

•Approximate result: 1.4 < x < 1.6


•Accuracy of the results is improved by decreasing the step
size, x

6
Analytical versus Numerical methods
• Previous example favors the ANALYTICAL
METHOD – quick, simple and exact results!
• BUT….
What if the problem is COMPLEX???
p V
  sin   V
s s
OR

  u v w


   0
t  x y z 

7
WHY NUMERICAL METHODS?

 Fast approximate solution for mathematical


problem

 Solving complex geometries and nonlinearities


when analytical solution is impossible

 Development of code and modelling software.

8
EXAMPLE: Numerical method to solve an
engineering problem

Consider a case of a bungee jumping below:

Question:

What is the final terminal speed of the


man?

9
Step 1: Draw FBD and derive the equation of
motion using Newton’s second law

= Where

ODE problem

10
Step 2: Attempt to solve the problem
analytically if possible

It turns out that the ODE can be solved


analytically and the solution is:
Boundary condition:

Exact solution

Intro/10

11
Step 3: If the equation cannot be solved easily, use
Numerical Method to solve it

Decide on which numerical method to be used for ODE….

Note that this term


represents a slope

How to approximate ‘slope’ using numerical method?

12
13
Using Euler’s method to solve ODE numerically

new value  old value  slope  step size


yi 1  yi  f ( xi , yi )  h
Now perform iteration using the boundary condition and
set the step size, let
1st iteration,
;

14
2nd iteration,

Iteration
continues:

15
Comparison: Analytical vs Numerical solutions

16
CONCLUSION

 Numerical methods solve equations which cannot be


solved analytically.

 The numerical results are approximations

 Good knowledge in Numerical Methods helps us reduce


errors in approximations and increase accuracy.

17
MDB 3053 Numerical Methods

ERROR ANALYSES

Reading Assignment: Chapter 3 in Textbook

18
Course Outcome

1. Apply knowledge of Numerical methods in


solving complex engineering problems

2. Analyze errors associated with the numerical


solutions to engineering problems

3. Create programming codes for the application


of numerical methods to solve engineering
problems

19
Error Analysis
Differentiate and understand the following terminologies
for numerical methods:

• Significant Figures
• Accuracy & Precision
• True Error & Approximate Error
• Round-off Error & Truncation Error

20
Odometer and Speedometer Readings

21
Based on the reading, it can be confidently said that:

• Speedometer Reading- the car is traveling at


approximately 49 km/h. The two certain digits are 48
km/h.
Note: Third digit e.g. 48.8 km/h or 48.7 km/h are just
estimates.

• Odometer reading - the car has traveled slightly less


than 87,324.5 km. There are six certain digits.
Note: The seventh digit is uncertain.

22
Significant Figures (SF)

The concept of a significant digit has been developed to


formally designate the reliability of a numerical value

The significant digits of a number are those that can be


used with confidence.

The significant digits correspond to the number of certain


digits plus one estimated digit.

The estimated digit is set at one-half of the smallest scale


division on the measurement device.

23
Speedometer reading - consists of
the three significant figures: 48.5 km/h.

Certain Estimated

Odometer reading – consists of seven-significant-


figures: 87,324.45 km.

Certain Estimated

24
Significant Figures (SF)

48.5 (3 SF)

87324.45 (7 SF)
25
Examples of number of significant figures (SF)

2 SF – 0.0013, 0.000034, 2.5, 4.2 x 103


3 SF – 0.0145, 0.156, 5.34, 4.23 x 105
4 SF – 241.0, 13.00, 2367, 2.410 x 104,

Note: Leading zeroes are not significant figures eg 0.013 (2 SF)


Note: Trailing zeros are significant only if it contains decimal
point e.g 13.00 (4 SF)

Note: when trailing zeroes are used in large numbers, it is not


clear how many, if any, of the zeroes are significant.

For example, the number 45,300 may have 3, 4 or 5 SF,


depending on whether the zeroes are known with
confidence.
26
The uncertainty can be resolved by using scientific notations:
3 SF - 4.53 × 104
4 SF - 4.530 × 104
5 SF - 4.5300 × 104

• Since numerical methods yield approximate results, there is


a need to develop a criteria to specify the confident level of
results - students are advised to keep 3–4 SF in this course

• Numbers such as π, e, or √7 represent specific quantities


but they cannot be expressed by a limited number of
digits. The omission of the remaining significant figures
is called round-off error.

27
CLASS ACTIVITY

Find the Significant Figure (SF)

Number SF Rule

1234

13008

9.820

41100

0.00082

5.20000E8

28
ACCURACY vs. PRECISION

•ACCURACY: Refers to how close a computed or


measured value agrees with the true value.

•PRECISION : Refers to how close individual


computed or measured values agree with each other.

29
ANALOGY OF TARGET PRACTICE

30
MEASUREMENT OF ERROR

• If there are any inaccuracy or imprecision, we use the


term ‘error’ to measure the deviation of the computed
values

• Two types of error :


1. TRUE ERROR
2. APPROXIMATE ERROR

It is more exact if the term ‘uncertainty’ is used in placeof


error when it comes to measurement.

31
TRUE ERROR

• True error is when the current approximation value is


compared with the true value

• It is used to measure the lack of accuracy of an estimate


• Usually expressed in absolute value without any sign.

Et  true value - approximat ion


 true error

true value - approximat ion


t  100% Accurate
true value
 true percent relative error (%)

32
Example

33
APPROXIMATE ERROR

• Approximate Error is obtained when the current


approximation is compared with the previous approximation
• To measure the lack of precision of an estimate during an
iterative procedure

• Usually expressed in absolute value without any sign

Ea  current approx - previous approx.


 approximat e error

current appr. - previous appr.


a  100%
Precise
current approx.
 approximat e percent relative error (%)
34
PRE-SPECIFIED TOLERANCE, s
• Usually computations are repeated until the approximate
percent relative error, a falls below the pre-specified
tolerance or stopping criterion , s i.e. until  a   s
• s is usually determined as below :
2 n
 s  (0 .5  10 )% where n  no. of SF

• e.g. if the result is correct/conform to 3 SF, then s is :


2 3
 s  ( 0 .5  10 )%  0 .05 %
We must continue our iteration  a  0 .05 %
s becomes stopping criterion

35
TYPES OF NUMERICAL ERRORS
• Round-off errors
• Caused by the limited no. of significant digits that can
be retained by the digital computers (16-bit or 32-bit)
 has to round-off the digits
• Ex :  = 3.1415926535897…… vs.  = 3.1416 (5 SF)

• Truncation errors (or Chopping error)


• Occur when using an approximation to represent exact
mathematical procedure  has to chop off the digit or
some terms
• Ex : chopping of Taylor series: ex = 1+ x+ x2/2+ x3/6 + …

36
Chopping of numbers:

True value : 324.287

Chopping to 4 SF : 324.2

Rounding off numbers:

True value : 324.287

Rounding off to 4 SF : 324.3

37
CLASS ACTIVITY

Evaluate f(x)=6.1x2+3.2x at x=4.71 using 3-digit (3 SF)


arithmetic with chopping and rounding. Also compute the error.

Estimate x x2 6.1x2 3.2x f (x)

Exact 4.71

3-digit 4.71
(chopping)
3-digit 4.71
(rounding)

true value - approximat ion


t  100%
true value
 true percent relative error (%)
38
SOLUTION

function f(x)=6.1x2+3.2x at x=4.71

Estimate x x2 6.1x2 3.2x f (x)

Exact 4.71 22.1841 135.32301 15.072 150.39501

3-digit 4.71 22.1 6.1(22.1)=134 3.2(4.71)=15.0 134+15 =149


(chopping)
3-digit 4.71 22.2 6.1(22.2)=135 3.2(4.71)=15.1 135 + 15.1=150
(rounding)

true value - approximat ion t,c = 0.93%


t  100%
t,r = 0.26%
true value
 true percent relative error (%)

39
CLASS ACTIVITY

Compute for x = 0.5. Add terms until the absolute value of


the approximate error estimate εa falls below a prespecified
error criterion εs conforming to three significant figures.

40
41
CONCLUSION

•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.

• True error is when the current approximation value is


compared with the true value

• Approximate Error is obtained when the current


approximation is compared with the previous
approximation

42
• Round-off errors are caused by the limited no. of
significant digits that can be retained by the digital
computers

• Truncation errors occur when using an approximation


to represent exact mathematical procedure

43
MDB 3053 Numerical Methods

Error Propagation & Machine Epsilon

Reading Assignment: Chap 3 & 4

44
Measurement Uncertainty

45
1 2
Propagation of Error s  ut  at
2

•All measurements have some uncertainty associated with


them, and the final answer will, of course, have some level
of uncertainty.
• Propagation of error is the process of determining the
uncertainty of an answer obtained from a calculation

•Example:
L Area of a rectangle: A=L*W
W if L= 5.0 0.2 mm and W = 2.0  0.2 mm
Calculate the area and its uncertainty.

(Ans: 10.0  1.1 mm2)

46
Propagation of Error

RULE 1: ADDITION and SUBSTRACTION


Given R= X + Y – Z . If X, Y and Z have uncertainties X,
Y and Z, then the uncertainty in R, R is

Example:
Given z = x+y where x =3.0 0.1 , y=4.0 0.2
Find the uncertainty of z. (ans:  0.2)

47
Propagation of Error

RULE 2: MULTIPLICATION and DIVISION


Given R= XY/Z , if X, Y and Z have uncertainties X, Y
and Z, then the uncertainty in R, R is

Example:
Given A = LW ; where L =3.0  0.1 , W=4.0  0.2
Find the uncertainty of z. (ans:  0.7)

48
Propagation of Error

RULE 3: MULTIPLICATION with a CONSTANT


Given R= cX , if X has uncertainty X, then the uncertainty
in R, R is

Example:
Given F = mg ; where m =5.10 0.05 kg
Find the uncertainty of F. (ans:  0.49)

49
Propagation of Error

RULE 4: Raising to a POWER


Given R= Xn , if X has uncertainty X, then the uncertainty
in R, R is

Example:
Given, z = x2 ; where x =3 0.1
Find the uncertainty of z. (ans:  0.6)

50
Rules in Combination
Find the error propagation in y = vt – 0.5gt2

51
Machine Epsilon

52
Machine Epsilon

Chap3/51

53
MDB 3053 Numerical Methods

Series Expansion
&
Approximation of Small Perturbation

Reading Assignment: Chap 4

54
Motivation
• Sought: sin(0.1)
• Missing: calculator or lookup table
• But we know: sin for another nearby value i.e. sin(0)
• Also known: values of all derivatives at 0.
• Can we use them to approximate sin(0.1)?
• What will be the error of this approximation?

• Solution: use Taylor Series


Taylor series can be used to predict the value od a
function at one point in terms of the function and its
derivative at another nearby value.

55
Taylor’s series

Small perturbation

df (x) 1 d 2 f (x)
f x  x  f (x)   x   x
2
2
dx 2! dx


1 d 3 f (x)
3! dx 3
3
 
 x  O x
4

56
Taylor Series

•It is widely used in numerical methods to express functions


in an approximate fashion to replace exact mathematical
h = xi+1 - xi
formulation.
f ( xi ) 
f ( xi 1 )  f ( xi )  f ( xi )( xi 1  xi )  xi 1  xi 2  f ( xi ) ( xi 1  xi )3  
2! 3!
f n ( xi ) f ( n 1) ( x) n 1
 ( xi 1  xi ) n  Rn Rn Re mainder term  h
n! (n  1)!

•xi is a base point (a constant) and its derivatives, f n(xi) are


known
•xi+1 is a forward point nearby xi , and f(xi+1) is sought

57
Taylor Series

forward pt: xi+1 base pt: xi

f ( xi ) 2 f ( xi ) 3 f n ( xi ) n
f ( xi 1 )  f ( xi )  f ( xi )h  h  h  h  Rn
2! 3! n!
where step size, h = xi+1  xi
Remainder Rn can be expressed as Rn=O(hn+1) --- big O notation

Example: Taylor series expansion for f(x) = sin x


sin xi cos xi
sin( xi 1 )  f ( xi 1 )  sin xi  h cos xi  h 2  h3 
2! 3!

zero order term 1st order term

58
Approximation of Taylor Series

• Original infinite Taylor Series (infinite terms)


f ( xi ) f n ( xi )
f ( xi 1 )  f ( xi )  f ( xi )( xi 1  xi )  xi 1  xi    
2
( xi 1  xi ) n  Rn
2! n!

• Up to Zero Order approximation


f (xi1 )  f (xi )  produce a constant line

• Up to First Order approximation


f (xi1 )  f (xi )  f ( xi )(xi1  xi )  produce a linear line

• Up to Second Order approximation


f ( xi )
f ( xi 1 )  f ( xi )  f ( xi )( xi 1  xi )  xi 1  xi 2
2!
 produce a quadratic line
59
Accuracy of Taylor Series
•To obtain better accuracy, retain more terms in the series
OR use much smaller step, h
•Truncation Error occurs when the Taylor series terms are
limited  produce lesser error if higher order terms are kept

f ( x)
Zero Order (constant)
First Order (linear)
Increasing accuracy

Second Order (parabola)


h

xi xi1 x

60
CLASS ACTIVITY

Using zero to 3rd order approximation of Taylor Series,


estimate f(x)=cos(x= /3) at xi+1=/3 and xi= /4 (in radian)
and compute the true percent relative error, t.

Ans:
zero to 3rd order: t = 41.4% ; 4.4%; 0.45%; 0.026%
61
SOLUTION

Find f(/3)=cos(/3) , given xi+1=/3 and xi= /4

Step 1: Find true value: f(x) = cos (/3) = cos(60) = 0.5


cos xi sin xi
Step 2: Expansion f ( xi 1 )  cos xi  h sin xi  h  h3 
2

2! 3!
Step 3: use xi+1=/3 and xi= /4 , step h = /3-/4 = /12

Ans:
zero to 3rd order: t = 41.4% ; 4.4%; 0.45%; 0.026%
62
CLASS ACTIVITY

What about sin(1)? Use xi+1=1 and xi=0.5 (in radian) and
compute the true percent relative error, t. Step h =1–0.5 = 0.5

Step 1: Find true value: f(1) = sin (1) = 0.84147


sin xi cos xi
Step 2: Expansion f ( xi 1 )  sin sxi  h cos xi  h 2  h3 
2! 3!

Ans: zero to 3rd order: t = 43.0; 9.1%; 2.0%; 0.2% 63


Maclaurin Series

•For the special case, Taylor series becomes Maclaurin


series if we take base point xi = 0and x i+1 = x , thus

f (0) 2 f (0) 3
f ( x)  f (0)  f (0) x  x  x 
2! 3!

Example: MacLaurin series expansion for function sin x

x3 x5 x 7 f ( x)  sin x  f (0)  0
sin x  x      f ( x)  cos x  f (0)  1
3! 5! 7 !
f ( x)   sin x  f (0)  0
f ( x)   cos x  f (0)  1
1st order term
3rd order term

64
EXAMPLE

Find the Maclaurin series expansion for cos(x) :


f (0) 2 f (0) 3
Expansion: f ( x)  f (0)  f (0) x  x  x 
2! 3!
Estimate cos(x) up to eighth order approximation :
f ( x)  cos x  f (0)  1
f ( x)   sin x  f (0)  0
At each order: f ( x)   cos x  f (0)  1
f ( x)  sin x  f (0)  0
f 4 ( x)  cos x  f 4 (0)  1

x 2 x 4 x 6 x8
Answer: cos x  1      
2 ! 4 ! 6 ! 8!

65
CLASS ACTIVITY

The Maclaurin series expansion for cos(x) is


x 2 x 4 x 6 x8
cos x  1      
2 ! 4 ! 6 ! 8!

Estimate cos(/4) up to eighth order approximation and


compute the true percent relative error, t for each step.

Step 1: Find true value: f(/4) = cos (/4) = 0.70710678

Step 2: substitute the series cos(x)

t= 41.4%; 2.2%; 0.046%; …….

66
Error Analysis and Series

 We have covered Chapter 1 to 4 in textbook

67
Application of Taylor Series

•First order approximation of Taylor series can be used to


predict the first derivative f ’ (xi) of a function atxi
•By truncating the Taylor series after first derivative:

f (xi1)  f (xi )  f (xi)(xi1  xi )  R1 Remainder

f (xi1 )  f (xi ) R1
f (xi )  
(xi1  xi ) (xi1  xi )
f (xi1 )  f (xi )
  O(h)
(xi1  xi )
Truncation Error
First-orderApproximation

68
Finite-Divided Difference Scheme

• Also called as Numerical Differentiation (Chap 23)


• Finite-divided difference scheme is obtained from Taylor
series to numerically approximate the first-order
derivative
f (xi1 )  f (xi )
f ( x i) 
(xi 1  xi )

• 3 types of finite-divided difference schemes:


1. Forward
2. Backward
3. Centered

69
First Forward Differencing

• “First” means it is an approximation of the first


derivative
• It is called “forward” because it utilizes data at i and i+1
True
f(x) Derivative
Approximation
forward pt base pt

f (xi1)  f (xi )
f '(x i ) 
h
h
Truncation error = O(h) xi xi1 x
It is linearly convergent base pt forward pt

70
First Backward Differencing

• First Backward Differencing : utilizing data at i and i-1

True
Derivative
f(x)
base pt backward pt
Approximation

f (xi )  f (xi1 )
f (xi ) 
h h
Truncation error = O(h) xi1 xi x
backward pt base pt
It is linearly convergent

71
First Centered Differencing

• First Centered Differencing :utilizing data at i-1 and i+1


and give more accurate approximation
True
Derivative
f(x)
forward pt backward pt
Approximation

f (xi1) f (xi1)
f (x) i
2h
2h
Truncation error = O(h2)
xi1 xi1 x

72
CLASS ACTIVITY

Use the first forward, first backward and first centered


difference scheme to estimate the first derivative of the
function:
f(x) = 5x3 3
Evaluate the derivative at x = 2 by using a step size of h = 0.5.
Compute the true percent relative errors.

True percent relative error = 27.1%, 22.9%, 2.1%

73

Anda mungkin juga menyukai