chapter 2 slide
TRANSCRIPT
-
7/30/2019 Chapter 2 Slide
1/30
MEEN 221 Numerical Methods
1
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 2
-
7/30/2019 Chapter 2 Slide
2/30
MEEN 221 Numerical Methods
2
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Programming and SoftwareChapter 2
Objective is how to use the computer as a toolto obtain numerical solutions to a givenengineering model. There are two ways in
using computers:Use available software
Or, write computer programs to extend thecapabilities of available software, such as Excel
and Matlab.
Engineers should not be tool limited, it isimportant that they should be able to do both!
-
7/30/2019 Chapter 2 Slide
3/30
MEEN 221 Numerical Methods
3
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Computer programs are set of instructions that direct thecomputer to perform a certain task.
To be able to perform engineering-oriented numericalcalculations, you should be familiar with the followingprogramming topics:
Simple information representation (constants, variables, and typedeclaration)
Advanced information representation (data structure, arrays, andrecords)
Mathematical formulas (assignment, priority rules, and intrinsicfunctions)
Input/Output
Logical representation (sequence, selection, and repetition)
Modular programming (functions and subroutines)
We will focus the last two topics, assuming that you havesome prior exposure to programming.
-
7/30/2019 Chapter 2 Slide
4/30
MEEN 221 Numerical Methods
4
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Structured Programming
Structured programmingis a set of rules that
prescribe god style habits for programmer.
An organized, well structured code
Easily sharable
Easy to debug and test
Requires shorter time to develop, test, and update
The key idea is that any numerical algorithm can becomposed of using the three fundamental structures:
Sequence, selection, and repetition
-
7/30/2019 Chapter 2 Slide
5/30
MEEN 221 Numerical Methods
5
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.1
-
7/30/2019 Chapter 2 Slide
6/30
MEEN 221 Numerical Methods
6
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Sequence. Computer
code must be
implemented oneinstruction at a time,
unless you instruct
otherwise. The
structure can beexpressed as a
flowchart or
pseudocode.
Fig.2.2
-
7/30/2019 Chapter 2 Slide
7/30
MEEN 221 Numerical Methods
7
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Selection. Splitsthe programs flowinto branches
based on outcomeof a logicalcondition.
Fig. 2.3
-
7/30/2019 Chapter 2 Slide
8/30
MEEN 221 Numerical Methods
8
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Repetition. A means to implement instructions repeatedly.
Fig. 2.4
-
7/30/2019 Chapter 2 Slide
9/30
MEEN 221 Numerical Methods
9
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.5
-
7/30/2019 Chapter 2 Slide
10/30
MEEN 221 Numerical Methods
10
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Figure 2.6
MEEN 221 N i l M th d
-
7/30/2019 Chapter 2 Slide
11/30
MEEN 221 Numerical Methods
11
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Modular Programming
The computer programs can be divided intosubprograms, or modules, that can be developed andtested separately.
Modules should be as independent and self containedas possible.
Advantages to modular design are:
It is easier to understand the underlying logic of
smaller modulesThey are easier to debug and test
Facilitate program maintenance and modification
Allow you to maintain your own library ofmodules for later use
MEEN 221 N i l M th d
-
7/30/2019 Chapter 2 Slide
12/30
MEEN 221 Numerical Methods
12
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.7
MEEN 221 N i l M th d
-
7/30/2019 Chapter 2 Slide
13/30
MEEN 221 Numerical Methods
13
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
EXCEL
Is a spreadsheet that allow the user to enter and performcalculations on rows and columns of data.
When any value on the sheet is changed, entire calculation isupdated, therefore, spreadsheets are ideal for what if? sorts
of analysis. Excel has some built in numerical capabilities including
equation solving, curve fitting and optimization.
It also includes VBA as a macro language that can be used toimplement numerical calculations.
It has several visualization tools, such as graphs and threedimensional plots.
MEEN 221 N i l M th d
-
7/30/2019 Chapter 2 Slide
14/30
MEEN 221 Numerical Methods
14
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.8
MEEN 221 N i l M th d
-
7/30/2019 Chapter 2 Slide
15/30
MEEN 221 Numerical Methods
15
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB
Is a flagship software which was originally
developed as a matrix laboratory. A variety of
numerical functions, symbolic computations,
and visualization tools have been added to the
matrix manipulations.
MATLAB is closely related to programming.
MEEN 221 N i l M th d
-
7/30/2019 Chapter 2 Slide
16/30
MEEN 221 Numerical Methods
16
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.9
MEEN 221 N i l M th d
-
7/30/2019 Chapter 2 Slide
17/30
MEEN 221 Numerical Methods
17
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Other Languages and Libraries
Fortran 90 (IMSL)
C++
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
18/30
MEEN 221 Numerical Methods
18
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
19/30
MEEN 221 Numerical Methods
19
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Homework #1
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
20/30
MEEN 221 Numerical Methods
20
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
20
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
21/30
MEEN 221 Numerical Methods
21
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
21
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
22/30
MEEN 221 Numerical Methods
22
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
22
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
23/30
MEEN 221 Numerical Methods
23
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Problem 2.24
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
24/30
MEEN 221 Numerical Methods
24
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
50( ) ( ) 9.8 ( )
80
v t t v t v t t
Before the chute opens (t < 10). Eulers method can be
implemented as
After the chute opens (t 10). The drag coefficient is changed and
the implementation becomes
10( ) ( ) 9.8 ( )
80v t t v t v t t
Problem 2.24
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
25/30
MEEN 221 Numerical Methods
25
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
26/30
MEEN 221 Numerical Methods
26
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Problem 2.24
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
27/30
MEEN 221 Numerical Methods
27
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
28/30
MEEN 221 Numerical Methods
28
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
29/30
MEEN 221 Numerical Methods
29
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
z =
Columns 1 through 15
0 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000 7.0000 8.0000 9.0000
10.0000 11.0000 12.0000 13.0000 14.0000
-20.0000 -7.6900 3.0813 12.5061 20.7528 27.9687 34.2826 39.8073 44.6414
48.8712 52.5723 29.5246 20.8817 17.6406 16.4252
Columns 16 through 21
15.0000 16.0000 17.0000 18.0000 19.0000 20.0000
15.9695 15.7985 15.7345 15.7104 15.7014 15.6980
MEEN 221 Numerical Methods
-
7/30/2019 Chapter 2 Slide
30/30
MEEN 221 Numerical Methods
30
t v
0 -20.000
1 -7.690
2 3.081
3 12.5064 20.753
5 27.969
6 34.283
7 39.807
8 44.641
9 48.871
10 52.572
11 29.525
12 20.882
13 17.641
14 16.425
15 15.969
16 15.799
17 15.734
18 15.710
19 15.701
20 15 698>>