Lecture Notes 1

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 27

CHAPTER 1

Introduction

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Introduction
• Numerical methods are techniques by which mathematical
problems are formulated so that they can be solved with
arithmetic operations.

• Engineering includes heavily mathematical models. Main


responsible of engineers are to solve these mathematical
models

• Solutions are obtained by standard mathematical


techniques if the models are simple enough.

• However most of the engineering problems are not simple


enough to solve using standard mathematical techniques.
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Introduction

• For Example, consider the following integral


b
 x2
I1   xe
a
dx

• This integral may be integrated using standard


mathematical technique

1  x2 b 1  a2  b2
I1   e  (e e )
2 a
2

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Introduction

• On the other hand

b
 x2
I2  e
a
dx

• The integration above may not be solved using standard


mathematical techniques. This integral can be evaluated
only numerical analysis.

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Basic Definitions

• Significant figures
• Whenever we employ a number in a computation, we
must have assurance that it can be used with confidence

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Significant figures

• What is the speed of the car?

• It is 48 km/h or 49km/h?

• Or it is 48.8 km/h or 48.9 km/h?

• May one claim its speed is 48.86523 km/h?

• The significant figures of a number are those that can be


used with confidence.

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


How to find number of significant figures

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


How to find number of significant figures

• Usually it is a straightforward procedure, but some cases can lead


to confusion.

• For example, zeros are not always significant figures because


they may be necessary just to locate a decimal point 0.00001845,
0.0001845, and 0.001845 all have four significant figures.

• Similarly, when trailing zeros are used in large numbers, it is not


clear how many, if any, of the zeros are significant. For example, at
face value the number 45,300 may have three, four, or five
significant digits, depending on whether the zeros are known with
confidence.

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


How to find number of significant figures

• Π is represented with 7 significant figures as below

πchop =0.3141592 x 101


πround =0.3141593 x 101

• To count the significant digits (figures), we write the numbers in a


scientific notation (normalized decimal form)

0.d1d 2 d 3d 4 ....d k x10 n d1  0


• Here k represents the number of significant figures.
• For example 0.1032, 0.001324 and 22.53 have four significant
figures.

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Chopping and Rounding

• Many numbers like π require infinitely many number of


digits for exact representation. The representation of a real
number in a computer by the use of finite number of digits is
called its floating point. Floating point is determined
chopping and rounding.

• Chopping

• Π= 3.1415926535897932384626433832795….
• If the π is represented 5 significant digits
• Π=3.1415

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Target digit

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Effect of number of digits used in computations

• Example
1
Calculate the derivative of f ( x )  2
with 3& 4 digit aritmetics at x  1.22
(3  2 x )
4x
f ( x) 
(3  2 x 2 ) 2
3 Digits Arithmetic's
4*1.22 4.88 4.88 4.88
f (1.22)  2 2
 2
 2
  12, 200
(3  2*(1.22) ) (3  2*1.49) (3  2.98) 0.0004

4 Digits Arithmetic's

4*1.22 4.88 4.88 4.88


f (1.22)  2 2
 2
 2
  8472
(3  2*(1.22) ) (3  2*1.488) (3  2.976) 0.000576

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Accuracy and Precision

• ACCURACY
• Accuracy refers to how closely a computed or measured
value agrees with the true value.

• PRECISION
• Precision refers to how closely individual computed or
measured values agree with each other.

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Accuracy and Precision

(a) Inaccurate and imprecise

(b) accurate and imprecise

(c) inaccurate and precise

(d) accurate and precise

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Error

• TRUE ERROR

• The relationship between the exact (true) value and


the approximation can be formulated as:

• True value= Approximate value + Error

• From the above equation, true error is denoted as:

• Et=True value-Approximate value

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Error

• To account for the magnitudes of the quantities being


evaluated is to normalize the error to the true value, as in
True error
Re lative Error 
True value

• The relative error can also be multiplied by 100 percent, as


in
True error
t  100%
True value

• where εt designates the true percent relative error.

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Example
• Suppose that you have the task of measuring the lengths of a bridge
and a rivet and come up with 9999 and 9 cm, respectively. If the true
values are 10,000 and 10 cm, respectively, compute (a) the true error
and (b) the true percent relative error for each case.
• Solution:

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Approximate Error
• In real-world applications, we will obviously not know
the true answer a priori. Therefore, an alternative error
(approximate error) should be defined

• Certain numerical methods use an iterative approach to


compute answers. In such an approach, a present
approximation is made on the basis of a previous
approximation. The approximate error is then defined:

Current Approximation  Pr evious Approximation


a  100%
Current Approximation

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Approximate Error

• The signs of approximate error may be either positive or


negative, therefore, it is often useful to employ the absolute
value
• For such cases, the computations repeated until
a  s
• It is also convenient to relate these errors to the number of
significant figures in the approximation, we can be assured
that the result is correct to at least n significant figures.
 s   0.5 x102 n  %
• n= number of significant figure

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Classification of Errors

• 1. TRUNCATION ERROR
• This error results from the discrepancy introduced by the
fact that the numerical method employs approximation to
represent exact mathematical operations and quantities

• 2. ROUND OFF ERRORS


• This kind of errors occurs due to the fact that computers
can only represent quantities with a finite number of digits

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Taylor Series

• The Taylor Series provide a means to predict a function value


at one point in terms of the function value and its derivatives
at another point.

• If a function f(x) and its first n+1 derivatives are continuous


on an interval containing ‘’a’’ and ‘’x’’ then the value of the
function at x is given by:


f n (a)
f ( x)   ( x  a) n
n 0 n!

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Taylor Series

( x  a) ( x  a)2 ( x  a )3 ( x  a)n
f ( x)  f (a )  f (a)  f (a)  f (a) n
 ......  f (a )  Rn
1! 2! 3! n!

where, the remainder Rn is defined as:

n 1 ( x  a ) n 1
Rn  f (a ).
( n  1)!

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Example

• Expand f(x)=ex to the Taylor Series at a=0. Then calculate


true values and approximate values at x=0.5 (for n=2, 3
and 4) (n= number of terms in expansion)
• Solution
f ( x)  e x  f (0)  e0  1
f ( x)  e x  f (0)  e0  1
f ( x)  e x  f (0)  e0  1
f ( x)  e x  f (0)  e0  1
2 3
( x  0) ( x  0) ( x  0)
f ( x)  e x  f (0)  f (0)  f (0)  f (0)  .....
1! 2! 3!
CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
2 3 4 n
x x x x x
f ( x)  e x  1      ... 
1! 2! 3! 4! n!

• Then calculate true and approximate values of function at


x=0.5

• True value =
f (0.5)  e0.5  1.6487

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


Example

• Approximate values:

• n=2
x
f ap ( x)  1   f ap (0.5)  1  0.5  1.5
1!
• Relative True error

True value  Approximate value 1.6487  1.5


t    0.0902
True value 1.6487

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN


• n=3
x2 0.52
f ap ( x)  1  x   f ap (0.5)  1  0.5   1.625
2! 2
• Relative True error
1.6487  1.625
t   0.0144
1.6487
• n=4
x 2 x3 0.52 0.53
f ap ( x)  1  x    f ap (0.5)  1  0.5    1.6458
2! 3! 2 6
• Relative True error
1.6487  1.6458
t   0.0018
1.6487 CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN
Matlab Code

n=input('enter n');
Outputs
x=input('enter x');
enter n=4
eax=0; enter x=0.5
ex=exp(x); n eax error
disp(['n eax error']) 1.0000 1.6487 0.3935
for i=1:n; 2.0000 1.6487 0.0902
k=i-1;
eax=eax+(x^k)/factorial(k); 3.0000 1.6487 0.0144
error=abs((ex-eax)/ex); 4.0000 1.6487 0.0018
disp([i eax error])
end

CENG 202: NUMERICAL ANALYSIS, DR. SEMIH ERHAN

You might also like