View
229
Download
1
Tags:
Embed Size (px)
Citation preview
ECIV 301
Programming & Graphics
Numerical Methods for Engineers
Lecture 4
Programming and Software
EXCEL and MathCAD
Last Time Software Packages
Users
Standard Power
Limited to standard software capabilities
Write your own macros and/or software
Last TimeAlgorithms & Flowcharts
AlgorithmThe step by step procedure that describes the implementation of a solution strategy.
Flowchart
The visual representation of an algorithm.
Last Time Pseudocode and Computer Code
Computer CodeSet of Instructions in a computer language that direct the computer to perform a certain task.
PseudocodeSet of code-like instructions that express the flowchart in a narrative form
Last TimeProgramming 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
Last Time Logical Representation
• SequenceComputer code is to be implemented one instruction at a time
tm
c
ec
gmv 1Analytic Solution
Enter g,m,c
Enter time t
Evaluate v
Print t,v
Last TimeLogical Representation
• Selection
Computer code flow is split into branches based on a logical decision.
Enter g,m,c
Check if m=0
Print Error MessageOK to continue
Last TimeModular 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
• 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 b2-4ac=0 – Double Real Root
a
acbbx
2
42
Analytic vs Numerical SolutionUse Finite Difference to Approximate Derivative
vi
ti ti+1
vi+1
True Slope
Approximate Slope
ii
ii
tt
tvtv
dt
dv
1
1
Analytic vs Numerical Solution
iiiii tttvm
cgtvtv
11
Numerical Solution
SlopeNew Value
Old Value Step Size
Euler Method
Analytic vs Numerical SolutionAlgorithm
1. Input a sequence of time nodesi.e. Start Time, End Time, Time
Step2. Input model parameters
i.e. m, c
4. Input initial velocityi.e. v(t=0)
3. Input forcing functioni.e. g
Algorithm
5. Check if m=0avoid division by 0
iiiii tttvm
cgtvtv
11
6. For each time node evaluate
7. Other secondary checks…
Project # 1 – DUE 9/12/03
This is a group project. You form your own teams. Each team should consist of UP TO THREE students.
Consider the parachutist problem. Write an Excel Spreadsheet solution using Visual Basic macros to calculate terminal velocities numerically for each of the following cases:• Mass in the range of 0-100 Kg with step 10• For each mass vary the drag coefficient c in the range 0
to 20 with step 2• Plot the terminal velocity as a function of drag coefficient
for each mass