Sei sulla pagina 1di 77

users.isc.tuc.gr/~adelis/ENG407.

html users isc tuc gr/~adelis/ENG407 html

Lectures 1 2 L t 1-2

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

Logistics
Lectures: 09:00-11:00 Mon-Tue and Thu-Fri
announced the day before!!) (location will be

Lab Sessions: Tue 11:00 13:00 (Lab Instructor : Marianna Papadomanolaki) Textbook: Numerical Methods for Engineers by Steven C. Chapra and
Raymond P Canale McGraw Hill N Y 5th edition 2006 P. Canale, Hill, N.Y., edition, 2006.

Office Hours: at the New Sciences Building: Department of Sciences


(Office 145.B.99)

Course Evaluation (under negotiation!): Quizzes (30%), Assignments (25%) and a Final Exam (45%) (closed books closed notes) adelis@science.tuc.gr
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

What are Numerical Methods?


Techniques by which mathematical p problems are formulated so that they can y be solved with arithmetic operations {+,-,*,/} {+ * /} that can then be performed by a computer.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

Why You Need to Learn Numerical Methods?


During your career, you may often need to use commercial computer programs (canned programs) that involve numerical methods You need to know the basic theory of methods. numerical methods in order to be a better user. Numerical methods are extremely powerful problem-solving tools. You will often encounter problems that cannot be solved by existing canned programs; you must write your own program of numerical methods. Numerical methods are an efficient vehicle for learning to use computers. Numerical methods provide a good opportunity for you to reinforce your understanding of mathematics. f f You need that in your life as an engineer or a scientist
Part 1 (Chapters 1-4) 4


Dr A.I. Delis TUC 2010

Motivation

(a) Pre-computer era

(b) Computer era

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

Problems to solve in this course


Roots of equations: concerns with finding the value of a variable that satisfies a single nonlinear equation especial valuable in engineering design where it is often impossible to explicitly solve design equations of parameters. Systems of linear equations: a set of values is sought that simultaneously satisfies a set of linear algebraic equations. They arise in all disciplines of engineering, e.g., structure, electric circuits, fluid networks; also in curve fitting and differential equations. Optimization: determine a value or values of an independent variable that correspond to a best or best optimal value of a function. It occurs routinely in engineering contexts. (not in this course) Curve fitting: to fit curves to data points. Two types: regression and interpolation. Experimental results are often of the first type. Integration: determination of the area or volume under a curve or a surface. It has many applications in engineering practice.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

Problems to solve (cont)

Ordinary differential equations: very important in engineering practice, because many physical laws are couched in terms of the rate of change of a quantity rather than the magnitude of the q g q y g quantity itself. Initial value and boundary value y y problems. Partial differential equations: used to characterize engineering systems where the behavior of a physical quantity is couched in terms of the rate of change with respect to two or more independent variables. Examples: steady-state distribution of temperature of a heated plate (two spatial dimensions) or the time-variable temperature of a heated rod (time and one spatial dimension), fluid flows etc.. Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

Mathematical Modeling and Engineering Problem solving


Chapter 1

Requires understanding of engineering systems


By observation and experiment (empiricism) Theoretical analysis and generalization y g These two are closely coupled (with a two way connection as one compliments the other).

Computers are great tools, however, without fundamental understanding of engineering problems, g g g p , they will be useless.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

What is the relationship between mathematic modeling and engineering problem-solving? bl l i ?

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

A mathematical model is represented as a functional p relationship of the form

Dependent Variable =f

independent forcing variables, parameters, functions

Dependent variable: Characteristic that usually reflects the state of the system I d Independent variables: Dimensions s ch as time and space d t i bl : such along which the systems behavior is being determined Parameters: reflect the systems properties or composition system s Forcing functions: external influences acting upon the system

Part 1 (Chapters 1-4)

10

An Example: Newtons 2nd law of Motion Newton s


States that the time rate change of momentum f y q gf g of a body is equal to the resulting force acting on it. The model is formulated as F = m a (1.2) F=net force acting on the body (N) m=mass of th object (kg) f the bj t (k ) a=its acceleration (m/s2) (
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

11

F Formulation of N t 2nd l l ti f Newtons law h several has l characteristics that are typical of mathematical models of the physical world:
It describes a natural process or system in p y mathematical terms It represents an idealization and simplification of reality (focuses on its essential manifestations). Finally it yields reproducible results consequently Finally, results, consequently, can be used for predictive purposes, e.g. a = m/F /F

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

12

Some mathematical models of physical phenomena may be much more complex. Complex models may not be solved exactly or Co p e ode s y o so ved e c y o require more sophisticated mathematical techniques than simple algebra for their solution. p g
Example modeling of a falling parachutist: Example,

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

13

dv F d = dt m F = FD + FU FD = mg FU = cv dv mg cv g = dt m
Dr A.I. Delis TUC 2010

v=t terminal velocity ( / ) i l l it (m/s) t = time (s) m = mass of the object ( g) j (kg)
g = gravitational constant (9.81 m/s2)

c = drag coefficient (kg/s)

Part 1 (Chapters 1-4)

14

dv c =g v dt m
This is a differential equation and is written in terms of the differential rate of change dv/dt of the variable that we are interested in predicting. If the parachutist is initially at rest (v=0 at t=0), using calculus we get an analytical (or exact) solution

gm ( c / m ) t v(t ) = 1 e c Dependent variable


Forcing function
Dr A.I. Delis TUC 2010

Independent variable

Parameters
15

Part 1 (Chapters 1-4)

Solution for differential equation cannot always be solved analytically using simple algebraic solution solution. The exact solution for differential equation can be solved using calculus or by g y approximation using numerical methods.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

16

For steady-state condition in falling parachute,

We have

thus,

dv =0 dt

mg v= c

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

17

Conservation Laws and Engineering


Conservation laws are the most important and g g fundamental laws that are used in engineering. Change = increases decreases (1.13) Ch Change implies changes with time (transient). i li h ih i ( i ) If the change is nonexistent (steady-state), e c ge s o e s e (s e dy s e), Eq. (1.13) becomes Increases =Decreases I D
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

18

Fig 1.6

For steady-state incompressible fluid flow in pipes: Flow in = Flow out or 100 + 80 = 120 + Flow4 Flow4 = 60
In general we are interested in conservation of mass, momentum and energy
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

19

Practical issues in engineering applications


Linearity vs Nonlinearity: Linearization in order to
p permit analytical solutions. y

Large vs small systems: With computers and numerical


methods large scale and multi-component systems can be g p y examined.

Ideal vs nonideal laws:


engineering, nonideal laws computationally demanding. p y g conditions.

Idealized laws abound in are more realistic but

Sensitivity Analysis: how a system responds to different Design: determine a systems parameters to a required performance.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

20

Programming and Software g g


Chapter 2

Objective is how to use the computer as a tool g to obtain numerical solutions to a given engineering model. There are two ways in g p using computers:
Use available software Or write computer programs to extend the Or, capabilities of available software, such as Excel and Matlab.
Engineers should not be tool limited, it is important that they should be able to do both!
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

21

Computer programs are set of instructions that direct the p p g computer to perform a certain task. To be able to perform engineering-oriented numerical calculations, you should b f ili l l ti h ld be familiar with th f ll i ith the following programming topics:
Simple information representation (constants, variables, and type p f p ( , , yp declaration) Advanced information representation (data structure, arrays, and records) Mathematical formulas (assignment, priority rules, and intrinsic functions) Input/Output Logical representation (sequence, selection, and repetition) Modular programming (functions and subroutines)

We will focus the last two topics, assuming that you have some prior exposure to programming.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

22

Structured Programming
Structured programming is a set of rules that prescribe god style habits for programmer.
An organized well structured code organized, Easily sharable Easy to debug and test Requires shorter time to develop, test, and update

Th k id i th t any numerical algorithm can The key idea is that i l l ith be composed of using the three fundamental structures: t t
Sequence, selection, and repetition
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

23

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

24

Sequence: Computer code must be implemented one p instruction at a time, unless you instruct y otherwise. The structure can be expressed as a flowchart or pseudocode.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

25

Selection: Splits the programs flow into branches based on b d outcome of a logical condition condition.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

26

Repetition: means to implement instructions repeatedly.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

27

Modular Programming
The computer programs can be divided into subprograms, or modules, that can be developed and tested separately. Modules should b as i d d l h ld be independent and self contained d d lf i d as possible. Advantages to modular d i are: d d l design
It is easier to understand the underlying logic of smaller modules They are easier to debug and test Facilitate program maintenance and modification Allow you to maintain your own library of modules for later use
Part 1 (Chapters 1-4) 28

Programming and Software


We W are going to use the computer as a i t th t tool to obtain numerical solutions to a given engineering model. Selected soft are MATLAB softwareMATLAB is originally developed as a matrix laboratory. MATLAB is closely related to programming programming.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

29

Familiar yourself with MATLAB !!

How to do it??
1) Install MATLAB software in your notebook. 2) Explore yourself the Appendix B in Chapra ( ) and Canale (2006). 3) Try any other exercises. 4) Check th answers MATLAB gave Ch k the and make sure you understand them.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

30

Dr A.I. Delis TUC 2007

Part 1 (Chapters 1-4)

31

Approximations and Round-Off Errors pp


Chapter 3 F many engineering problems, we cannot obtain analytical For i i bl t bt i l ti l solutions. Numerical methods yield approximate results, results that y pp , are close to the exact analytical solution. We cannot exactly compute the errors associated with numerical methods.
Only rarely given data are exact, since they originate from O y a e y g ve a e e act, s ce t ey o g ate o measurements. Therefore there is probably error in the input information. Algorithm itself usually introduces errors as well, e.g., unavoidable round-offs, etc The output information will then contain error from both of these sources.

How confident we are in our approximate result? The question is how much error is present in our calculation and is it tolerable? tolerable?
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

32

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. p Inaccuracy (or bias). A systematic deviation from the actual value value. Imprecision (or uncertainty). Magnitude of scatter.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

33

Accuracy?

Inaccuracy?

Precision? Imprecision? I i i ?

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

34

In numerical methods, we use approximation , pp to represent the exact mathematical operations.


Numerical errors rise

Numerical error equal to discrepancy between pp the truth and approximation: true error

E t = t r u e v a l u e a p p r o x i m a ti o n
True percent relative error,

t r u e e r r o r 100% t = tr u e v a l u e
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

35

Error Definitions
True Value = Approximation + Error Et = True value Approximation ( / ) (+/-)
True error

true error True fractional l ti T f ti l relative error = true value true error 100% True percent relative error, t = true value
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

36

If we cannot solved 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 answers. made on the basis of a previous approximation. Percent relative error, a

c u r r e n t a p p r o x .- p r e v i o u s a p p r o x .100% a = c u rr e nt a p p r o x.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

37

For numerical methods, the true value will be known only when we deal with functions that y can be solved analytically (simple systems). In real world applications, we usually not know the pp , y answer a priori. Then

Approximate error A i t a = 100% pp Approximation


Iterative approach, example Newtons method
Current approximation - Previous approximation a = 100% Current approximati C t i tion

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

38

The a may be in + or signs. But, the most important is its absolute value value. The Th calculation should proceed until th l l ti h ld d til the absolute value of a lower than percent tolerance given, s .

a < s
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

39

Result is correct/almost exact after the iteration to at least n significant figures. , , n= 1,2,3.

s = 0.510

2 n

)%

(See Example 3.2)


Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

40

Use absolute value. Computations are repeated until stopping criterion is satisfied. satisfied

a s

Pre-specified % t l P ifi d tolerance b based d on the knowledge of your solution

If the following criterion is met

s = (0.5 10(2-n) )%
you can be sure that the result is correct to at least n significant figures.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

41

Significant Figures g g
Number of significant figures indicates precision. Significant digits of a number are those that can be used with confidence, e.g., the number of certain di i plus one estimated di i i digits l i d digit. 53,800 How many significant figures? 5.38 x 104 5.380 x 104 5.3800 x 104 3 4 5

Zeros are sometimes used to locate the decimal point not significant figures. 0.00001753 0 00001753 0.0001753 0.001753
Dr A.I. Delis TUC 2010

4 4 4
Part 1 (Chapters 1-4) 42

Type of errors: Round-off Errors Round off


Numbers such as , e, or 7 cannot be expressed by a fixed number of significant figures. Computers use a base-2 representation, they cannot p precisely represent certain exact base-10 numbers. y p Fractional quantities are typically represented in computer using floating point form, e.g., floating point
Integer part

m be
mantissa

exponent Base of the number system used

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

43

Figure 3.3

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

44

Figure 3.4

Representation of the decimal integer -173 on a 16-bit computer

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

45

Figure 3.5

The manner in which a floating point number is stored

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

46

156.78

0.15678x103 in a floating point base-10 system

Suppose only 4 1 = 0.029411765 decimal places to be stored 34 1 0 0.029410 m <1 b

Normalized to remove the leading zeroes. g Multiply the mantissa by 10 and lower the exponent by 1 p y 0.2941 x 10-1 Additional significant figure
is retained
Part 1 (Chapters 1-4) 47

Dr A.I. Delis TUC 2010

1 m <1 b

Therefore for base-10 system f ab 10 t 0.1 m<1 01 1 for a base-2 system 0.5 m<1 See example 3.4

Floating point representation allows both fractions and very l large numbers t b expressed on th computer. b to be d the t However, Floating point numbers take up more room room. Take longer to process than integer numbers. Round-off errors are introduced because mantissa Round off holds only a finite number of significant figures.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

48

Significance of floating point representation Strange behavior of the machine numbers 1+x 1 = 1 !!! E = For F

x b1- t

b1-t

is called the machine epsilon epsilon.

Limited range of quantities that may be represented g q y p (overflow and underflow may occur) Fi it number of quantities can b represented within th Finite b f titi be t d ithi the range (precision is limited e.g. irrational numbers)

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

49

Type of errors: Chopping


Example: p =3.14159265358 to be stored on a base-10 system y g g g carrying 7 significant digits. =3.141592 chopping error t=0.00000065 If rounded =3.141593 t=0.00000035 Some machines use chopping, because rounding adds chopping to the computational overhead. Since number of significant figures is large enough, resulting chopping error is negligible.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

50

Types of errors: T T f Truncation error ti Truncation errors are th T ti those th t result f that lt from using an approximation in place of an exact mathematical procedure.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

51

The T l 4 i Th Taylor series Chapter A mathematical formulation that used widely in numerical methods to predict a function value i approximate f hi f ti l in i t fashion. Why it is called in series? Its build term by term, started with zero-order y , approximation. The higher the order of approximation applied the lower the applied, truncation error.
Dr A.I. Delis TUC 2010

Taylor Series y

Part 1 (Chapters 1-4)

52

Non-elementary functions such as trigonometric, y g , exponential, and others are expressed in an approximate fashion using Taylor series when their pp g y values, derivatives, and integrals are computed. Any smooth function can be approximated as a polynomial. polynomial Taylor series provides a means to predict the value of a function at one point in terms of the function value and its derivatives at another point.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

53

nth order approximation


f 2 ( xi )( xi +1 xi ) + f ( xi +1 ) f ( xi ) + f ( xi +1 xi ) + 2! f (n) ( xi +1 xi ) n + Rn + n! n!

(xi+1-xi)= h
( n +1)

step size (define first)

f ( ) ( n +1) Rn = h (n + 1)!
R i d term, Rn, accounts for all terms Reminder t t f ll t from (n+1) to infinity.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

54

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

55

Zero-order approximation:

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

f ( xi +1 ) f ( xi ) + f ' ( xi )( xi +1 xi )
The additional term consist of a slope multiply the distance between x i and x i + 1 .
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

56

Second-order approximation:

f ' ' (xi ) 2 f (xi+1) f (xi ) + f ' (xi )(xi+1 xi ) + (xi+1 x1) 2!
and so on d

f ' ' (xi ) 2 f (xi+1) f (xi ) + f ' (xi )(xi+1 xi ) + (xi+1 xi ) 2! (3) (n) f (xi ) f (xi ) n 3 + (xi+1 xi ) +.......... + (xi+1 xi ) + Rn 3! n! where Rn is the remainder term
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

57

Remainder term: f n+1 ( ) n+1 Rn = ( xi +1 x1 ) (n + 1)! where

is a value lies between xi and xi +1

Simplifying h = ( x i + 1 x i ) , hence,

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


Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

58

i not k is known exactly, li l lies somewhere h 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 expansion. However, R=O(hn+1), (n+1)th order, the order of truncation error i hn+1. t ti is O(h), halving the step size will halve the error. O(h2), halving the step size will quarter the error.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

59

Example: To get the cos(x) for small x:

x2 x4 x6 cos x = 1 + + 2! 4! 6!
If x=0.5 ( ) cos(0.5) =1-0.125+0.0026041-0.0000127+ =0.877582 From the supporting theory, for this series the error theory series, is no greater than the first omitted term.

x8 8!
Dr A.I. Delis TUC 2010

for

x = 0.5 = 0.0000001
Part 1 (Chapters 1-4) 60

Fig 4 2 4.2

Dr A.I. Delis TUC 2007

Part 1 (Chapters 1-4)

61

How to solve the derivatives of an equation given using Taylor series? We use an approximation using numerical differentiation with: a) F ) Forward divided diff d di id d difference b) Backward divided difference c) Centered divided difference They Th are d developed f l d from th T l series the Taylor i to approximate derivatives numerically.
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

62

a) Forward divided diff )F d di id d difference (1stt d i ti ) derivative)


f ( xi +1 ) f ( xi ) f ' ( xi ) = + O ( h) xi +1 xi

where h

O (h) =

(2)

( xi )( xi +1 xi ) 2!

O (h ) is an truncation error.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

63

b) Backward divided difference (1st derivative) ) ( )

f ( xi ) f ( xi 1 ) f ' ( xi ) = xi ( xi 1 )
c) Centered divided difference (1st derivative) f ( xi +1 ) f ( xi 1 ) f ' ( xi ) = + O(h 2 ) 2( xi +1 xi ) where h
Dr A.I. Delis TUC 2010

f ( 3) ( xi )( xi +1 xi ) 2 O (h 2 ) = 3!
Part 1 (Chapters 1-4) 64

Fig 4 6 4.6

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

65

Error Propagation
fl(x) refers to the floating point (or computer) p representation of the real number x. Because a computer can hold a finite number of significant figures for a given number there number, may be an error (round-off error) associated with th fl ti ith the floating point representation. Th i t t ti The error is determined by the precision of the computer ().
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

66

Suppose that we have a function f(x) that is dependent on a single independent variable x. fl(x) is an approximation of x and we would like to estimate the effect of discrepancy between x and fl(x) on the value of the function:
f ( x fl ) = f ( x) f ( x fl ) both f(x) and xfl are unknown

Employ Taylor series to compute f(x) near f(x fl ), dropping the second and higher order terms f ( x) f ( x fl ) f ( x fl )( x x fl )

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

67

Fig 4 7 4.7

Dr A.I. Delis TUC 2007

Part 1 (Chapters 1-4)

68

Also, let t, the fractional relative error, be the error associated with fl(x). Then

fl ( x) x x

= t

where t

Machine epsilon, epsilon upper boundary

Rearranging, we get

fl ( x) x = t x f fl ( x) = x( t + 1)
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

69

Case 1: Addition of x1 and x2 with associated errors t1 and t2 yields the following result: d i ld th f ll i lt fl(x1)=x1(1+t1) fl(x2)=x2(1+t2) fl(x1)+fl(x2)=t1 x1+t2 x2+x1+x2

fl ( x1 ) + fl ( x2 ) ( x1 + x2 ) t1 x1 + t 2 x2 = = 100% x1 + x2 x1 + x2
A large error could result from addition if x1 and x2 are A almost equal magnitude but opposite sign, therefore one should avoid subtracting nearly equal numbers. numbers
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

70

Generalization: Suppose the numbers fl(x1) fl(x2) fl(x3) , fl(xn) are ), ), ), approximations to x1, x2, x3, ,xn and that in each case the maximum possible error is E. E Eti E fl(xi)-E xi fl(xi)+E It f ll follows by addition that b dditi th t

fl ( x ) nE x fl ( x ) + nE
i i i

So that

nE xi fl ( xi ) nE
Therefore, the maximum possible error in the sum of fl(xi) is nE .
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

71

Case 2: Multiplication of x1 and x2 with associated errors et1 and et2 results in:

fl ( x1 ) fl ( x2 ) = x1 (1 + t1 ) x2 (1 + t 2 ) fl ( x1 ) fl ( x2 ) = x1 x2 ( t1 t 2 + t1 + t 2 + 1) fl ( x1 ) fl ( x2 ) x1 x2 = = t1 t 2 + t1 + t 2 100% x1 x2

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

72

Since t1, t2 are both small, the term t1t2 should be small relative to t1+t2. Thus the magnitude of the error associated with one multiplication or division step should be t1+t2. t1 (upper bound) Although error of one calculation may not be significant, if 1000 calculations were done, the error g , , is then approximately 1000. The magnitude of error associated with a calculation is directly proportional to the number of multiplication steps. Refer to Table 4.3
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

73

Overflow: Any number larger than the largest number that can be e pressed on a comp ter will res lt in an o erflo expressed computer ill result 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 th solution i overwhelmed b th error, i d t ti d the l ti is h l d by the such algorithms are called unstable.

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

74

Try for yourself


Given Gi

f ( x) = 0.1x 0.15 x 0.5 x 0.25 x + 1.2


4 3 2

at x =0.25. The derivative can be calculated directly as

f ' ( x) = 0.4 x 0.14 x 1.0 x 0.25


3 2

and can be used to compute the exact value as f ' ( x) =-0.9125. (x 0.9125. a) Use forward, backward and centered difference approximations t estimate the first derivative. i ti to ti t th fi t d i ti b) Calculate the true percent relative error, t .
Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

75

HOMEWORK 1
Chapra and Canale (2006): Problems 3.1,3.2,3.6,3.7,3.10 Problems 4.1,4.2,4.4,4.6,4.7

Dr A.I. Delis TUC 2010

Part 1 (Chapters 1-4)

76

Trade-offs Type of Mathematical Problem (Model) Type, Availability, Cost, and Speed of Computer Program Development Cost vs Software Cost Characteristics of the Numerical Method:
1. 2. 3. 4. 5. 6. 7. Number of Initial Guesses Rate of Convergence g Stability (of numerical algorithm) Accuracy and Precision Breadth of Application Special Requirements Programming Effort

Maintenance (of programming codes) Ease of Application (user-friendly?) Mathematical Behavior:(Ill or Well-) Conditioned (function, data ..)
Dr A.I. Delis TUC 2007

Part 1 (Chapters 1-4)

77

Potrebbero piacerti anche