Sie sind auf Seite 1von 30

MEEN 221 Numerical Methods

1
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 2
MEEN 221 Numerical Methods
2
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Programming and Software
Chapter 2
Objective is how to use the computer as a tool
to obtain numerical solutions to a given
engineering model. There are two ways in
using computers:
Use available software
Or, write computer programs to extend the
capabilities of available software, such as Excel
and Matlab.
Engineers should not be tool limited, it is
important that they should be able to do both!
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 the
computer to perform a certain task.
To be able to perform engineering-oriented numerical
calculations, you should be familiar with the following
programming topics:
Simple information representation (constants, variables, and type
declaration)
Advanced information representation (data structure, arrays, and
records)
Mathematical formulas (assignment, priority rules, and intrinsic
functions)
Input/Output
Logical representation (sequence, selection, and repetition)
Modular programming (functions and subroutines)
We will focus the last two topics, assuming that you have
some prior exposure to programming.
MEEN 221 Numerical Methods
4
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Structured Programming
Structured programming is 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 be
composed of using the three fundamental structures:
Sequence, selection, and repetition

MEEN 221 Numerical Methods
5
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.1

MEEN 221 Numerical Methods
6
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Sequence. Computer
code must be
implemented one
instruction at a time,
unless you instruct
otherwise. The
structure can be
expressed as a
flowchart or
pseudocode.

Fig.2.2
MEEN 221 Numerical Methods
7
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Selection. Splits
the programs flow
into branches
based on outcome
of a logical
condition.




Fig. 2.3
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
MEEN 221 Numerical Methods
9
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.5
MEEN 221 Numerical Methods
10
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Figure 2.6
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 into
subprograms, or modules, that can be developed and
tested separately.
Modules should be as independent and self contained
as possible.
Advantages to modular design are:
It is easier to understand the underlying logic of
smaller modules
They are easier to debug and test
Facilitate program maintenance and modification
Allow you to maintain your own library of
modules for later use




MEEN 221 Numerical Methods
12
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.


Fig. 2.7
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 perform
calculations on rows and columns of data.
When any value on the sheet is changed, entire calculation is
updated, 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 to
implement numerical calculations.
It has several visualization tools, such as graphs and three
dimensional plots.
MEEN 221 Numerical Methods
14
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Fig. 2.8

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 Numerical Methods
16
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.


Fig. 2.9
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
18
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MEEN 221 Numerical Methods
19
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Homework #1
MEEN 221 Numerical Methods
20
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
20
MEEN 221 Numerical Methods
21
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
21
MEEN 221 Numerical Methods
22
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
22
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
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
(
+ A = + A
(

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 ( )
80
v t t v t v t t
(
+ A = + A
(

Problem 2.24
MEEN 221 Numerical Methods
25
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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
27
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MEEN 221 Numerical Methods
28
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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
30
Copyright 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
t v
0 -20.000
1 -7.690
2 3.081
3 12.506
4 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
>>

Das könnte Ihnen auch gefallen