Presentation is loading. Please wait.

Presentation is loading. Please wait.

Se-Woong Chung, Chungbuk National University 1 환경수치해석 Numerical Method for Environmental Engineers Se-Woong Chung Department of Environmental Engineering.

Similar presentations


Presentation on theme: "Se-Woong Chung, Chungbuk National University 1 환경수치해석 Numerical Method for Environmental Engineers Se-Woong Chung Department of Environmental Engineering."— Presentation transcript:

1 Se-Woong Chung, Chungbuk National University 1 환경수치해석 Numerical Method for Environmental Engineers Se-Woong Chung Department of Environmental Engineering Chungbuk National University

2 Se-Woong Chung, Chungbuk National University 2 PT1.1 Motivation: Engineering problem solving processes (a)The precomputer era (b) The computer era

3 Se-Woong Chung, Chungbuk National University 3 Class Overview (a)Part2: Roots of equations (b)Part3: Linear algebraic equations (c)Part4: Optimization (d)Part5: Curve fitting (e)Part6: Integration (f)Part7: ODE (g)Part8: PDE

4 Se-Woong Chung, Chungbuk National University 4 Class Overview

5 Se-Woong Chung, Chungbuk National University 5 Modeling, Computers, and Error Analysis PART 1

6 Se-Woong Chung, Chungbuk National University 6 Lecture Overview CHA 1. Mathematical Modeling and Engineering Problem Solving CHA 2. Programming and Software CHA 3. Approximations and Round-Off Errors CHA 4. Truncation Errors and the Taylor Series

7 Se-Woong Chung, Chungbuk National University 7 PT1.3 Schematic of the organization of Part One

8 Se-Woong Chung, Chungbuk National University 8 Study Objective of Part 1 Understand the difference between analytical( 해석해 ) and numerical( 수치해 ) solutions Understand how conservation laws are employed to develop mathematical models of physical systems Know the use of structured programming and start to familiarize with any software packages that you will be using Recognize the distinction between truncation and round- off errors ….

9 Se-Woong Chung, Chungbuk National University 9 CHAPTER 1. Mathematical Modeling and Engineering Problem Solving CHAPTER 1

10 Se-Woong Chung, Chungbuk National University 10 1.1 A Simple Mathematical Model Mathematical model: A formulation or equation that expresses the essential features of a physical system or process in mathematical terms Dependent Variable = f (independent variables, parameter, forcing functions) F = ma a = F / m

11 Se-Woong Chung, Chungbuk National University 11 Analytical Solution: Falling parachutist Terminal Velocity dv/dt = F / m F = F D + F U = mg – cv dv/dt = (mg – cv) / m dv/dt = g – (c / m) v : Nonhomogeneous Linear Differential Equation v(t) = mg/c (1 – e (-c/m)t ) : how can you obtain the analytical solution ? 공기저항은 낙하속도에 선형 비례 가정 c = drag coefficient, 항력계수, kg/s

12 Se-Woong Chung, Chungbuk National University 12 Ex. 1.1 Analytical Sol. to the Falling Parachutist Problem Excel Visual Basic Fortran Program 예제 1.1 해석해 (analytical solution), 엄밀해 (exact solution)

13 Se-Woong Chung, Chungbuk National University 13 Numerical Solution: Falling parachutist Finite divided difference approximation of derivative at time t i Finite divided difference approximation 유한제차분

14 Se-Woong Chung, Chungbuk National University 14 Euler’s Method New value = old value + slope * step size dv/dt =  v /  t = [v(t i+1 ) – v(t i )] / (t i+1 – t i ) Therefore, [v(t i+1 ) – v(t i )] / (t i+1 – t i ) = g –(c/m) v(t i ) v(t i+1 ) = v(t i ) + [g –(c/m) v(t i )] (t i+1 – t i ) Ex.1.2 Numerical Sol. to the Falling Parachutist Problem 예제 1.2 수치해 (numerical solution), 근사해 (approximate solution)

15 Se-Woong Chung, Chungbuk National University 15 Comparison of the numerical and analytical solutions Excel Visual Basic Fortran Program

16 Se-Woong Chung, Chungbuk National University 16 Option Explicit Function Euler(dt, ti, tf, yi, m, cd) Dim h As Single, t As Single, y As Single, dydt As Single t = ti y = yi h = dt Do If t + dt > tf Then h = tf - t End If dydt = dy(t, y, m, cd) y = y + dydt * h t = t + h If t >= tf Then Exit Do Loop Euler = y End Function Function dy(t, v, m, cd) Const g As Single = 9.81 dy = g - (cd / m) * v End Function Visual Basic Code for Euler Method

17 Se-Woong Chung, Chungbuk National University 17  M16 탄두의 무게 ? 4g ( 동전 10 원 )  초속 700m/s 로 발사  공기마찰로 지상 1km 도달 ( 무마찰 24km)  자유낙하 100m 이후 공기저항으로 45 m/s 의 종단속도 (terminal velocity) 도달  박찬호 선수의 최고구속 ? 45m/s (162 km/hr)  결국, 하늘로 쏜 총알에 맞으면 박찬호 선수가 4g 짜리 쇠구슬을 던져서 맞는 정도의 충격 하늘로 쏜 총알에 맞으면 충격은 ?

18 Se-Woong Chung, Chungbuk National University 18 1.2 Conservation Laws and Engineering Change = increase – decrease If change = 0, then it is called steady-state condition Flow in = Flow out Flow out of pipe 4 ?

19 Se-Woong Chung, Chungbuk National University 19 l Conservation of - Energy (Thermodynamics): Temperature - Mass: Mass Transport and WQM - Momentum: Hydrodynamics and Hydraulics Fate of Chemical = f (Reaction, Transport) Mass Balances dM/dt = Inputs - Outputs± Reactions Applications of Conservation Laws

20 Se-Woong Chung, Chungbuk National University 20 Completely Mixed Flow : Mass Conservation Continuity Mass Balance Loading(W) Reactions(kCV), Settling(v s AC) Outflow(Q out, C out )Inflow (Q in, C in ) Rate (dM/dt) V, C

21 Se-Woong Chung, Chungbuk National University 21 CHAPTER 2. Programming and Software CHAPTER 2

22 Se-Woong Chung, Chungbuk National University 22 2.1 Packages and Programming Packages : Excel, Excel-VBA, MATLAB, MATLAB M-files Programming : Fortran, Visual Basic, C 2.2 Structured Programming ( 구조화된 프로그래밍 ) easy to understand, test, debugging, and update 3 fundamental control structures Sequence ( 순차적 실행 ) Selection ( 선택적 실행 ) Repetition ( 반복적 실행 ) Flowchart or pseudocode is used

23 Se-Woong Chung, Chungbuk National University 23 Symbols used in flowcharts

24 Se-Woong Chung, Chungbuk National University 24 Logical Representation  Sequence structure  the computer code is to be implemented one instruction at a time  Step-by-step

25 Se-Woong Chung, Chungbuk National University 25  Selection  based on logical conditions  IF/THEN ( 단일대안 )  IF/THEN/ELSE ( 이중대안 )  IF/THEN/ELSEIF ( 복합대안 )  CASE Structure Logical Representation

26 Se-Woong Chung, Chungbuk National University 26 예제 p.34

27 Se-Woong Chung, Chungbuk National University 27  Repetition  Implement instructions repeatedly  DOEXIT or break loop  Pretest  Posttest  Midtest  Logical Loop Logical Representation

28 Se-Woong Chung, Chungbuk National University 28  DOFOR or count-controlled structure Logical Representation

29 Se-Woong Chung, Chungbuk National University 29 Ex. 2.1 Algorithm for Roots of Quadratic Problem Algorithm 1. Prompts the user for the coefficients, a, b, and c 2. Implements the quadratic formula, guarding against all eventualities (for example, avoiding division by zero and allowing for complex roots) 3. Displays the solution, that is, the values for x 4. Allows the user the option to return to step 1 and repeat the process

30 Se-Woong Chung, Chungbuk National University 30 Pseudocode 1. No consideration on abnormal parameters DO INPUT a, b, c r1 = (-b + SQRT(b 2 -4ac)) / (2a) r2 = (-b - SQRT(b 2 -4ac)) / (2a) DISPLAY r1, r2 DISPLAY ‘Try again? Answer yes or no’ INPUT response IF response = ‘no’ EXIT ENDDO

31 Se-Woong Chung, Chungbuk National University 31 Pseudocode 2. With consideration on abnormal parameters DO INPUT a, b, c r1 = 0: r2 = 0: i1 = 0 : i2 = 0 IF a = 0 THEN IF b  0 THEN r1 = -c/b ELSE DISPLAY “Trivial Solution” ENDIF ELSE discr = b 2 -4*a*c IF discr  0 THEN r1 = (-b + SQRT(discr)) / (2*a) r2 = (-b - SQRT(discr)) / (2*a) ELSE r1 = -b/(2*a) r2 = r1 i1 = SQRT(Abs(discr))/(2*a) i2 = -i1 ENDIF DISPLAY r1, r2, i1, i2 DISPLAY ‘Try again? Answer yes or no’ INPUT response IF response = ‘no’ EXIT ENDDO

32 Se-Woong Chung, Chungbuk National University 32 Modular Programming  Computer programs can be divided into small subprograms, or modules  Easy to program and debug  Procedure  Function : Return a single result  Subroutine : May return several results  Library

33 Se-Woong Chung, Chungbuk National University 33 Modular Programming for Falling parachutist Problem Function g = 9.8 INPUT cd, m INPUT ti, vi, tf, dt t = ti v = vi h = dt DO IF t+dt > tf THEN h = tf – t ENDIF dvdt = g – (cd/m) * v v = v + dvdt * h t = t + h IF t  tf EXIT ENDDO DISPLAY v Function dv/dt = g – (c / m) v v(t i+1 ) = v(t i ) + [g –(c/m) v(t i )] (t i+1 – t i )

34 Se-Woong Chung, Chungbuk National University 34 Excel-VBA Programming Option Explicit Function Euler(dt, ti, tf, yi, m, cd) Dim h As Single, t As Single, y As Single, dydt As Single t = ti y = yi h = dt DO If t + dt > tf Then h = tf - t End If dydt = dy(t, y, m, cd) y = y + dydt * h t = t + h If t >= tf Then Exit Do LOOP Euler = y End Function

35 Se-Woong Chung, Chungbuk National University 35 Function dy(t, v, m, cd) Const g As Single = 9.8 dy = g - (cd / m) * v End Function EXCEL-VBA 실습 MATLAB FORTRAN90, C++

36 Se-Woong Chung, Chungbuk National University 36 Function Euler(dt, ti, tf, yi, m, cd) REAL dt, ti, tf, yi, m, cd t = ti y = yi h = dt Do If (t + dt > tf) Then h = tf - t End If dydt = dy(t, y, m, cd) y = y + dydt * h t = t + h IF (t.GE. Tf) Exit END DO Euler = y End Function FORTRAN Programming

37 Se-Woong Chung, Chungbuk National University 37 Fig 2.8

38 Se-Woong Chung, Chungbuk National University 38 Fig 2.9

39 Se-Woong Chung, Chungbuk National University 39 CHAPTER 3 Approximation and Round-Off Errors

40 Se-Woong Chung, Chungbuk National University 40  수치해석과 오차 Although the numerical technique yield estimates that are close to the exact analytical solution, there is a discrepancy, or error, because the numerical method involve an approximation.  오차의 중요성 In professional practice, errors can be costly and sometimes catastrophic. If a structure of device fails, lives can be lost.  허용가능한 오차 ? The question is : How much error is present in our calculations and is it tolerable? Chapter Subject : Error

41 Se-Woong Chung, Chungbuk National University 41 3.1 Significant Figures Whenever we employ a number in a computation, we must have assurance that it can be used with confidence Significant figures is the number of figures that can be used with confidence It is conventional to set the estimated digit at one- half of the smallest scale division on the measurement device. Speedometer (3 figures): 48.5 km/r Odometer (7 figures): 87,324.45km Speedometer 49 km/hr 48.8 or 48.9 km/hr Odometer < 87,324.5km Number of significant figures = the number of certain digits + one estimated digit

42 Se-Woong Chung, Chungbuk National University 42 3.1 Significant Figures  The concept of significant figures has two important meanings for numerical methods ( 수치해석에서 유효숫자의 중요성 ) Numerical methods yields approximate results. Thus we need criteria (significant figures) to specify how confident we are in our approximate result. ( 즉, 수치해 근사값이 몇 자리 유효숫자까지 정확한가 ?) Computers retain only a finite number of significant figures for specific numbers such as  (3.14159..), e, and sqrt(7). The omission of the remaining significant figures is called round-off-error. ( 유효숫자의 생략 => 반올림 오차 발생 )

43 Se-Woong Chung, Chungbuk National University 43 3.2 Accuracy & Precision accuracy ( 정확도 ) how closely a computed or measured value agrees with the true value precision( 정밀도 ) how closely individual computed or measured values agree with each other The errors can be characterized with regard to their accuracy and precision.

44 Se-Woong Chung, Chungbuk National University 44 Inaccuracy (= bias) systematic deviation from the truth Imprecision (= uncertainty) the magnitude of the scatter from each other Error = Inaccuracy + Imprecision

45 Se-Woong Chung, Chungbuk National University 45 3.3 Error Definitions  Truncation errors ( 절단오차 ) result when approximations are used to represent exact mathematical procedures.  Round-off errors( 반올림 오차 ) result when numbers having limited significant figures are used to represent exact numbers.  True value = approximation + error (E t )  참오차 E t = true value - approximation

46 Se-Woong Chung, Chungbuk National University 46  The relative error ( 참백분율 상대오차 )  Percent relative error for iterative method ( 근사백분율 상대오차 ) Given tolerance n = number of significant figures 3.3 Error Definitions

47 Se-Woong Chung, Chungbuk National University 47 CHAPTER 4 Truncation Errors and the Talyor Series

48 Se-Woong Chung, Chungbuk National University 48 Truncation Errors and Taylor Series  Truncation errors  result from using an approximation in place of an exact mathematical procedure.  Example : Finite Divided Difference for ODE

49 Se-Woong Chung, Chungbuk National University 49  If the function f 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  The Taylor Series (p. 68 보충설명 4.1 참조 ) Where the remainder t = dummy variable( 모조변수 )  Taylor series provides a means to predict a function value at one point in terms of the function value and its derivatives at another point

50 Se-Woong Chung, Chungbuk National University 50  Numerical Approximation of Taylor Series First-order approximation: Linear line Second-order approximation: Curvature

51 Se-Woong Chung, Chungbuk National University 51  Taylor series approximation of a polynomial Predict the function’s value at x = 1 예제 4.1

52 Se-Woong Chung, Chungbuk National University 52  The remainder for the Taylor Series Expansion The magnitude of truncation error is function of h n+1 (Taylor 급수를 이용한 유한차분화 과정의 절단오차 크기 )

53 Se-Woong Chung, Chungbuk National University 53  Graphical depiction of a zero-order Taylor series and remainder

54 Se-Woong Chung, Chungbuk National University 54  Numerical Differentiation first-order forward difference first-order backward difference (1) (2)

55 Se-Woong Chung, Chungbuk National University 55 first-order centered difference (1) – (2) second-order centered difference (1) + (2)  Numerical Differentiation

56 Se-Woong Chung, Chungbuk National University 56 예제 4.3

57 Se-Woong Chung, Chungbuk National University 57  Homework #1 Chapter 1 : 1.12, 1.13 Chapter 4 : 4.4 모든 실습 결과물은 USB 메모리에 저장할 것. 실습시간과 학기말에 노트 검사와 함께 채점 예정.


Download ppt "Se-Woong Chung, Chungbuk National University 1 환경수치해석 Numerical Method for Environmental Engineers Se-Woong Chung Department of Environmental Engineering."

Similar presentations


Ads by Google