Numerical Methods

107 downloads 1066 Views 1MB Size Report
Example of Solving an Engineering. Problem. Bascule Bridge THG the Bridge of Lions in. St. Augustine, Florida. Autar Kaw http://numericalmethods.eng.usf.edu.
Numerical Methods

Lecture 1. Introduction to numerical methods

dr hab.inż. Katarzyna Zakrzewska, prof. AGH, Department of Electronics, AGH e-mail: [email protected] http://home.agh.edu.pl/~zak Numerical Methods - Lecture 1

1

Introduction to numerical methods Numerical methods are a part of applied mathematics focused on the development of approximate methods for solving mathematical problems that can not be solved either by the exact methods or the exact methods have such a large computational complexity that are useless Numerical methods are involved in constructing algorithms in which the input data, intermediate results and final results are represented by numbers Numerical Methods - Lecture 1

2

Introduction to numerical methods

Characteristics of numerical methods: • calculations are performed on approximate numbers • solutions are expressed as approximate numbers • error in the numerical calculation should be always controlled

Numerical Methods - Lecture 1

3

References: • Z. Fortuna, B. Macukow, J. Wąsowski, Metody numeryczne, Podręczniki Akademickie EIT, WNT Warszawa,1982, 2005 • L.O. Chua, P-M. Lin, Komputerowa analiza układów elektronicznych-algorytmy i metody obliczeniowe, WNT, Warszawa, 1981 • G.Dahlquist, A.Björck, Metody matematyczne, PWN Warszawa, 1983 • Autar Kaw, Luke Snyder http://numericalmethods.eng.usf.edu

Numerical Methods - Lecture 1

4

Additional references: • M.Wciślik, Wprowadzenie do systemu Matlab, Wydawnictwo Politechniki Świętokrzyskiej, Kielce, 2000 • S. Osowski, A. Cichocki, K.Siwek, Matlab w zastosowaniu do obliczeń obwodowych i przetwarzania sygnałów, Oficyna Wydawnicza Politechniki Warszawskiej, Warszawa 2006 • W.H. Press, et al., Numerical recipes, Cambridge University Press, 1986

Numerical Methods - Lecture 1

5

Introduction to numerical methods

Outline • Solving engineering problems • Overview of typical mathematical procedures • Fixed and floating-point representation of numbers

Numerical Methods - Lecture 1

6

How to solve an engineering problem?

Problem Description Mathematical Model Solution of Mathematical Model Application of the Solution Numerical Methods - Lecture 1

7

Example of Solving an Engineering Problem Autar Kaw http://numericalmethods.eng.usf.edu

Bascule Bridge THG the Bridge of Lions in St. Augustine, Florida

Numerical Methods - Lecture 1

8

Bascule Bridge THG

Hub Trunnion Girder

Numerical Methods - Lecture 1

9

Trunnion-Hub-Girder Assembly Procedure

Step 1.

Trunnion immersed in dry-ice/alcohol (108 F, around -80 C)

Step 2.

Trunnion warm-up in hub

Step 3.

Trunnion-Hub immersed in dryice/alcohol

Step 4.

Trunnion-Hub warm-up into girder

Numerical Methods - Lecture 1

10

A problem occurred!

After cooling, the trunnion got stuck in the hub

Numerical Methods - Lecture 1

11

Why did it get stuck?

Magnitude of contraction of the trunnion was expected to be 0.015” or more. Did it contract enough?

Numerical Methods - Lecture 1

12

Calculations

ΔD = D × α × ΔT D = 12.363 "

α = 6.47 × 10 in / in / F −6

o

ΔT = −108 − 80 = −188 F o

Δ D = (12 . 363 )( 6 . 47 × 10

−6

)( − 188 )

= − 0.01504" Numerical Methods - Lecture 1

13

Units 1 in = 2.54 cm

D = 12.363" ≈ 31,4cm 0

⎞ ⎛9 TF = ⎜ TC + 32 ⎟ F ⎝5 ⎠

T = 80 o F ≈ 26,7 0 C

Δ D = 0 . 01504 in = 0 . 03820 cm Numerical Methods - Lecture 1

14

Is the formula used correct?

ΔD = D × α × ΔT

ΔD = D α ΔT

Numerical Methods - Lecture 1

T(oF)

α (μin/in/F)

-340

2.45

-300

3.07

-220

4.08

-160

4.72

-80

5.43

0

6.00

40

6.24

80

6.47 15

Problem solving The correct model should account for varying thermal expansion coefficient α

Tc

ΔD = D ∫ α (T )dT Ta

Numerical Methods - Lecture 1

16

Can you roughly estimate the contraction? Tc

ΔD = D∫α(T )dT

Ta=80F; Tc=-108F; D=12.363”

Ta

Tc

ΔD = D∫α (T )dT Ta

Numerical Methods - Lecture 1

17

Estimating Contraction Accurately

Change in diameter (ΔD) by cooling it in dry ice/alcohol is given by Tc

ΔD = D ∫ α (T ) dT Ta

Ta = 80oF Tc = -108oF D = 12.363" −5 2 −3 α = −1.2278 × 10 T + 6.1946 × 10 T + 6.0150

ΔD = −0.0137 " Numerical Methods - Lecture 1

to small!!! 18

So what is the solution to the problem? One solution is to immerse the trunnion in liquid nitrogen which has a boiling point of -321F as opposed to the dry-ice/alcohol temperature of 108F.

ΔD = −0.0244 "

Numerical Methods - Lecture 1

19

Revisiting steps to solve a problem

1) Problem statement: trunnion stuck in the hub 2) Modeling: a new model Tc

ΔD = D ∫ α (T )dT Ta

3) Solution: a) trapezoidal rule or b) regression and integration. 4) Implementation: cool the trunnion in liquid nitrogen. Numerical Methods - Lecture 1

20

Mathematical Procedures • • • •

Nonlinear Equations Differentiation Simultaneous Linear Equations Curve Fitting – Interpolation – Regression

• Integration • Ordinary Differential Equations • Other Advanced Mathematical Procedures: – Partial Differential Equations – Optimization – Fast Fourier Transforms Numerical Methods - Lecture 1

21

Nonlinear Equations How much of the floating ball is under water?

2R=0.11m −4

x − 0.165 x + 3.993 × 10 = 0 3

Numerical Methods - Lecture 1

2

22

f ( x ) = x 3 − 0.165 x 2 + 3.993 × 10−4 = 0 Numerical Methods - Lecture 1

23

Numerical Methods - Lecture 1

24

Differentiation

What is the acceleration at t=7 seconds?

⎛ ⎞ 16 × 104 ⎟⎟ − 9.8t v(t) = 2200 ln⎜⎜ 4 ⎝ 16 × 10 − 5000t ⎠ Numerical Methods - Lecture 1

dv a= dt 25

Differentiation

Time (s)

5

8

12

V(m/s)

106

177

600

dv a= dt

Numerical Methods - Lecture 1

26

Simultaneous Linear Equations

Find the velocity profile, given: Time (s)

5

8

12

V (m/s)

106

177

600

v (t ) = at 2 + bt + c,

5 ≤ t ≤ 12

Three simultaneous linear equations:

25a + 5b + c = 106

64a + 8b + c = 177 144a + 12b + c = 600 Numerical Methods - Lecture 1

27

Interpolation

What is the velocity of the rocket at t=7 s? Time (s)

5

8

12

V (m/s)

106

177

600

Numerical Methods - Lecture 1

28

Regression

Thermal expansion coefficient data for cast steel

Numerical Methods - Lecture 1

29

Regression

Numerical Methods - Lecture 1

30

Integration

T fluid

ΔD = D ∫ α dT Troom

Numerical Methods - Lecture 1

31

Ordinary Differential Equations

How long does it take a trunnion to cool down?

dθ mc = − hA(θ − θ a ), θ (0) = θ room dt Numerical Methods - Lecture 1

32

What you need to know to create your own computing algorithms?

• the size of your computer's memory • the execution speed of arithmetic and logic operations • the acceptable range of numbers during the calculations • the accuracy of basic arithmetic operations performed on real numbers

Numerical Methods - Lecture 1

33

Numbers representation in a computer memory

The numbers are stored as • fixed-point numbers • floating-point numbers The computer works in the binary system, and communicates with the outside world in the decimal system, therefore conversion procedures are needed. This is a source of errors.

Numerical Methods - Lecture 1

34

Computer arithmetic How a Decimal Number is Represented

257.76 = 2 ×10 2 + 5 ×101 + 7 ×100 + 7 ×10 −1 + 6 ×10 −2 Base 2

⎛ (1× 23 + 0 × 2 2 + 1× 21 + 1× 20 ) ⎞ ⎟ (1011.0011) 2 = ⎜⎜ −1 −2 −3 −4 ⎟ ⎝ + (0 × 2 + 0 × 2 + 1× 2 + 1× 2 ) ⎠10 = 11.1875 In the binary system we use two digits: 0 and 1, called bits

Numerical Methods - Lecture 1

35

Convert base 10 integer to binary representation Quotient 11/2

5

5/2

2

2/2

1

1/2

0

Hence

Remainder

1 = a0 1 = a1 0 = a2 1 = a3

(11)10 = (a3 a 2 a1 a0 ) 2 = (1011) 2

Numerical Methods - Lecture 1

36

Start

Input (N)10

Integer N to be converted to binary format

i=0

Divide N by 2 to get quotient Q & remainder R

i=i+1,N=Q

ai = R

No Is Q = 0? Yes n=i (N)10 = (an. . .a0)2

STOP

http://numericalmethods.eng.usf.edu Numerical Methods - Lecture 1

37

Converting a base-10 fraction to binary representation

after Number before Number Number decimal decimal

0.1875 × 2 0.375 × 2 0.75 × 2 0.5 × 2

Hence

0.375

0.375

0.75

0.75

1.5

0.5

1.0

0.0

0 = a−1 0 = a− 2 1 = a− 3 1 = a− 4

(0.1875)10 = (a−1a− 2 a− 3a− 4 ) 2 = (0.0011) 2

Numerical Methods - Lecture 1

38

Start Fraction F to be converted to binary format

Input (F)10 i = −1

Multiply F by 2 to get number before decimal, S and after decimal, T

i = i − 1, F = T ai = R

No Is T =0? Yes n=i (F)10 = (a-1. . .a-n)2

STOP

Numerical Methods - Lecture 1

http://numericalmethods.eng.usf.edu

39

Decimal Number to Binary

(11.1875)10 = (

?.?

Since

(11)10 = (1011) 2

and

(0.1875)10 = (0.0011) 2

)2

we have

(11.1875)10 = (1011.0011) 2 Numerical Methods - Lecture 1

40

Different approach

(11.1875)10 (11)10 = 2

3

+3

= 2 + 2 +1 3

1

= 23 + 21 + 20 = 1× 2 + 0 × 2 + 1× 2 + 1× 2 3

2

1

0

= (1011)2 Numerical Methods - Lecture 1

41

Different approach

(0.1875)10 = 2

−3

+ 0.0625

−3

−4

=2 +2 −1

−2

−3

= 0 × 2 + 0 × 2 + 1× 2 + 1× 2

−4

= (.0011)2

(11.1875)10 = (1011.0011)2 Numerical Methods - Lecture 1

42

The problem of accuracy Example: Not all fractional decimal numbers cannot be represented exactly

0. 3 × 2 0. 6 × 2 0. 2 × 2 0. 4 × 2 0. 8 × 2

Number

Number after decimal

Number before decimal

0.6 1.2 0.4 0.8 1.6

0.6 0.2 0.4 0.8 0.6

0 = a−1 1 = a− 2 0 = a−3 0 = a− 4 1 = a− 5

(0.3)10 ≈ (a−1a− 2 a−3 a− 4 a−5 ) 2 = (0.01001) 2 = 0.28125 The accuracy depends on the computer words length. Rounding off and chopping off lead to errors. Numerical Methods - Lecture 1

43

Floating Point Representation

x = M ×Nw M - mantissa W - exponent N=2, 10 The notation floating point number is represented by two groups of bits: I – mantissa M, fractional part ½