Sie sind auf Seite 1von 41

Chapter 1

Introduction

Course Contents

Modeling, Computers, and Error


analysis
Eng. Problem solving
Programming and software
Errors and Taylor Series
Roots of equations
Bracketing methods
Open methods
Roots of polynomials
Linear algebraic equations
Gauss elimination
LU Decomposition &Matrix
inversion
Gauss-Seidel

Curve fitting
Least square regression
Interpolation

Polynomial Interpolation

Numerical differentiation &


integration
Integration of equations
Numerical differentiation

Ordinary differential equations


Eulers Method
Runge-Kutta Methods
2

Chapter Outline
1.1

Introduction

1.2

Mathematical Modeling & Engineering Problem Solving

1.3

Programming and Software

1.4

Errors

Numerical Methods
Numerical Methods:
Algorithms that are used to obtain numerical solution of a
mathematical problem.
Why do we need them?
No analytical solution exists
An analytical solution is difficult to obtain or not practical.

Mathematical Models
Equation that expresses the features of system or process in mathematical
terms.
A mathematical model is a functional relationship of the form

=f

independent
forcing
variables, parameters, functions

Dependent
variable

Mathematical Models
Example :Newtons Second Law of Motion
F=ma
F = net force (kgm/s2 or N)
m = mass of the object (kg)
a = acceleration (m/s2)
6

Mathematical Models
Example :Model for falling parachute,

dv
=
dt

c
g
v
m

v = terminal velocity (m/s)


t = time (s)
g = gravitational constant (9.8 m/s2)
c = drag coefficient (kg/m)
m = mass of the object (kg)
7

Engineering Problem Solving Process


dv F
=
dt
m
dv FD Fu
mg cv 2
=
=
dt
m
m
dv
c
= g v2
dt
m

F = ma

v=

a=

mg
tanh(
c

with
e x - e-x
tanh (x) = x
e + e-x

Air
Resistance

gc
t)
m

Gravity
Falling Parachutist
8

Engineering Problem Solving Process


1- Problem definition
2- Mathematical model
3- Numerical or graphical results
4- Implementation

Analytical Solution, (Exact)


m=68.1 kg,
c=0.25kg/m

v(t ) =

68.1* 9.81
9.81* 0.25
tanh(
t)
0.25
68.1

V= 51.6938 m/s

v(t ) = 51.66938 tanh(0.18977 t )

v (t ) = 51.6938 tanh(0.18977 t )
v (0) = 0
v () = 51.6938 m/s

10

Approximate Solution (Numerical)


dv
c
=g v
dt
m

dv / dt v / t
v (t i +1 ) v (t i )
c
= g v (t i )
t i +1 t i
m

v(ti+1) can be estimated


dv(t )
c

v(ti +1 )= v(ti ) + g v(ti ) (ti +1 ti )= v(ti ) + i t


dt
m
11

Numerical Solution to the Falling Parachutist


Example 1.2
Employ a step size of 2 s: v(t + 2) = v(t ) + 2 *[9.8
0.25
v(2) = v(0) + 2 * [9.8
v(0)] = 19.62 m/s
68.1
v(4) = v(2) + 2 * [9.8

0.25
v(2)] = 36.4137 m/s
68.1

0.25
v(t )]
68.1
T, sec

V m/s

0.00

19.6200

36.4137

46.2983

50.1802

10

51.3123

12

51.6008

51.6938 12

Numerical versus Analytical Solution

Error = True Value - Approximate

13

Programming and Software


We are going to use the computer as a tool to obtain
numerical solutions to a given engineering model.
Selected software- MATLAB

MATLAB is originally developed as a matrix laboratory.


MATLAB is closely related to programming.
14

Errors
Why errors are a concern?

For many engineering problems, we cannot obtain exact solutions.


Numerical methods yield approximate results, results that are close
to the exact solution.
The question is How much error is present in our calculation and
is it tolerable?

15

Errors --- Falling Parachutist


T, sec

0
2
4
6
8
10
12

Parachutist Speed V(m/s)


Analytical
Numerical
Solution
Solution
(Exact)
(Approximate)
0
0
18.7292
19.6200
33.1118
36.4137
42.0762
46.2983
46.9575
50.1802
49.4214
51.3123
50.6175
51.6008
51.6938
51.6938

Absolute
Error
(m/s)
0
0.8908
3.3019
4.2221
3.2227
1.8909
0.9833
0

16

Accuracy Vs. Precision


Bullet holes

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 others

17

Precision and Accuracy


Precision and accuracy are two independent quantities: one can be

precise but inaccurate or vice versa. For Example, the radar guns
used by police may measure the speed of five vehicles traveling at
100 km/h as 96, 99, 105, 102, and 103 km/h, while the new laser
speed detectors measure the same speeds as 100 km/h, 100, 99,
100, and 101 km/h. The first set of readings are accurate but not
very precise while the second set of readings are accurate and more
precise.
18

Precision and Accuracy


Accuracy. How close is a computed or measured value to the true

value
Precision (or reproducibility). How close is a computed or measured
value to previously computed or measured values.
Inaccuracy (or bias). A systematic deviation from the actual value.
Imprecision (or uncertainty). Magnitude of scatter.

19

Precision and Accuracy


Precision

Precision describes how many digits we use to approximate a


particular value. It is very possible to have a very precise
approximation which is not very accurate.
Accuracy

Accuracy describes how close an approximation is to a correct answer.


We will see how we can describe accuracy using either absolute or
relative error

20

Error Definition
True Error

The discrepancy between the true and approximate values


There are two problems with using the true error:

Error
= E=
True Value Approximation
t
Significance: It gives you a feeling of the size of the error but how
significant is the error
Units: The true error will change depending on the units used. The
error of the approximation 2.4 MV of an actual voltage of
2.573243 MV is 0.17 MV, whereas the error of the approximation
2400000 V to an actual voltage of 2573243 V is 170000 V.
21

Error Definition
Relative Error

compare the error relative to the correct value. Thus, we define the
relative error to be the ratio between the true error and the value of
the correct value
t =

True Value Approximation


*100%
True Value

In this equation, any units cancel, so the relative errors of the


approximations 2.4 MV and 2400000 V versus the actual voltages
of 2.573243 MV and 2573243 V, respectively, are equal. Also, a
relative error of 0.01 means that the approximation is correct to
within one part in one hundred, regardless of the size of the actual
value.
22

Error Definition
If we cannot solve the problem analytically to get the true value, how
to calculate its true error?
We normalize the error to approximate value.
Numerical methods use iterative approach to compute answers. A
present approximation is made on the basis of a previous approximation.
Percent relative error,

current approximation previous approximation


a =
100%
current approximation
23

Error Definition
Absolute Relative Approximate Error

a = ( approximation error / approximation ) *100%


Iterative methods:
current approximation previous approximation
a =
100%
current approximation

Stopping Criterion

a s ( percent tolerance )

24

Error Definition
Result is correct/almost exact after the iteration to at least n

significant figures. n = 1,2,3

s = (0.5 * 10 2-n )%

a s

Maclaurin series expansion for ex is given as


x2 x3
xn
x
e =1 + x +
+
+ .... +
n!
2
3!

To ensure correct results for 3 significant figures

s =
(0.5 10 2 3 ) =
0.05%
25

Example
ex

x2 x3
xn
=1 + x +
+
+ .... +
n!
2
3!

s =
(0.5 10 2 3 ) =
0.05%

We add terms until a falls below s, for example for x=0.5, then
2
3
n
0.5
0.5
0.5
e0.5 =1 + 0.5 +
,
+
+ .... +
2
3!
n!

(2)

e x (k ) e x (k 1) x k 1 / (k 1)!
.
=
m
x
k
x
e (k )

m=0 m !

m
x
e x =
m=0 m !
m

k is term No

0.51 /1!
100% 0.5
/1.5 33.3%
=
=
m
2
0.5

m =0 m !

Terms

Results

a %

1.5

33.3

1.625

7.69

1.645833333

1.27

1.648437500

0.158

1.648697917

0.0158
26

Significant Figures
Significant digits of a number are those that can be used with confidence,
e.g., the number of certain digits plus one estimated digit.
53,800 How many significant figures?
5.38 x 104
5.380 x 104
5.3800 x 104

3
4
5

27

Significant Figures
Zeros are sometimes used to locate the decimal point not significant
figures.
0.00001753
0.0001753
0.001753

4
4
4

Number of significant figures indicates precision.

28

Types of Errors- Round-off Errors


Numbers such as , e, or
of significant figures.

7 cannot be expressed by a fixed number

The discrepancy introduced by error of significant figures is called


round-off error.

29

Types of Errors- Truncation Errors

Truncation errors are those that result from using an approximation in


place of an exact mathematical procedure.

30

Types of Errors
Overflow: Any number larger than the largest number that can be

expressed on a computer will result in an overflow.


Underflow (Hole) : Any positive number smaller than the smallest

number that can be represented on a computer will result an underflow.


Stable Algorithm: In extended calculations, it is likely that many

round-offs will be made. Each of these plays the role of an input error
for the remainder of the computation, impacting the eventual output.
Algorithms for which the cumulative effect of all such errors are
limited, so that a useful result is generated, are called stable
algorithms. When accumulation is devastating and the solution is
overwhelmed by the error, such algorithms are called unstable.
31

Taylor Series
A mathematical formulation that used widely in numerical methods to
predict a function value in approximate fashion.

Why it is called series?


Its build term by term, started with zero-order approximation. The
higher the order of approximation applied, the lower the truncation error.

32

The Taylor Series Approximation


Second-order Approximation:
f ( xi +1 ) f ( xi ) + f ' ( xi )( xi +1 xi ) +

f ' ' ( xi )
( xi +1 x1 ) 2
2!

and so on
f ' ' ( xi )
( xi +1 xi ) 2
2!
f ( n ) ( xi )
3
xi ) + .......... +
( xi +1 xi ) n + Rn
n!

f ( xi +1 ) f ( xi ) + f ' ( xi )( xi +1 xi ) +
+

( 3)

( xi )
( xi +1
3!

where Rn

is a remainder term
33

The Taylor Series Approximation

34

35

The Taylor Series Approximation


Zero-order approximation: f ( xi +1 ) f ( xi )
Additional terms of the Taylor series are required to provide a better
estimate.
First-order approximation:
f ( xi +1 ) f ( xi ) + f ' ( xi )( xi +1 xi )

The additional term consist of a slope multiply the distance between xi


and xi+1

36

The Taylor Series Approximation


Second-order Approximation:
f ( xi +1 ) f ( xi ) + f ' ( xi )( xi +1 xi ) +

f ' ' ( xi )
( xi +1 x1 ) 2
2!

and so on
f ' ' ( xi )
( xi +1 xi ) 2
2!
f ( n ) ( xi )
3
xi ) + .......... +
( xi +1 xi ) n + Rn
n!

f ( xi +1 ) f ( xi ) + f ' ( xi )( xi +1 xi ) +
+

( 3)

( xi )
( xi +1
3!

where Rn

is a remainder term
37

The Taylor Series Approximation


Remainder term:
Rn

f n + 1 ( )
( xi + 1 x1 )n + 1
( n + 1)!

Rn = O( hn +1 )

where is a value lies between xi and xi+1


Simplifying h= (xi+1 xi), hence,

f ' ' ( xi ) 2
f ( xi +1 ) f ( xi ) + f ' ( xi ) h +
h
2!
f ( 3) ( xi ) 3
f ( n ) ( xi ) n
+
h + .......... +
h + Rn
3!
n!
38

The Taylor Series Approximation


is not known exactly, lies somewhere between xi+1> >xi .
Need to determine f n+1(x), to do this you need f'(x).
If we knew f(x), there wouldnt be any need to perform the Taylor

series expansion.
However, R=O(hn+1), (n+1)th order, the order of truncation error is

hn+1.
O(h), halving the step size will halve the error.
O(h2), halving the step size will quarter the error.

39

Example
Use Taylor Series to approximate f(x) = cos(x) at xi =/4 on the basis
of value of xi+1 = /3
The correct value f ( / 3) = 0.5
Zero-order approximation is f( /3) f(/4) = 0.707106781
& relative error
t

0.5 0.707106781
=
100% 41.4%
0.5

First-order approximation is
f ( / 3) cos( / 4) + (- sin(/4) (/3 - /4) = 0.521986659

t = 4.41%
40

Example
Use Taylor Series to approximate f ( x) = Cos x at xi = / 4
on the basis of value of xi +1 = / 3
Order
n

f ( n ) ( x)

f ( / 3)

Cos x

0.707106781

-41.4

-Sin x

0.521986659

-4.4

-Cos x

0.497754491

0.449

Sin x

0.499869147

0.0262

Cos x

0.500007551

-0.00151

-Sin x

0.500000304

-0.0000608

-Cos x

0.499999988

0.00000244

41

Das könnte Ihnen auch gefallen