Download presentation

Presentation is loading. Please wait.

1
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software

2
Last Time Mathematical Model Physical Problem Mathematical Model DataTheory Numeric or Graphic Results Implementation

3
Last Time 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 Forcing Functions Parameters

4
Mathematical Model Fundamental Laws Conservation of Mass Conservation of Momentum Conservation of Energy

5
Mathematical Model Change = Increase - Decrease Change 0 : Transient Computation Change = 0 : Steady State Computation Expressed in terms of

6
Analytic vs Numerical Solution t (s)v (m/s) 0.00 219.6 432 639.85 844.82 1047.97 1249.96

7
Software Packages Users StandardPower Limited to standard software capabilities Write your own macros and/or software

8
Objectives Computer Implementation of Numerical Methods Introduce Algorithms Discuss Flowcharts Discuss Pseudocodes Programming Tools and Styles

9
Computer Implementation Algorithm Flowchart Pseudocode Computer Program

10
Algorithms & Flowcharts Algorithm The step by step procedure that describes the implementation of a solution strategy. Flowchart The visual representation of an algorithm.

11
Flowchart Symbols Used in Flowcharts

12
Pseudocode and Computer Code Computer Code Set of Instructions in a computer language that direct the computer to perform a certain task. Pseudocode Set of code-like instructions that express the flowchart in a narrative form

13
VISUAL C++

14
FORTRAN

15
Visual Basic

16
MathCAD

17
Building Software… Instructions in TEXT form

18
Building Software… Compiled Form….

19
Building Software… Compiled Form….

20
Building Software… Linked Form…..exe

21
Programming Topics Simple Information Specification –Constants, variables, type declarations Advanced Information Representation –Arrays, data structures, records Mathematical Formulas –Operators, priority rules, intrinsic functions Input/Output Logical Representation –Sequence, selection and repetition Modular Programming –Functions and Subroutines

22
Programming Topics Simple Information Specification –Constants, variables, type declarations Advanced Information Representation –Arrays, data structures, records Mathematical Formulas –Operators, priority rules, intrinsic functions Input/Output Logical Representation –Sequence, selection and repetition Modular Programming –Functions and Subroutines

23
Simple Information Specifications Constants: Value does not change e.g. acceleration of gravity g_SI=9.81 e.g. pi=3.141592654

24
Simple Information Specifications Variables: Value depends on the problem –User Input Assign descriptive names, e.g. mass instead of m

25
Simple Information Specifications Type Declaration real mass8 decimal accuracy int istepinteger double g_SI16 decimal accuracy BOOL trivialTRUE/FALSE e.t.c.

26
Programming Topics Simple Information Specification –Constants, variables, type declarations Advanced Information Representation –Arrays, data structures, records Mathematical Formulas –Operators, priority rules, intrinsic functions Input/Output Logical Representation –Sequence, selection and repetition Modular Programming –Functions and Subroutines

27
Advanced Information Representation Arrays –N-dimensional matrices of same data type real v(10)velocity at 10 time steps int cell(100,100)100x100 rectangular matrix e.t.c.

28
Advanced Information Representation Structures and Records –Collection of data types struct STUDENT { charName real GPA int Age BOOLInState }

29
Programming Topics Simple Information Specification –Constants, variables, type declarations Advanced Information Representation –Arrays, data structures, records Mathematical Formulas –Operators, priority rules, intrinsic functions Input/Output Logical Representation –Sequence, selection and repetition Modular Programming –Functions and Subroutines

30
Mathematical Formulas Operators, priority rules, intrinsic functions

31
Programming Topics Simple Information Specification –Constants, variables, type declarations Advanced Information Representation –Arrays, data structures, records Mathematical Formulas –Operators, priority rules, intrinsic functions Input/Output Logical Representation –Sequence, selection and repetition Modular Programming –Functions and Subroutines

32
Logical Representation Sequence Computer code is to be implemented one instruction at a time Analytic Solution Enter g,m,c Enter time t Evaluate v Print t,v

33
Logical Representation Selection Computer code flow is split into branches based on a logical decision. Enter g,m,c Check if m=0 Print Error Message OK to continue

34
Logical Representation Repetition Implement instructions repeatedly

35
Programming Topics Simple Information Specification –Constants, variables, type declarations Advanced Information Representation –Arrays, data structures, records Mathematical Formulas –Operators, priority rules, intrinsic functions Input/Output Logical Representation –Sequence, selection and repetition Modular Programming –Functions and Subroutines

36
Modular Programming Module is a self contained and independent code segment Modules are designed to perform a specific, well designed task Functions return a single result Subroutines return several results

37
Example Consider Quadratic Equation With closed form solution

38
Example If a,b,c are given Compute x 1 and x 2 What Do I Need?

39
Example Ask user to input a,b,c Check if a=0 –Linear equation, this solution does not apply Check if a=0 and b=0 –Trivial Solution Check if b 2 -4ac=0 –Double Real Root

40
Example Check if b 2 -4ac>0 –Two Real Roots Check if b 2 -4ac<0 –Imaginary Roots

41
Example START a=0 Loop Input a, b, c Print Solution 1 FALSE 2 TRUE Solve Again TRUE END FALSE

42
Example 1 d Complex Roots d<0d>0 d=0

43
Example 2 b=0 Trivial Solution TRUEFALSE

44
DO INPUT a, b, c d = b**2 – 4*a*c IF a = 0 THEN IF b=0 THEN TRIVIAL SOLUTION ELSE x1 = -c/b ENDIF ELSE IF d<0 THEN COMPLEX ROOTS ELSE IF d = 0 THEN x1=x2=-b/2a ELSE x1 = (-b+SQRT(d))/(2*a) x2 = (-b-SQRT(d))/(2*a) ENDIF PRINT Continue? INPUT Control IF ( CONTROL == FALSE ) EXIT ENDDO PSEUDOCODE START a=0 Loop Input a, b, c Print Solution 1 FALSE 2 TRUE Solve Again TRUE END FALSE

45
Additional Homework Problem 2.8 Do not write a program. Draw the flowchart and pseudocode

Similar presentations

© 2019 SlidePlayer.com Inc.

All rights reserved.

To make this website work, we log user data and share it with processors. To use this website, you must agree to our Privacy Policy, including cookie policy.

Ads by Google