ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software.
Published byModified over 4 years ago
Presentation on theme: "ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software."— Presentation transcript:
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software
Last Time Mathematical Model Physical Problem Mathematical Model DataTheory Numeric or Graphic Results Implementation
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
Mathematical Model Fundamental Laws Conservation of Mass Conservation of Momentum Conservation of Energy
Mathematical Model Change = Increase - Decrease Change 0 : Transient Computation Change = 0 : Steady State Computation Expressed in terms of
Analytic vs Numerical Solution t (s)v (m/s) 0.00 219.6 432 639.85 844.82 1047.97 1249.96
Software Packages Users StandardPower Limited to standard software capabilities Write your own macros and/or software
Objectives Computer Implementation of Numerical Methods Introduce Algorithms Discuss Flowcharts Discuss Pseudocodes Programming Tools and Styles
Computer Implementation Algorithm Flowchart Pseudocode Computer Program
Algorithms & Flowcharts Algorithm The step by step procedure that describes the implementation of a solution strategy. Flowchart The visual representation of an algorithm.
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
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
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
Example Consider Quadratic Equation With closed form solution
Example If a,b,c are given Compute x 1 and x 2 What Do I Need?
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
Example Check if b 2 -4ac>0 –Two Real Roots Check if b 2 -4ac<0 –Imaginary Roots
Example START a=0 Loop Input a, b, c Print Solution 1 FALSE 2 TRUE Solve Again TRUE END FALSE
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
Additional Homework Problem 2.8 Do not write a program. Draw the flowchart and pseudocode