Download as pdf or txt
Download as pdf or txt
You are on page 1of 56

Draft

DRAFT

Lecture Notes in:

COMPUTING LITERACY
For Undergraduate Engineering Students

       
   
            
1
F1 ! " #
1 ! r_, " _# :$ r% &
1
F2 ! " #
2 ! r_, " _# :$ r% &
    ' (')  (* + ,-  /.0 *    1  2   3 4
g1 ! r_, " _# :$ D ! 1 ! r, " # , r, r# 5 D ! 1 ! r, " # , r# 6 r 5 D ! 1 ! r, " # , " , " # 6 r2
g2 ! r_, " _# :$ D ! g1 ! r, " # , r, r# 5 D ! g1 ! r, " # , r# 6 r 5 D ! g1 ! r, " # , " , " # 6 r2
    ' ('     
F1 ! " _# $ Exp ! m ! 7 # " #
8 9 m: ; <
 =  > ? ' (A@     +    * > 0 *    
eqdiff $ Simplify B Factor ! g2 ! r, " # # r3C % D
8 9 m : ; < E E F 1 GH I 2 G m J H K 2 I E E 1 G H I 2 G m J H K 2I
Solve ! eqdiff Exp ! L m ! 7 # " # M 0, m ! 7 # #
N N m J H K O F P E F 1 G H I Q , N m J H K O P E F 1 G H I Q , N m J H K O FP E 1 G H I Q , N m J H K O P E 1 G H I Q Q
    ' ('R   + * >2  >     

% Dimension of elements
A=[ft,Sigma2,(fc-Sigma2)];
if (sigma(1)<=ft && sigma(1)>0)
w_nod=C1;
elseif (sigma(1)<=0 && sigma(1)>Sigma2)
for h=1:16
w_nod(h)=C1(h)+M1(h)*sigma(1);
end
elseif (sigma(1)<=Sigma2 && sigma(1)>=fc)
for h=1:16
w_nod(h)=C2(h)+M2(h)*(sigma(1)-Sigma2);
end
else
w_nod=zeros(1,14);
end

Victor E. Saouma
Dept. of Civil Environmental and Architectural Engineering
University of Colorado, Boulder, CO 80309-0428

Draft
Contents
1 MATLAB: Basic Introduction
1.1 Background . . . . . . . . . . . . . . . . . . .
1.1.1 What is MATLAB? . . . . . . . . . .
1.1.2 Availability . . . . . . . . . . . . . . .
1.1.3 Accessing MATLAB . . . . . . . . . .
1.1.4 Help . . . . . . . . . . . . . . . . . . .
1.1.5 Basic Features . . . . . . . . . . . . .
1.1.6 Simple Math . . . . . . . . . . . . . .
1.1.7 Common Mathematical Functions . .
1.1.8 Statements, Expressions and Variables
1.1.9 Display Formats . . . . . . . . . . . .
1.1.10 Printing Text and Matrices . . . . . .
1.1.11 Variables . . . . . . . . . . . . . . . .
1.1.12 MATLAB Workspace . . . . . . . . .
1.1.13 Saving and Retrieving Data . . . . . .
1.1.14 Arrays . . . . . . . . . . . . . . . . . .
1.1.15 Graphics . . . . . . . . . . . . . . . .
1.1.16 Graphics hardcopy . . . . . . . . . . .
1.2 Assignment . . . . . . . . . . . . . . . . . . .
1.2.1 Practice . . . . . . . . . . . . . . . . .
1.2.2 Work . . . . . . . . . . . . . . . . . .
1.2.3 Stresses . . . . . . . . . . . . . . . . .
1.2.4 Measurement Errors, [?] . . . . . . . .
1.2.5 Statistical Analysis; Part I . . . . . . .
1.2.5.1 Elements of Statistics . . . .
1.2.5.2 Assignment . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

17
17
17
17
17
19
19
19
22
22
24
25
26
26
27
27
30
32
32
32
33
33
34
34
34
38

2 MATLAB: Matrix Algebra


2.1 Syntax . . . . . . . . . . . . . . . .
2.1.1 Matrix Operations . . . . .
2.1.1.1 Matrix Definition
2.1.1.2 Matrix Operations
2.1.1.3 Matrix functions .
2.1.2 Graphics Revisited . . . . .
2.1.2.1 Polar Plots . . . .
2.1.2.2 3-D mesh plots. .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

39
39
39
39
41
42
43
43
44

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

Draft
CONTENTS

4.1.1.3
4.1.1.4
4.1.1.5
4.1.1.6

4.1.2

4.1.3

Front End and Kernel . . . . . . . . . . .


Accessing Mathematica . . . . . . . . . .
Help . . . . . . . . . . . . . . . . . . . . .
Notebook Front End . . . . . . . . . . . .
4.1.1.6.1 Pointers . . . . . . . . . . . . . .
4.1.1.6.2 Cell Brackets . . . . . . . . . . .
4.1.1.7 Brackets, Parentheses, and Braces . . . .
Examples . . . . . . . . . . . . . . . . . . . . . . .
4.1.2.1 Basic Arithmetic Operation . . . . . . . .
4.1.2.2 Approximate Numerical Values . . . . . .
4.1.2.3 Complex Numbers . . . . . . . . . . . . .
4.1.2.4 Derivatives . . . . . . . . . . . . . . . . .
4.1.2.5 Integration . . . . . . . . . . . . . . . . .
4.1.2.6 Algebraic Formulae . . . . . . . . . . . .
4.1.2.7 Solving equations . . . . . . . . . . . . .
4.1.2.8 Matrices . . . . . . . . . . . . . . . . . .
4.1.2.9 Graphics and Three-Dimensional Plots .
4.1.2.10 Interfacing with Mathematica . . . . . . .
4.1.2.10.1 Input . . . . . . . . . . . . . . .
4.1.2.10.2 Output . . . . . . . . . . . . . .
4.1.2.11 Packages . . . . . . . . . . . . . . . . . .
4.1.2.12 Graphics hardcopy . . . . . . . . . . . . .
4.1.2.13 Input file . . . . . . . . . . . . . . . . . .
Some Mathematica Commands . . . . . . . . . . .
4.1.3.1 Basic Operations . . . . . . . . . . . . . .
4.1.3.2 Mathematical Functions . . . . . . . . . .
4.1.3.3 Some Mathematica Constants . . . . . . .
4.1.3.4 Complex Numbers . . . . . . . . . . . . .
4.1.3.5 Recall of Previous Expressions . . . . . .
4.1.3.6 Assignment of Variables . . . . . . . . . .
4.1.3.7 Brackets . . . . . . . . . . . . . . . . . .
4.1.3.8 Help . . . . . . . . . . . . . . . . . . . . .
4.1.3.9 Interrupting Mathematica . . . . . . . . .
4.1.3.10 Transformation of Algebraic Expressions
4.1.3.11 Differentiation . . . . . . . . . . . . . . .
4.1.3.12 Integration . . . . . . . . . . . . . . . . .
4.1.3.13 Summation & Products . . . . . . . . . .
4.1.3.14 Equations . . . . . . . . . . . . . . . . . .
4.1.3.14.1 Preliminaries . . . . . . . . . . .
4.1.3.14.2 Solution . . . . . . . . . . . . . .
4.1.3.14.3 Differential Equations . . . . . .
4.1.3.14.4 Numerical Values . . . . . . . .
4.1.3.15 Functions . . . . . . . . . . . . . . . . . .
4.1.3.16 Vectors & Matrices . . . . . . . . . . . .
4.1.3.17 Graphics . . . . . . . . . . . . . . . . . .
4.1.3.17.1 Preliminaries . . . . . . . . . . .
4.1.3.17.2 Plot Options . . . . . . . . . . .
4.1.3.17.3 3 Dimensional Plots . . . . . . .

Victor E. Saouma

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

81
83
83
84
84
84
84
85
85
85
85
86
86
86
86
87
88
88
88
89
90
90
90
90
90
91
91
91
92
92
92
92
92
93
93
93
94
94
94
94
94
94
94
95
95
95
95
96

Computing Literacy for Undergraduate Engineering Students

Draft
CONTENTS
5.8.2

Listing . . . . . . . . . .
5.8.2.1 infiltration.m .
5.9 montecarlo . . . . . . . . . . .
5.9.1 Description . . . . . . .
5.9.2 Listing . . . . . . . . . .
5.9.2.1 montecarlo.m
5.10 3dplot . . . . . . . . . . . . . .
5.10.1 Description . . . . . . .
5.10.2 Listing . . . . . . . . . .
5.10.2.1 cont.m . . . .
5.10.2.2 pix.m . . . . .
5.10.2.3 smooth.m . . .
5.11 zec . . . . . . . . . . . . . . . .
5.11.1 Description . . . . . . .
5.11.2 Listing . . . . . . . . . .
5.11.2.1 linregress.m
5.11.2.2 zec.m . . . . .
5.12 Stress/Strain Programs . . . .
5.12.1 Description . . . . . . .
5.12.2 Sample Output: . . . .
5.12.2.1 Example 1: .
5.12.2.2 Example 2: .
5.12.2.3 Example 3: .

7
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

135
135
136
136
136
136
137
137
138
138
139
140
140
140
141
141
142
144
144
145
147
148
150

6 Fortran 90: INTRODUCTION


6.1 Introduction . . . . . . . . . . . . . . . . . . . .
6.1.1 Computer Architecture and Software . .
6.1.1.1 Computer Hardware . . . . . .
6.1.1.2 Computer Software . . . . . .
6.1.2 Fortran Past, Present, and Future . . .
6.2 From Source to Binary . . . . . . . . . . . . . .
6.3 Sample Example . . . . . . . . . . . . . . . . .
6.4 Fortran Compilers . . . . . . . . . . . . . . . .
6.4.1 Compilers . . . . . . . . . . . . . . . . .
6.4.2 File Extensions . . . . . . . . . . . . . .
6.4.3 Workstation Compilers . . . . . . . . . .
6.4.4 Compiling with Microsoft Power Station
6.5 Flow Charts, Macro-Code . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.

153
153
153
153
155
156
157
157
157
157
158
158
158
158

7 Fortran 90: Basic Operations


7.1 Background . . . . . . . . . . . .
7.1.1 Preliminaries . . . . . . .
7.1.1.1 Program Layout
7.1.1.2 Characters . . .
7.1.1.3 Variable Types .
7.1.1.4 Labels . . . . . .
7.1.2 Data Declaration . . . . .
7.1.3 Basic Operations . . . . .

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

161
161
161
161
161
161
162
162
163

Victor E. Saouma

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

Computing Literacy for Undergraduate Engineering Students

Draft
CONTENTS

9 Fortran 90; PROGRAM UNITS; POINTERS


9.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . .
9.1.1 Program Units . . . . . . . . . . . . . . . . . . . .
9.1.1.1 Main Program . . . . . . . . . . . . . . .
9.1.1.2 Functions . . . . . . . . . . . . . . . . . .
9.1.1.3 Recursive Subprograms . . . . . . . . . .
9.1.1.4 Subroutines . . . . . . . . . . . . . . . . .
9.1.1.5 Modules . . . . . . . . . . . . . . . . . .
9.1.1.6 Interface . . . . . . . . . . . . . . . . .
9.1.2 Derived Data Type . . . . . . . . . . . . . . . . . .
9.1.3 Pointers . . . . . . . . . . . . . . . . . . . . . . . .
9.1.3.1 Pointer Variable . . . . . . . . . . . . . .
9.1.3.2 Pointer Assignment . . . . . . . . . . . .
9.1.3.3 Dynamic Memory Allocation for Pointers
9.1.3.4 Pointers to Arrays . . . . . . . . . . . . .
9.1.3.5 Pointers as a Tool for Linked Lists . . . .
9.2 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . .
9.3 Mendeleev . . . . . . . . . . . . . . . . . . . . . . . . . . .
9.4 Linked List . . . . . . . . . . . . . . . . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

189
189
189
189
189
191
191
192
193
193
193
193
193
195
195
196
196
196
197

10 Fortran 90: MAKE, DEBUGGER


10.1 Debugging options . . . . . . . . .
10.2 FORTRAN Preprocessor . . . . . .
10.2.1 System Calls . . . . . . . .
10.3 Make . . . . . . . . . . . . . . . . .
10.4 Debugger . . . . . . . . . . . . . .
10.5 Introduction to Debugging . . . . .
10.5.1 The debugger . . . . . . . .
10.5.2 Running the debugger . . .
10.5.3 Debugger Commands . . .

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.

199
199
200
200
201
203
203
203
206
206

11 INTRODUCTION TO UNIX
11.1 logging In . . . . . . . . . . . . .
11.2 Changing Your Password . . . .
11.3 Logging Out . . . . . . . . . . . .
11.4 On-Line Help . . . . . . . . . . .
11.4.1 man . . . . . . . . . . . .
11.4.2 Apropos . . . . . . . . . .
11.5 UNIX File System . . . . . . . .
11.5.1 Directory Structure . . .
11.5.2 Your User Account . . . .
11.5.3 Absolute Pathnames . . .
11.5.4 Relative Pathnames . . .
11.6 Shell . . . . . . . . . . . . . . . .
11.7 File Management . . . . . . . . .
11.7.1 Changing Directories . . .
11.7.2 Changing File Protection
11.7.3 Copying Files . . . . . . .

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

209
209
209
209
210
210
210
210
210
211
211
211
211
211
211
211
213

Victor E. Saouma

.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

Computing Literacy for Undergraduate Engineering Students

Draft
CONTENTS

11.17.3 Basic Commands .


11.18Standard Unix Editors .
11.18.1 vi Editor . . . . .
11.18.2 Emacs . . . . . . .
11.19Other Editors . . . . . . .

Victor E. Saouma

11
.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

.
.
.
.
.

227
228
228
229
231

Computing Literacy for Undergraduate Engineering Students

Draft
List of Figures
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8

Matlabs Main Window . . . . . . . . . . . . . . . . . . . . . . . . . .


Set Path in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Selecting path Directory in Matlab . . . . . . . . . . . . . . . . . . . .
Directory Containing Source Code in Matlab . . . . . . . . . . . . . .
Matlabs Operating Environment . . . . . . . . . . . . . . . . . . . . .
Simple Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Multiple Plots in a Single Graph . . . . . . . . . . . . . . . . . . . . .
Normalized Gauss Distribution, and Cumulative Distribution Function

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

18
19
20
21
21
30
32
37

2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10

Polar Plot of a Cardioid . . . . . . . . . . . . . . . . . . . . .


Sample of Surface and Contour Plots . . . . . . . . . . . . . .
Picture Used for Animation . . . . . . . . . . . . . . . . . . .
Histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Regression Analysis . . . . . . . . . . . . . . . . . . . . . . .
Bonded Strain Gage . . . . . . . . . . . . . . . . . . . . . . .
Strain Rosette . . . . . . . . . . . . . . . . . . . . . . . . . . .
Steel Truss . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Single Degree of Freedom Oscillator . . . . . . . . . . . . . .
Simply Supported Beam Column; Differential Segment; Effect

. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
Force P

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

44
45
45
47
48
52
53
56
59
61

3.1
3.2
3.3
3.4
3.5
3.6
3.7

Newton-Cotes Numerical integration . . . . . . . . . . . . . . . . . . . .


Center of Gravity and Moments of Inertia of A Triangular Cross-Section
Runges Midpoint Method . . . . . . . . . . . . . . . . . . . . . . . . . .
Runges Trapezoid Method . . . . . . . . . . . . . . . . . . . . . . . . .
4th Order Runge-Kutta Method . . . . . . . . . . . . . . . . . . . . . .
Runge-Kutta Solution for the Mass-Spring-Damper System . . . . . . .
Equivalent and Exact Stress Distribution in Reinforced Concrete Beams

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

.
.
.
.
.
.
.

66
68
71
71
72
76
77

4.1
4.2
4.3
4.4

Notebook Front End for Mathematica . . . . . . . .


Notebook Front End Help for Mathematica . . . . .
Two-dimensional Plot generated from Mathematica .
Three-dimensional Plot generated from Mathematica

5.1
5.2
5.3
5.4

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
of Axial

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

82
83
88
89

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

104
104
106
108

Draft
List of Tables
1.1
1.2
1.3
1.4
1.5
1.6
1.7
1.8
1.9
1.10

Basic Commands . . . . . . . . . .
Special Characters . . . . . . . . .
Common Mathematical Functions
Display Options . . . . . . . . . . .
Text and String Operations . . . .
Special Variables . . . . . . . . . .
Disk Files Commands . . . . . . .
Array Operations . . . . . . . . . .
2D Graphics Commands . . . . . .
Printer Devices . . . . . . . . . . .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

20
22
23
24
26
26
27
29
31
32

2.1
2.2
2.3
2.4
2.5
2.6
2.7
2.8
2.9
2.10

Built In Matrix Definition Functions


Matrix Operations . . . . . . . . . .
Matrix Functions . . . . . . . . . . .
Statistical Analysis Functions . . . .
Signal Processing Functions . . . . .
Relations and Logical Operators . .
Relational and Logical Functions . .
Control Flow . . . . . . . . . . . . .
Strain Rosette Problems . . . . . . .
Result of Truss Design . . . . . . . .

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

.
.
.
.
.
.
.
.
.
.

39
41
42
46
49
49
50
51
55
58

3.1
3.2
3.3
3.4

Weights for Newton-Cotes Quadrature Formulas


Numerical Integration and Differentiation . . . .
Nonlinear Equations and Optimization . . . . . .
Differential Equations . . . . . . . . . . . . . . .

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

66
67
69
74

4.1

Mathematica Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

6.1
6.2
6.3

PC Vs Workstation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Fortran Compilers in the Bechtel Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Fortran Compiler Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159

7.1
7.2
7.3
7.4

Characters . . . . . . . . . . . . . . . . .
Basic Arithmetic Operations . . . . . .
Truth Table for Logical Operators . .
Common Arithmetic Intrinsic Functions

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

.
.
.
.

161
164
164
165

Draft
Chapter 1

MATLAB: Basic Introduction


1.1

Background

1.1.1

What is MATLAB?

1 MATLAB is an interactive, matrix-based system for scientific and engineering calculations. Contrarily
to programming languages, such as Fortran, C, or Basic you can solve complex numerical problems
without actually writing a program.

MATLAB is an abbreviation for MATrix LABoratory.

3 MATLAB is the most widely used software package for interactive numeric computation, graphics,
data analysis1 .

1.1.2
4

Availability

MATLAB is available in the CAD lab (PC/Windows version), as well as in the Bechtel Laboratory.

A relatively inexpensive Student Edition is available from Prentice Hall and can be purchased from
the Buffalo Chip.

1.1.3

Accessing MATLAB

Once you clicked on the MATLAB icon, the menu shown in Fig. 1.1 will be displayed which may be
accomplished through browsing, Fig. 1.1.3.

Fig. 1.1.3 illustrates the content of the default directory containing your source code.

Finally, Fig. ?? illustrates a typical working envirnoment, where a file has been selected for editing in
one window, and program is executed in the other. Note that upon completion of the program, you can
always querry values in the MATLAB main window.
8

1 Other

similar products include IDL, and MATHEMATICA for symbolic computations.

Draft
Chapter 2

MATLAB: Matrix Algebra


2.1

Syntax

2.1.1

Matrix Operations

2.1.1.1

Matrix Definition

Matrices can be entered in several different ways:


Entered by an explicit list of elements, or built from blocks. For example,
A=[1 4 6; 2 1 8; -2 7 -9];
B = [A, ones(3,2); zeros(2,3), eye(2)]}
will build a 5-by-5 matrix.
Generated by built-in statements and functions, Table 2.1. For example, ones(m,n) produces an
eye
zeros
ones
diag
triu
tril
rand
hilb
magic
toeplitz

identity matrix
matrix of zeros
matrix of ones
see below
upper triangular part of a matrix
lower triangular part of a matrix
randomly generated matrix
Hilbert matrix
magic square
see help toeplitz

Table 2.1: Built In Matrix Definition Functions


m-by-n matrix of ones; if A is a matrix, then ones(A) produces a matrix of ones of the same size
as A.
If x is a vector, diag(x) is the diagonal matrix with x down the diagonal; if A is a square matrix,
then diag(A) is a vector consisting of the diagonal of A.

Draft
2.1 Syntax
x(1,:)
ans =
3

-1

41

z=[y(1,:);y(3,:)]
z =
3
-1
5
5
-3
9
v=[0.2 1.4 2.6]
v =
0.2000
1.4000

2.6000

diag(v)
ans =
0.2000
0
0

0
0
2.6000

2.1.1.2
4

0
1.4000
0

Matrix Operations

Matrix operations are listed in Table 2.2.


+

b
0

\
/

addition
subtraction
multiplication
power
transpose
left division
right division

Table 2.2: Matrix Operations


The matrix division operations deserve special comment. If A is an invertible square matrix and b
is a compatible column, vector, then x = A\b is the solution of A x = b

>> A=[2 3;1 4];b=[8;9];AInv=inv(A);


>> x=AInv*b
x =
1
2
>> x=A\b
x =
1
2

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
2.1 Syntax
0.5000

43

-0.9167

-6.2917

EDU>> triu(lux)
ans =
4.0000
2.0000
0
6.0000
0
0

3.0000
11.5000
-6.2917

EDU>> tril(lux)
ans =
4.0000
0
-0.2500
6.0000
0.5000
-0.9167

0
0
-6.2917

EDU>> tril(lux,-1)
ans =
0
0
-0.2500
0
0.5000
-0.9167

0
0
0

EDU>> diag(lux)
ans =
4.0000
6.0000
-6.2917
EDU>> eig(x)
ans =
4.4123
12.9438
2.6440
EDU>> x=[0.5 0.25;0.25 0.5]
x =
0.5000
0.2500
0.2500
0.5000
EDU>> [V,D]=eig(x)
V =
0.7071
0.7071
-0.7071
0.7071
D =
0.2500
0
0
0.7500
EDU>> x*V-V*D
ans =
0
0
0
0

2.1.2

Graphics Revisited

2.1.2.1

Polar Plots

theta=0:pi/60:2*pi;r=2*(1-cos(theta));polar(theta,r);axis square
print -deps2 polar.eps
resulting in Fig 2.1

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
2.1 Syntax

45
1

0.1

0.8

0.6
0.4

0.8

0.4

0.6

0.2

0.4

0.2

0.2

0.9

0.8

0.7
0.6

0.4

0
1

0.3

0.5
0.5

0
0.5
1

0.5

0.8

0.5

0.6

0.2

1
1

0.8

0.6

0.4

0.2

0.2

0.4

0.6

0.8

Figure 2.2: Sample of Surface and Contour Plots


for fac=-5:1:5 % loop
k=k+1;
z=fac*N8;
surf(X,Y,z);
%axis off;
axis([-1 1 -1 1 -5 5]) % freeze the axis to user specified values
M(:,k)=getframe; % grab the frame into M
end
movie(M,10) % play back 10 times
will generate the animation of Fig. 2.3

5
1
1

0.5
0.5

0.5

0.5
1

Figure 2.3: Picture Used for Animation

Note that alternatively you may generate the image within a loop, and insert a pause after each one.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

2.2 Assignment

2.2.7

Nonlinear Equation

2.2.7.1

Theory

61

Considering a beam-column subjected to axial and shear forces as well as a moment, Fig. 2.10, taking
dv
the moment about i for the beam segment and assuming the angle dx
between the axis of the beam and
w(x)

dx

y,u

V+

V
x dx
P

v
x

dx

M+ M
x dx

i
j

dx

Figure 2.10: Simply Supported Beam Column; Differential Segment; Effect of Axial Force P
the horizontal axis is small, leads to




 
(dx)2
dV
dM
dv
dx + w
+ V +
dx P
dx = 0
M M+
dx
2
dx
dx

(2.25)

neglecting the terms in dx2 which are small, and then differentiating each term with respect to x, we
obtain
dV
d2 v
d2 M

P 2 =0
(2.26)
2
dx
dx
dx
However, considering equilibrium in the y direction gives
dV
= w
dx

(2.27)

From beam theory, neglecting axial and shear deformations, we have


M = EI

d2 v
dx2

(2.28)

Substituting Eq. 2.27 and 2.28 into 2.26, and assuming a beam of uniform cross section, we obtain
EI

Victor E. Saouma

d2 v
d4 v
P 2 =w
4
dx
dx

(2.29)

Computing Literacy for Undergraduate Engineering Students

Draft

2.2 Assignment

63

(e) Tolerance

2. Plot the equation for the specified range


3. Solve the equation within the specified tolerance
4. Display the root of the equation and the number of iterations.
Test your program by solving Eq. 2.33 and compare the number of flops (floating point operations) with
the preceding solution.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
Chapter 3

MATLAB: Advanced Topics


3.1
3.1.1

Background
Numerical Integration and Differentiation

Rb
The integration of a F (x)dx is essentially based on passing a polynomial P (x) through given values
Rb
of F (x) and then use a P (x)dx as an approximation.

F (x)dx

(3.1)

P (x)dx
a

2 Using P (x) = F (x) at n points, and recalling the properties of Lagrangian interpolation functions, we
obtain

P (x)

l1 (x)F (x1 ) + l2 (x)F (x2 ) + + ln (x)F (xn )


n
X
=
li (x)F (xi )

(3.2-a)
(3.2-b)

i=1

3.1.1.1

Newton-Cotes Method

In Newton-Cotes integration, it is assumed that the sampling points are equally spaced, Fig. 3.6, thus
we define
Z b
Z bX
n Z b
n
X
P (x)dx =
li (x)dxF (xi ) =
li (x)dxF (xi )
(3.3)

or

Approximation
Weights
(n)

Rb
a

P (x)dx
(n)
Wi

=
=

Pn
(n)
W F (xi )
R b i=1 i
(n)
l (x)dx = (b a)Ci
a i

(3.4)

where Ci are the weights of the Newton-Cotes quadrature for numerical integration with n equally
spaced sampling points.

Draft

3.1 Background
R1

67

P (x)dx

P (x) =
l1 (x) =

R1

l2 (x)

l3 (x)

(3)
W1
(3)
W2
(3)
W3

=
=
=

F (x)dx

which is Simpsons rule


3.1.1.2
8

P3

i=1 li (x)F (xi )


(xx2 )(xx3 )
1
(x1 x2 )(x1 x3 ) = 2 x(x 1)
(xx1 )(xx3 )
(x2 x1 )(x2 x3 ) = (1 + x)(x 1)
(xx1 )(xx2 )
= 1 x(1 + x)
R(x13 x1 )(x3 x2 ) 1 R 21
l1 (x)dx = 2 1 x(x 1)dx = 31
R1
R1
1
l2 (x)dx = 1 (1 + x)(x 1)dx = 43
1
R1
R1
l3 (x)dx = 12 1 x(1 + x)dx = 13
1
R1
P3
(3)
P (x)dx = i=1 Wi F (xi ) = 13 [F (1)
1

+ 4F (0) + F (1)]

MATLAB Examples

MATLABs functions for numerical (definite) integration and differentiation are shown in Table 3.2.

trapz
quad
quad8
diff

Numerical Integration
trapezoidal numerical integration
numerical function integration; Simpsons rule
Newton-Cotes 8 panel rule
approximate derivatives

Table 3.2: Numerical Integration and Differentiation


For example, let us recall the expression for the center of gravity
Z
ydA
y=
A
and moment of inertia
Z
Z
x2 dA
y 2 dA
Iyy =
Ixx =
9

cg
+ Ad2y
Ixx = Ixx

Iyy =

A
cg
+
Iyy

Ad2x

and moment of inertia for a given cross section


for a rectangular cross (width b, height h) section we would have
Z
ydA
y =
A
Z h
ydy
b
0
=
bh
h
=
2
Victor E. Saouma

(3.5)

(3.6-a)
(3.6-b)

(3.7-a)

(3.7-b)
(3.7-c)

Computing Literacy for Undergraduate Engineering Students

Draft
Chapter 4

MATHEMATICA
4.1

Background

4.1.1

Introduction

4.1.1.1

What is Mathematica ?

Mathematica is a program for symbolic mathematics.

With Mathematica, you can perform algebraic operations of various complexities. Hence, rather than
numerically solving an Engineering problem, you can solve it algebraically.

Because of its power, Mathematica will enable you to easily address problem of such complexities that
it would have been impractical to solve otherwise.

Finally, Mathematica has a very powerful set of graphics capabilities.

4.1.1.2
5

Availability

Mathematica is available in the Bechtel Laboratory.

A relatively inexpensive Student Edition can be purchased from the Buffalo Chip, and the University
used to have a site license for it.

4.1.1.3

Front End and Kernel

Mathematica consists of two parts: the Kernel which is the computation engine, and the Front End
which is the user interface. The Kernel is identical on all computers, however the Kernel may vary.
7

There are two Front Ends supported in the Bechtel Lab:

Command-Line Interface: where the current input line is displayed on the last line of the screen
(it can be edited by using the arrow, insert and delete keys). This Front End does not support
graphics, and is invoked by the math command. It is a convenient (and only available one) to use if
you connect to the server via a remote terminal which does not support graphics (such as a home

Draft

4.1 Background

83

In both cases Mathematica is used interactively

4.1.1.4

Accessing Mathematica

10 In the Bechtel Lab, Mathematica is accessible through by clicking the left mouse button and then
selecting Mathematica. Note that the program is licensed to run only on the server (bechtel).

If you want to run the program differently, you need to


xhost + on your console
rlogin bechtel To connect you to the server
setenv DISPLAY yourmachine:0.0 To have the graphics displayed on your workstation
Type math for the Command Line Front End. To exit you simply type Exit.
11

12

Alternatively, you may simply type mathematica for the Notebook Front End.

4.1.1.5

Help

13

For help, simply type ?. For a specific function, you can type ?Sqrt or ?P*.

14

Note that after each command, you should hit the following two keys simultaneously <Shift> <return>

15

The Notebook Front End also provides extensive help, Fig. 4.2.

Figure 4.2: Notebook Front End Help for Mathematica

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
4.3 References

101

(c) Label the x axis x, and the y axis y.

5. Plotsin( sin x + y) for 3 < x < 3 and 3 < y < 3 using 33 grid points, no display of the axes.
6. Generate a contour plot of the previous equation.
7. Write a function which takes a pair x, y and returns

4.3

x2 + y 2 .

References

1. Wolfram, S. Mathematica: A System for Doing Mathematics by Computer second edition, AddisonWesley, 1991.
2. Maeder, R., Programming in Mathematica, Addison Wesley, 1991
3. Blachman, N., Mathematica a Practical Approach, Prentice Hall, 1991.
4. Gray, T., and Glynn J., The Beginners Guide to Mathematica, Addison-Wesley, 1992.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
Chapter 5

SAMPLES of MATLAB
PROGRAMS
This chapter contains the description and listing of a number of simple (and not so simple) MATLAB
codes.
The source codes can be freely copied from
/pub/Structures/cven4837

5.1
5.1.1

arches
Description

SUBDIRECTORY: arches
SYNOPSIS: axial, shear, and normal force plots for an arch (Structures)
DESCRIPTION: arches.m plots the Bending Moment, Shear Force, and Axial Force for a three pin
semi circular arch under uniform load.
CONTENTS;
arches.m

main program

Written by: Brian Rose


Determine the reactions of the three-hinged arch shown in Fig. 5.1 Solution:
Four unknowns, three equations of equilibrium, one equation of condition statically determinate.
(+ )
 MzC = 0;
(+ - ) Fx = 0;
) Fy = 0;
(+ 6
(+ )
 MzB = 0;

(RAy )(140) + (80)(3.75) (30)(80) (20)(40) + RAx (26.25) = 0


140RAy + 26.25RAx = 2.900
80 RAx RCx = 0
RAy + RCy 30 20 = 0

(Rax )(60) (80)(30) (30)(20) + (RAy )(80) = 0


80RAy + 60RAx = 3, 000

(5.1-a)

Draft
5.1 arches

105
wR
2 [

wR
2 [(
= 2 wR

sin ] |=
=0 =

Next we determine the horizontal reaction



(+ ) MB = 0;

(HC )(R) + (Vc )(R)

HC

=
=

2 wR

2 wR

sin ) (0 sin 0)]

(5.4-a)

=
2

|wRd
{z }

=0

wR
2

dP

R
| cos
{z }

=0

moment arm

=
2

cos d

=0

wR[sin ] |=02 = 2 wR wR( 2 0)



= 2 1 wR

(5.5-a)

By symmetry the reactions at A are equal to those at C


Draw the shear and moment diagram for the three hinged statically determined semi-circular arch
under its own dead weight w, Fig. 5.3. Solution:
Reactions: Those were determined earlier, Example ??. For the sake of clarity, we repeat their derivation:
1. Starting with CY
(+ )
 MA = 0;

(CY )(2R) +

CY

=
=

wR
2 [

sin ]

wR
2

=
=0

(Cx )(R) + (Cy )(R)

Cx

=
=

2 wR

(1 + cos )d

=0
wR
|=
=
=0
2 [(
= 2 wR

2. Next we determine the horizontal reaction



(+ ) MB = 0;

|wRd
{z } |R(1 +{zcos )} = 0
dP
moment arm

2 wR

sin ) (0 sin 0)]

(5.6-a)

=
2
=0

wR
2

|wRd
{z }
dP

=
2

R
{z }
| cos

=0

moment arm

cos d

=0

wR(sin ] |=02 = 2 wR wR( 2 0)



= 2 1 wR

(5.7-a)

3. By symmetry the reactions at A are equal to those at C

Shear Forces: Considering the free body diagram of the arch, and summing the forces in the radial
direction (FR = 0):
Z

wRd sin + V = 0
(5.8)
( 1)wR cos + wR sin
=0
| 2 {z
|2 {z }
}
Cx

Victor E. Saouma

Cy

h
i

V = wR ( 1) cos + ( ) sin
2
2

(5.9)

Computing Literacy for Undergraduate Engineering Students

Draft
5.1 arches

107

Axial Forces: Similarly, if we consider the summation of forces in the axial direction (F N = 0):
Z
( 2 1)wR sin + 2 wR cos
wRd cos + N = 0
(5.10)
=0


(5.11)
N = wR ( 2 ) cos ( 2 1) sin
Moment: Now we can consider the third equation of equilibrium (M = 0):
( 2 1)wR R sin 2 wR2 (1 cos ) +
Z
wRd R(cos cos ) + M = 0
=0


M = wR2 2 (1 sin ) + ( 2 ) cos

(5.12)
(5.13)

We seek to determine the vertical deflection of the crown of the three hinged statically determined
semi-circular arch, Fig. 5.4 under its own dead weight w, Fig. ??.
1. We first seek to determine the analytical expression of the moment diagram. From statics, it can
be shown that the vertical and horizontal reactions are Rv = 2 wR and Rh = ( 2 1)wR.
2. Next considering the free body diagram of the arch, and summing the forces in the radial direction
(FR = 0):
Z
( 2 1)wR cos + 2 wR sin
wRd sin + V = 0
(5.14-a)
=0


V = wR ( 2 1) cos + ( 2 ) sin
(5.14-b)
3. Similarly, if we consider the summation of forces in the axial direction (F T = 0):
Z
( 2 1)wR sin + 2 wR cos
wRd cos + N = 0
=0


N = wR ( 2 ) cos ( 2 1) sin

(5.15-a)
(5.15-b)

4. Now we can consider the third equation of equilibrium (M = 0):

( 2 1)wR R sin 2 wR2 (1 cos ) +


Z
wRd R(cos cos ) + M = 0
=0


M = wR2 2 (1 sin ) + ( 2 ) cos

(5.16-a)
(5.16-b)

5. The real curvature is obtained by dividing the moment by EI


i

M wR2 h
(1 sin ) + ( ) cos
=
EI EI 2
2

(5.17)

6. The virtual force P will be a unit vertical point in the direction of the desired deflection, causing
a virtual internal moment
M =
Victor E. Saouma

R
[1 cos sin ]
2

(5.18)

Computing Literacy for Undergraduate Engineering Students

Draft
5.1 arches

109

7. Hence, application of the virtual work equation yields:


1
|{z}

=
=

5.1.2

Listing

5.1.2.1

arches.m

i R
wR2 h

(1 sin ) + ( ) cos [1 cos sin ] |{z}


Rd
2
2
=0 |EI
{z
} |2
{z
}

dx


wR4  2
7 18 12
16EI
4

.0337 wR
EI

(5.19-a)

Figure 5.5: Simply Supported Arch with Uniform Load

Equations used for calculation of shear force, axial force, and bending moment are as follows:

V
N
M

1) cos + ( ) sin ]
2
2

= R[( ) cos ( 1) sin ]


2
2

2
= R [ (1 sin ) + ( ) cos ]
2
2

R[(

arches.m file starts here:


%Arches is a script that plots the Bending Moment, Shear Force,
%and Axial Force for a three pin semi circular arch under uniform

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
5.2 beam1

111

Shear Force
200
90
120
60
0

150

30

200

180

0
330

210
240

270

300

Axial Force
400
90
120
60
200
0
150
200
400
180

30
0
330

210
240

270

300

Bending Moment
3000
90
120
60
1000
150

1000
3000

180

30
0
330

210
240

270

300

Figure 5.6: Sample output for arches.m using r = 100 and = 2

5.2
5.2.1

beam1
Description

SUBDIRECTORY : beam1
SYNOPSIS: shear and bending moment diagram for a simple beam (Structures)
DESCRIPTION: BMdemo.m gets the bending moment and deflection for a simply supported beam
subjected to either a point load or a distributed load.
CONTENTS:
BMdemo.m
M2deflection.m
P2M.m
P2V.m
w2M.m
w2V.m
Victor E. Saouma

the main program


converts bending moments to deflections by integration
converts point loads to moment using a formula
converts point loads to shear using a formula
converts uniform loads to moment using a formula
converts uniform loads to shear using a formula
Computing Literacy for Undergraduate Engineering Students

Draft
5.2 beam1

113

Continuous Load
R1 =

b
(2a + b)
2L

R2 =

b
(2c + b)
2L

M = R1 x
= R1 x

for (x < a)

(x a)
2

for (a x a + b)

= R2 (L - x)

for (x a + b)

V = R1
=

for (x < a)

(x a)(R2 R1 )
+ R1
b

= R2
00

v =

for (a x a + b)
for (x a + b)

v(i 1) 2v(i) + (i + 1)
M (i)
=
EI
dx2

BMdemo.m file starts here:


%BMdemo
%this script gets the bending moment and
%deflection for a simply supported beam subjected to either
%a point load or a distributed load
%prompt the user for the load type
choice=input(Analyze for point load (1) or a uniform load (2) ? );
%clear the screen
clc
%do the point load case
if choice==1
%prompt the user for some parameters
P=input(Enter P: );
a=input(Enter a: );
L=input(Enter L: );
E=input(Enter E: );
I=input(Enter I: );
number_points=input(Enter the number of discretization points: );
%calculate the mesh size
dx=L/(number_points-1);
%get the BM
M=P2M(P,a,L,dx);
%get the shear
V=P2V(P,a,L,dx);

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
5.2 beam1

115

Shear

Bending Moment

x 10

4
2
0
0
4
x 10
1

10

12

10

12

10

12

1
0

Displacement

0.5
0

Figure 5.8: Sample output of BMdemo.m with a pointload using P = 20 kN, a = 6 m, L = 12 m,


E = 200 GPa, I = 6e6 mm4 , and 12 discretization points.

%
%This algorithm integrates the bending moment twice
%using the central difference method.
%The second derivative is defined as
%
%
v(i-1) - 2v(i) + (i+1)
%v= ---------------------%
dx^2
%
%
%Using the central difference method we can w%The central difference method will take on the form Av=b.rite
%
%
v(i-1) - 2v(i) + (i+1)
%M(i)/EI = ---------------------%
dx^2
%
%If you write the above equation for every mesh point
%you get the following matrix equation.
%
%
-------%
| 1 -2 1 |
| v(-1) |
| M(0) |
%
|
1 -2 1
|
| v(0) |
| M(1) |
%
|
1 -2 1 |
| v(1) |
| M(2) |
%
|
. |
| v(2) |
| .
|
%1/dx^2 |
. |
| .
| = 1/EI | .
|
Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
5.2 beam1
%
%
%
%
%

117

/\
/\
|----A----|
|------------L------------|
|-------B-------|
|---> x

%get b
b=L-a;
%get the reactions
R1=P*b/L;
R2=P*a/L;
%make a vector x
x=(0:dx:L);
%get the moment
M=R1*(x<a).*x + R2*(x>=a).*(L-x);
%the above statement is a shorthand way of saying
%for i=1:length(x)
% if x(i) < a
%
M(i)=R1*x(i);
% elseif x(i) >= a
%
M(i)=R2*(L-x(i));
% end
%end
%Matlab is very fast at evaluating matrix operations
%like the shorthand command for M. Matlab is not so fast
%at doing if statements and for loops.

5.2.2.4

P2V.m

function V=P2V(P,a,L,dx)
%FUNCTION V=P2V(P,A,L,dx) returns the Shear diagram for a
%point load on a simply supported beam
%
%
|P
%
|
%
\|/
%
__________________________
%
/\
/\
%
|----A----|
%
|------------L------------|
%
%

|-------B-------|
|---> x

%get b
b=L-a;
%get the reactions
R1=P*b/L;
R2=P*a/L;
%make a vector x

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

5.12 Stress/Strain Programs

151

2*Theta = 22.46 degrees

x 10

Tmax
1

Tau xy

0.5

P1
2*Theta

S2

S1
Sigma x

P2

0.5

1
Tmin
5

10

15
7

x 10

Figure 5.28: Example 2(e): Mohrs circle of 2-D stress.

Tmax2

150

100

Tmax1
Tmax3

Tau xy

50
S3

S2

S1
Sigma x

50

100

150

150

100

50

50

100

150

200

Figure 5.29: Example 3(c): Mohrs circle of 3-D stress.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
Chapter 6

Fortran 90: INTRODUCTION


For a better understanding of fortran, this chapter will begin with a brief overview of the architecture
of a computer, role of its software, and finally status of fortran.

2 The next section will be devoted to a brief review of fortran (with which the reader is asumed to have a
certain familiarity), highlight those features which may not have been covered in an introductory course,
and terminate with recommendations for programming style and documentation.

6.1

Introduction

6.1.1

Computer Architecture and Software

6.1.1.1

Computer Hardware

Digital computers are concerned with the processing of data1 abd their basic architecture has seen little
if any fundamental changes since the conceptual model first proposed by Von Neumann in a landmark
paper in 1946:
3

Storage: of data and commands:


Data as well as commands are internally stored in binary form (0 or 1).
The most elementary unit of data is the bit.

A group of eight bits form a byte. A byte can have 28 = 256 different values, and is usually
used to store a character (extended ASCII).
In most present day computers, four bytes form a word.

Early PCs had 16 bit word, most other computers have 32 bits, and supercomputers have 64
bits.
Storage is accomplished on any one of the following:

1. cache memory, extremely fast, it acts as a buffer between the CPU and the core memory.
2. Core memory, very fast, usually around 8 Mb (106 ) bytes for PCs and at least 32 Mb
for workstations.

1 Early

on Engineers used extensively analog computers.

Draft

6.1 Introduction

155

1. a 1,012 by 1,012 8 bit graphical display (i.e a resolution of 1, 012 1, 012 pixels, each one
capable of assuming up to 28 = 256 colors).
2. A keyboard, and a mouse
3. Unix Operating system
4. At least 12 Mb of core memory
5. 200 Mb of disk space
6. Access to a local area network (usually ethernet)
7. X based window management

and access to laser printer, plotter, CD-ROM, tape drive, digitizer, scanner, speaker, modem.
Computers are often networked together, a commonly used standard is ethernet.
Increasingly the distinction between PC and workstation is being blurred. Currently, most new PCs
are computationally more powerful than the immediate past generation of workstations.

Major distinction between PC and Workstation is highlighted by table 6.1.


Feature
Processor
Memory
Operating System
RISC
Monitor
Resolution
Bit Planes
Graphics Accelerators
Networking
Editors
Virtual Memory
Primary Application
Source of Software
Graphics

PC
Intel
8-16 Mb
Windows 95/NT
N
15-17
1024x1024
8
Y
Novell
Word
N
Everything
Microsoft
Open GL

Workstation
Motorola
32-64 Mb
Unix/Motif
Y
19-21
1024x1024
8-24
Y
Ehternet
Vi, Emacs, Crisp
Y
Scientific Computing
Public-Domain, GNU, Vendors
Open GL, X

Table 6.1: PC Vs Workstation

6.1.1.2

Computer Software

For the computer to operate, it must also have:


Operating System: which is a collection of programs to control the operation of the hardware and
application programs.
Early on each computer vendor had its own operating system. Most recently, Unix 3 has
emerged as the uncontested de facto standard operating system for workstations, mainframes,
and supercomputers. It is also increasingly used on PCs for scientific computing (through
Linux).
3 Unix

is a trademark of AT&T.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

6.2 From Source to Binary

6.2
6

157

From Source to Binary

There are two major steps in creating an executable code:

Compiling: which takes as input the source code(s) written (in ASCII) by the developped and converts
it into an object code. Usually, the former has extensions such as .f, .F or .for, and the later
.obj.
Linking: Which takes the object files written by the user, and link them not only among themselves bu
also with standard (fortran) and non-standard (such as graphics) libraries. This process results in
an executable which on Unix is by default called a.out, or given an extension .exe in Windows.

6.3
7

Sample Example

To begin with, use your favourite editor to create the following file ello.f5

program Hello
print *, Hello, world
end program Hello
8

Next save the file, and type

f90 hello.f
a.out

6.4
6.4.1
9

Fortran Compilers
Compilers

In the Bechtel Lab, you have access to the fortran compilers listed in Table 6.2.
Compiler

Debugger Description
Sun Workstations
f77
dbx
Fortran 77
f90
None
Nag Fortran 90
IBM Workstations
f77
xldbx
Fortran 77
xlf90
xldbx
Fortran 90
PC
MicroSoft Power Station Fortran Compiler
Table 6.2: Fortran Compilers in the Bechtel Lab
It should be noted that the Fortran-90 compiler f90 on the Sun is only a pseudo-compiler in the
sense that the code is first internally translated into C and then compiled with a C compiler. This was

10

5 This classic example was first introduced by XX & xx in their introductory book on C, and has since then become the
opening example in most introductory computer language tutorials.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

7.1 Background

169

ndata=ndata+1
end do count
mean=sum/real(ndata)

32

Finally, do loops can be nested.

7.1.6

Input/Output

7.1.6.1

Devices

Default Devices/Read/Write Units must be assigned to input and output devices. On most systems,
they are 5 for the keyboard, and 6 for the screen.
33

Hence, by default, the basic format of read write formats becomes

read*, a,b,c
print*, a,b,c

Selected Input/Output Devices In the most general case, input data will be read from, and output
writen into user specified files. Thoose files must first be defined through the open statement which
takes the following form
open (unit=unit number,file=file name, status=status) where unit number is an integer number assigned to the device, file name is a character string giving the file name, and status is a
character string which can be old, write, or read.
7.1.6.2

Formated I/O

33 The format for the read statement is as follows


read(unit number,format label)variable list where unit number is the device number specified through
the open statement, and format label is the format label as defined below.

The format for the write statement is as follows


write(unit number,format label)expression list where unit number is the device number specified through
the open statement, and format label is the format label as defined below.
34

35

Note that we can use the default devices for both read and write

open(unit=1,file=input.dat)
open(unit=2,file=output.dat)
write(*,*) About to start reading from unit 1 ! May be placed for debugging purposes
read(1,800)a,b,c
write(2,900)a,b,c

Format Definition A format can be defined in anyone of the following ways:


Statement Label: referring to a format statement
900

write(6,900)A
format(f10.2)

Character Variable provides a flexible way to dynamically define the format:

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

7.1 Background

7.1.8

171

Style

1. Nested loops should be arranged such that the inner most loop should reference the first subscript,
and the outer most loop, the last subscript.
do

k=1,50
l=1,20
a(l,k)=b(l,k)+c(l,k)
end do
end do
do

2. All common blocks and sub-system control variables defined via parameter statements are defined
in include files. The naming convention for include files is based on their contents; include files
containing common blocks have the extension .cmn and include files containing parameters have
the extension .par. The different extensions allow the developer to determine the contents of an
include file without using a text editor.
3. Fortran is not a case sensitive language. However, lower case code is allowed. All source code
should be in lower case, this is much easier in a Unix environment which is case sensitive, with the
exception of the following exceptions:
Global or common variables begin with an upper case letter; all other characters are lower
case.
Variables defined via parameter statements are all upper case.
This allows the developer to quickly determine where a particular variable comes from.
4. All variables should be declared; and the FORTRAN standard for variable types should be ignored.
To insure that all variables are declared the -u option should be used when the source code is
compiled on the Sun. Explicit declaration of all variables eliminates typographical errors and the
omission of function subroutine type declarations, both of which are fairly tricky bugs to locate.
5. Variable names should be selected in a logical manner by choosing descriptive names. All variables
should have no more than 6 characters. Also a common syntax rule should be adopted where
a single basic variable name is employed with different prefixes depending on its usage in the
program:
(a) Prefix i,j, or l should be used to indicate a DO loop variable
(b) Prefix k will indicate a counter
(c) Prefix m will indicate a maximum value
(d) Prefix n will indicate a given number
For example ipoin, npoin, mpoin will indicate a particular point, number of points, and maximum number of points respectively.
6. All do loops should end on separate continue statements and the code between a do statement and
the corresponding continue statement should be indented. This is more a matter of readability
than anything else, but often comes in very handy when examining a particularly long do loop.
7. Ideally, a subroutine should have only one return statement. This is particularly true with long
subroutines where multiple return statements make it difficult to follow the logic of the subroutine. It can be especially difficult to debug a subroutine with multiple return statements and for
Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

7.2 Assignment

7.2

7.2.1

173

Assignment
Beam on Elastic FOundation Deflection

The defelection of a beam, length L, and flexural rigidity EI on elastic foundation with stiffness k by a
central point load P is given by
v=
where =

q
4

k
EI

2P [sinh(L) cos(x) cosh((L x)) sin(L) cosh(x) cos((L x))]




k sinh2 (L) sin2 (L)

(7.1)

Find the deflection for x = 0, 2, and 5 m for P = 100 kN, k = 4 103 kN/m2 and EI = 106 kN/m2

7.2.2

Quadratic Equation

Write a program to read in three numbers a, b and c, assumed to be the coefficeints of the quadratic
equation
ax2 + bx + c = 0
(7.2)
and calculate and print the roots. Account for the three possibilities
1. Two different real roots
2. One (double) root
3. A pair of complex conjugate roots

7.2.3

Statistical Analysis

Retrieve (through anonymous ftp to bechtel) the following set ftp/pub/Matlab/set1.dat. It contains
results of concrete compressive strength fc0 for two different ready mix companies.
Determine the Mean, Standard Deviation, Coefficient of variation, Skewness, and Kurtosis. (Refer
to MATLAB lecture notes).

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
Chapter 8

Fortran 90: ARRAYS


8.1
8.1.1

Background
Definition

An array is defined to have a shape given by its number of dimensions, called rank 1 and extent for
each one of these.

8.1.2

Declaration

Whereas the declaration of scalar quantities is optional (unless we use implicit none0, all arrays
must be declared. For example

real, dimension(20):: force


real, dimension(20,20):: k

Alternatively we can use the following format


real :: force(20)
real :: k(20,20)
3 It is conventially assumed that the first subscript of a two-dimensional array represents the row, and
the second the column.

In fortran, arrays are stored column-wise, i.e. internally all arrays (no matter what their rank is) must
be stored sequentially as a vector, hence stiffness will be stored as
k(1,1),k(2,1),...,k(20,1),k(1,2),k(2,2),...k(20,2),k(1,3),...k(20,20)

Array subscript can be negative, zero, and/or positive:

{\tt real:: vector(-10:22)}

is an example of one dimensional array where the subscript may range from -10 to +22.
{\tt real dimension(-10:25, 20:40):: grid}

is a two dimensional array.


1 Note that the rank of an array is the number of dimensions and has nothing to do with the mathematical rank of a
matrix.

Draft

8.1 Background

8.1.6

177

Dynamic Memory Allocation

10 Dynamic allocation is useful when reading a datafile of a size that is not known until run-time. The
array would need to be defined as allocatable. This is done by simply adding allocatable to the
declaration line, with the dimensions specified as :. Next, the array must be allocated once the
dimensions are known, but before anything is read into the array. A second argument can be used with
the allocate routine, in which the error status is set according to the success of the call. This should
always be checked, to be sure there was enough memory for the allocation.

real,
dimension(:,3), allocatable :: nodal_coordinates
integer, dimension(:,2), allocatable :: element_connectivity
integer
:: error
read*, number_nodes, number_elements ! Get the matrix dimensions
allocate(nodal_coordinates(number_nodes, 3), stat = error)
allocate(element_connectivity(number_elements, 2), stat = error)
if (error .ne. 0) then
print*, "Allocation failed"
stop
endif
read*, nodal_coordinates
read*, element_connectivity
...
! Use arrays
...
deallocate(nodal_coordinates, element_connectivity) ! Release memory when finished

8.1.7
11

do Loops & Vector Operations

The do loops is often unnecessary for most array operations


1. Rows, columns, matrices, etc. may be assigned to each other as long as the dimensions are the
same. All of the following assignments are valid:
! Initialize A and B to dummy arrays of the same dimension
integer, dimension(5) :: a = (/ 1, 2, 3, 4, 5 /)
integer, dimension(8) :: b = (/ 1, 2, 3, 4, 5, 6, 7, 8 /)
integer, dimension(8) :: c
...
c = b
! set vector c equal to vector b
a = b(4:8)
! Assign to a the 4th through 8th elements of b
b(3:7) = c(2:6) + a

2. For example, if we have an array (any dimensions) and want to initialize it to any scalar, say 0.0,
rather than walking through each element with nested do loops, we can simply say matrix =
scalar, and every element of matrix will then be assigned the value of scalar.
3. Some do loops can be replaced with a call to the dot product intrinsic function.
real, dimension(4) :: a, b
c = dot_product(a,b)

4. Arrays or matrices can be accessed in non-ascending order, and portions can be extracted using
appropriate subscripts. To repeat the dot product of the previous example with array b reversed,
the following could be done:
c = dot_product(a,b(n:1:-1))

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
Chapter 9

Fortran 90; PROGRAM UNITS;


POINTERS
9.1
9.1.1
1

Background
Program Units

A fortran 90 code is a modular hierarchical object defined by fundamental blocks.

2 Each program unit may have one or more external procedures. Those procedures (function and/or
subroutine) are nearly independent pieces segments of the code. They can be written separately, make
it easier to debugg the code, can be reused in other programs, and can be reused in the same code.

Program and procedure can share data through the module unit.

9.1.1.1

Main Program

Always assign a header, i.e. program stress.

End the program similarly: i.e. end program stress.

Always return control to the main program upon termination (good programming practice), and hence
there should be no more than one stop statement in your code.

For abnormal completion, you may append a character string after the stop
stop Incomplete data, abnormal completion

8 There should be few executable statements in the main program. Calls to subroutines should be used
instead.

9.1.1.2

Functions

9 Often times an application program needs to have a relatively simple operation to be performed. If
that operation is to be repeated, and returns a single variable as a result of an operation on one or more

Draft

9.1 Background

191

return
end function average

9.1.1.3

Recursive Subprograms

Fortran 90 supports recursion. If a subprogram calls itself, directly or indirectly, the keyword
recursive must appear in the subprogram statement.

17

18 Recursive functions must also declare a result variable to avoid ambiguity with array-valued functions
that are directly recursive. The result variable is used to hold the function result for each function
invocation; the function name is used to invoke the function itself. Consequently, the recursive functions
name should never appear on the left side of an assignment statement. An example of a recursive factorial
function is shown below.

recursive function factorial( n ) result( f )


integer f
integer, intent( in ) :: n
if ( n <= 0 ) then
f = 1
else
f = n * factorial( n-1 )
end if
end function factorial

9.1.1.4

Subroutines

19 Subroutines are procedures used to perform operations which are too complex to be performed by
functions (if several values need to be returned, or values are simply to be read and passed back).
20 Just as we have intrinsic functions, fortran 90 has intrinsic subroutines which are included in the
compiler. You should consult your compiler manual to determine which intrinsic subroutines are predefined.

21

The general format to reference a subroutine is through the following executable statement
call subroutine-name (argument list)

22

In turn, the first line in a subroutine should look like


subroutine subroutine-name(argument list)

23 Contrarily to functions, a subroutine use the argument list to identify both input and output values
to a subroutine.

24

A subroutine may return zero, one or many values.

25

Declaration of all parameters should include the intent attribute.

26

The subroutine should include a return and end subroutine

27

It is advisable to have input arguments preceding output ones.

28

Following is a main program

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
10.3 Make

10.3

201

Make

When developing a program, the executable file must be continuously recreated as the source code is
modified and recompiled. This can become a hassle, especially if your program is lengthy. If your
modifications have only been in a few of the subroutines making up your program, it is a considerable
waste of time to recompile the entire program. This is where the make command is useful.
A program can be created from several source files, each file containing one or more subroutines.
Make will only recompile those files that have been modified since the last compile and will relink all
the object files and create a new executable.
To use make you need a description file that contains the information make needs to create your
program. This information includes the names of the source files, the compiler you wish to use, the
compiler options, and so on. This file is called the makefile. While this section will not go into the
million and one uses for make it will show you how to build a makefile.
Basically, a makefile consists of a number of definitions and a number of targets. The definitions are
used to specify file names, which compiler and linker to use, flags to use when compiling, etc. The targets
is what tells make what to do when invoked. A target specifies a dependency and a list of command.
The dependencies are used to tell make when to remake something, and the commands are used to tell
make what to do to remake the target. In the following example, the target $(PROGRAM) is dependent
on the files in $(OBJECTS), and the command to make the program from the object files is specified
on the next line (note that the command lines must start with a tab character).
Make is partially intelligent, it understands how to make an object file from a source file, for example
a .o file from a .f file. Thus when it sees that $(PROGRAM) is dependent on a number of object (.o)
files, it will find the source (.f) files in the directory and create the .o files automatically.
The following is an example of a simple makefile. The lines starting with # are comments, the
numbers in parentheses refers to the more detailed explanations following the example.
# (1) Name of the program.
PROGRAM = sample
# (2) List of source files making up the program.
SOURCES.f = \
file1.f \
file2.f \
file3.f \
file4.f
# (3) Linker to use.
LINK = $(LINK.f)
# (4) Flags to the compiler and linker.
FFLAGS += -g
# (5)Source and object files.
SOURCES = $(SOURCES.f)
OBJECTS = $(SOURCES.f:%.f=%.o)
# (6) Default target.
all: $(PROGRAM)

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
10.4 Debugger

203

This looks for a file called makefile in whatever directory you are in. If you want to call your description
file something other than makefile you would use the -f option as follows

> make -f filename


To make another target than the default one, specify the target on the command line to make:
> make target
Usual targets are all (usually default), the program name, both of which makes the executable file, and
clean, with cleans up in the directory.
If you need more information with creating your makefile the on-line man pages may help. Also the
book
Managing Programs with make by Andrew Oram and Steve Talbott, OReilly and Associates, Inc.
may prove very helpful.

10.4

Debugger

Written by Johannes Hermanrud

10.5

Introduction to Debugging

A debugger is a program that makes it easy to debug programs. Using a debugger, one can:
run the program in a normal fashion,
step through the program line by line,
run the program, but stop the execution at specified places (by setting breakpoints),
continue execution after a stop,
see the contents of variables, either at specified times or continuously, and
see the call stack, i.e. see which functions has been called to reach the current point of execution.
This information is valuable in deciding which parts of the program are actually executed, and what the
values of the programs variables are at different points during the execution.
When a program has a serious error, such as a segmentation fault, the operation system will create a
file called core in the current working directory. This file can be used with a debugger to find out where
in the program the error occurred. See the command where for details.

10.5.1

The debugger

Debugger is a tool that can be used with C, FORTIN, Pascal, Modula-2 and assembler (See section 10.5.2
for how to run the debugger). Debugger opens a window on the screen containing a menu bar and five
subwindows.
Menu Bar There are five menu options each with their corresponding submenus. Each menu and
submenu are briefly described below:
Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

10.5 Introduction to Debugging

205

Display Subwindow. This area shows the values of variables specified with the display command.
The text can be scrolled using the scollbar. The display command needs to be used only once
for a single variable, as the display of the variable will be updated throughout the execution of
the program. To get the display window to pop-up either type display variable name or select
Display Window... from the data menu.

Figure 10.1: Debugging Tool

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

10.5 Introduction to Debugging

207

clear [n] Clear breakpoints on line n, if n is not given, clear the breakpoint last stopped at.
change directory - cd path When the debugger is started from the menu system, the current directory
is your home directory. Generally it is best to run the debugger in the directory in which your
program resides, particularly if your program must read any data files. To change from your home
directory to a subdirectory called homework/CVEN5555 type :
(debugger) cd homework/CVEN5555

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
Chapter 11

INTRODUCTION TO UNIX
UNIX is a multi-user operating system that was invented by AT&T in 1969 and has grown to be the
operating system of choice for universities and research organizations. This section will introduce the
novice to some basic commands and also provide more advanced commands or tricks of the trade for
those who are interested.

11.1

logging In

You may login to a Unix system in a number of way; rlogin, telnet from one computer (including pc)
into the (Unix) computer.
In the Bechtel Lab., simply press return and the login prompt should appear. At the prompt, type
in the username which was given to you, and then press return. Then the passwprd prompt will
appear and you must carefully enter the password given to you. Note that as you type the password the
characters will not appear on the screen. Note that Unix is case sensitive.
If this is the first time you are loggin in, then it may bee safe to change your password.

11.2

Changing Your Password

Usage: passwd
After you typed passwd, the system will prompt you for your old password (for security reason),
and then will prompt twice (to make sure that there was no typo error) for the new one.
The system will check after the first entry that the specified password can not be easily guessed by
intruders (no dictionary name or permutations on your name allowed), that it has at least six characters,
and that it contains at least one upper case or numeral or special character.

11.3

Logging Out

In general logging out is from a specific device.


If you are remotely connected to a computer, then simply type exit.
To logg out from the Bechtel Lab., then click the right button of the mouse on the screen and select
quit. Once you are out, type contrl D. If you have followed properly the procedure, then a new login
prompt should appear.
Note: If you are using a workstation, never turn it off when you have finished.

Draft
11.6 Shell

11.5.2

211

Your User Account

When you log into your user account you log into your own directory. The name of this directory will
typically be you last name. This directory is called your home directory. Your working directory is
whatever directory you are currently in, this will change many times during the average loggin session.

11.5.3

Absolute Pathnames

The absolute pathname tells you the path you must travel to get from the root directory to where you
want to go. For example if Smith had a subdirectory called temp, the absolute pathname would be
/bechtel/users1/undergraduate/smith/temp.

11.5.4

Relative Pathnames

A relative pathname points to a particular subdirectory, relative to your current directory. The shell
assumes you are using relative pathnames unless you explicitly use an absolute pathname. If the user
Smith were in his home directory the path to temp would be temp.

11.6

Shell

In Unix a shell is a command-line interpreter. You can choose the shell you want to use. The most
popular ones being /bin/csh and /bin/tcsh or better known as C shell and turbo C shell.

11.7

File Management

11.7.1

Changing Directories

Usage: cd or cd directory
This command is used to change your working directory. If the directory you wish to change to is
the next level down you would type cd directoryname. If the directory you wish to change to is several
levels down you would type cd pathname. The pathname includes:
/bechtel/users1/undergraduate/username/...
A useful shortcut is to type:
~username/...
Where username is your user account name. When you type cd without a directory name, you will
be placed in your home directory. Also typing cd (space) .. will move you up one directory, not to be
confused with the MS DOS command cd.., you must remember to put a space between the cd and the
..

11.7.2

Changing File Protection

Usage: chmod
Since UNIX is intended for multiple users, protection rights for read, write and execute are assigned
to each file. There are three groups to which protection may be separately assigned: uuser (yourself),

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.7 File Management


r
w
x
X

213

Read.
Write.
Execute.
Give execute permission if the file is a directory or if there is execute permission for one
of the other user classes.
For example:
Set owner or group ID. This is only useful with
u or g. Also, the set group ID bit of a directory may only be modified with + or -.
Set the sticky bit to save program text between
processes.

> chmod ugo=rw junk.tex


will set the permission such that the user, group, and others can read from and write to the file
junk.tex.

11.7.3

Copying Files

Usage: cp file1 file2


This command copies file1 to file2. If file2 already exists, it is replaced with file1. If file1 is in you current
working directory but file2 is not, you must include the pathname for file2. The following example copies
file1 to file2, which is in a different directory.
> cp file1 ~username/directory/file2
If you have many files you wished to copy, and they all have similar names i.e. file1, file2, file3, file4, ...,
file10, you can use whats called a wildcard to copy all the files at once. This example puts all the files
named file1 through file10 into the subdirectory called directory.
> cp file[1-10] ~username/directory
If the files are not named in such a way that permitts you to use the wildcard option, you can list out
the names of the files you wish to copy. Here the file sample and exmpl are put into the subdirectory
temp. If a destination for the copy is omitted the files will be put in your current working directory.
> cp ~username/direc/sample ~username/direc/exmpl ~username/temp
If you wish to copy the contents of one directory to another directory this can be done as follows:
> cp ~username/directory1 ~username/directory2

11.7.4

Directory Listing

Usage: ls
Lists all files in your current directory. For example if you would like a listing of all files with the
extension .f in your current directory you could type:
> ls *.f

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.8 Printing Files

215

example either name filename or otherfile can be used to call up the file, they are both valid names for
the same file.

11.7.9

Removing Directories

Usage: rmdir directory


Rmdir removes (deletes) directories. But first the directory must be empty of all files. If you are certain
you want to delete the directory first delete all files in the directory using rm, then delete the directory
using the rmdir command.
> rm ~username/directory/temp/*
> rmdir ~username/directory/temp

11.7.10

Wildcards

Another function the shell provides is wildcard expansion. UNIX shells provide two special characters,
* and ? as wildcards. The * will match any number of arbitrary characters, including none. The ?
will match any single character. The shell looks for files that match the pattern typed and replaces the
pattern with a list of those files that matched. It sends this list to the program. This process is called
expanding the wildcards.
As an example, say you want to list all the files beginning with a. You could type
ls a*
into the shell. All files of any length starting with a would be listed, including the file a if it existed.
It would also match the file a.b since . is not a special character in Unix as it is in DOS, for instance.
Or, if you wanted to list all files of length two that start with a you would type
ls a?
You should be especially careful with wildcards when using rm until you are familiar with how they
match. Use ls to see what files match before using rm.

11.8

Printing Files

For printing ASCII, or post-script files.

11.8.1

Enscript

Usage: enscript -2r -Gfile


When you are printing large source files on the laser printer, this command will rotate the output and
place it in two columns. Also see Print.

11.8.2

Checking the Print Que

Usage: lpq
When you type the command to print a file and hit return the system prompt almost immediately
returns. This does not mean that your file has been printed, all it means is that it has been spooled to a
print que. If you would like to find out how busy the printer is, or how long the print que is, type lpq.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.9 Compressing and Archiving Files

11.9

217

Compressing and Archiving Files

Often users will be asked to limit their disk usage to ten megabytes, and will be notified when their
usage exceeds this amount. If you find yourself nearing this limit you can compress files that you are
no longer using, or wont be using for a while. A text file can be compressed by up to 90%, executables,
slightly less, this is a considerable space saving tool. Also, you can archive files directly to tape, freeing
up diskspace, you can also use the archive tool to do backups of your files. Users will be allowed to use
the cartrigde and 8mm tape drives on Bechtel, with permission from the system administrator, or they
can do backups directly to a diskette in the floppy drive of each machine.

11.9.1

Zipping Files

Usage: gzip filename


The gzip command will generate a file named filename but will tack on the extension .gz. For example:
> gzip filename
the file filename.gz will be generated.
> gzip file1.f
the file file1.f.gz will be generated. To unzip files use the command gunzip in the same manner you use
gzip. If we were to uncompress the FORTRAN source code we compressed in the previous example:
> gunzip file1.f.gz
this will restore file1.f to its normal size and strip off the .gz extension.

11.9.2

Compressing Files

Usage: compress filename


Note that this utility is not as efficient as gzip but is supported on all Unix machines.
The compress command will generate a file named filename but will tack on the extension .Z. For
example:
> compress filename
the file filename.Z will be generated.
> compress file1.f
the file file1.f.Z will be generated. To uncompress files use the command uncompress in the same
manner you use compress. If we were to uncompress the FORTRAN source code we compressed in the
previous example:
> uncompress file1.f.Z
this will restore file1.f to its normal size and strip off the .Z extension.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.10 Spooling Files

11.10

Spooling Files

11.10.1

Color Laser Printer

219

Color post-script files can be printed on the color laser printer on the NAC printer on the second floor
of the Engineering building by typing
printcolor fn
where fn is your filename

11.11

Pipe and Filters

You may wish the output from one command, be the input for another. Connecting commands together
in this fashion is known as a pipe. A pipe is designated by a vertical bar (|) on the command line between
two commands. When a pipe is set up between two commands, the output from the command on the
left becomes the input for the command on the right. Pipes can also be set up between programs.
When a program takes the output from another program as its input and does some sort of operation
on it and writes out a new output file, this is refered to as a filter. A filter can be thought of as some
sort of post-processor. For example, if we wished to take a listing of a directory and sort it by file size
would could do this as follows:
> ls -l | sort +4n
The pipe consists of the use of both commands ls and sort. The filter is sort, since it is rearranging the
output of ls. For more information on ls and sort please see Utilities.

11.12

Multi-Tasking

Suppose you have a large job to run, for example, you might be running a statistical package of some
sort that will probably take a long time. If you were using an MS-DOS machine, like a pc, you would
start the job running and come back later when it finshed. This is called a single process system. UNIX,
on the other hand, is a multi-process system, you can run jobs in the background while still doing
things in the foreground. You may even log off, and the background process will continue to run to
completetion.
Note: it is unethical the submitt batch jobs on a different workstation than the one you are logged
in on, this practice will not be tolerated. Under no circumstances are you to submitt a batch job to
Bechtel.

11.12.1

Job Control

To start a job running in the background, or a batch job, use the & after a command. After you hit
return the system will show you the process ID number, PID. The prompt will then return immediately.
The PID is useful for keeping track of how long the job has been running, and you will also need it if
you wish to kill the job. You dontt need to remember your process ID, however, since there is a simple
UNIX command to check on what processes you have running, (see Checking on a Process). You can
also bring the program back as the foreground job by using the fg function. Here is a sample session:

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
11.13 Utilities

221

foreground, but when the console is idle, the machine will devote more time to the background process.
So, as you sit talking to a friend, or looking something up, the background process will get more of the
cpu than it does when you are working.
You can set the nice value to anything between 0 and 19. The default value, if no number is given
with the nice command, is 10. Processs set with 0 will run fast, processs set with a nice number of 19
will only run when nothing else wants to. If you do not use the nice command, a processs nice number
will be 0. A user can only prioritize those process he has started, and can only increase the nice value
i.e decrease a processs priority. In order to change the priorty of a process you must use the renice
command. See the man page on renice for instructions on how to do this.

> nice -19 ps -l


this will set the nice number of a process to 19, then list all the process running on the machine (see ps
for more information) and the -l option displays the nice numbers for the processes.
Note: if someone has started a process on your machine, notify the system administrator immediatley.

11.13

Utilities

11.13.1

du

Usage: du options filename


The du command displays your disk usage . It gives the number of kilobytes contained in all files and,
recursively, subdirectories within the specified directory. If the filename is omitted, the current directory
is used. The -s option will display the grand total for each of the specified filenames. The -a option
will generate an entry for each file in the listed directory, and recursively go through the subdirectories,
of the directory. So doing du in your home directory will list all the subdirectories and the total space
they are using.

11.13.2

Find

Usage: find [pathname-list] [-options] expression


Used to find files by name, or by other characteristics. Find recursively descends the directory hierarchy
for each pathname under the pathname-list, seeking files that match a given file name or other logical
expression defined by any of the aviailable operators. For example, the following command will search
all directories below the current directory for the files having the name misc.f. The file path will be
printed each time the file is found.
> find . -name misc.f -print
./Isds/Isds2/misc.f
The find command has several operators that can be used for defining search parameters. For instance,
files can be searched for by, name of file, type of file, date accessed, date modified, files newer than
arguement file, etc. For more information on the find command, type man find from a shell tool
prompt.

11.13.3

Script

Usage: script filename


The command script will create a typescript file of a loggin session. Everything that is printed on your
Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.14 Shells and dotfiles

11.13.7

223

Whereis

Usage: whereis [-options] filename ...


Whereis locates source, binary and manual page files for a command. This command searches for
programs in a list of standard places. The available options are:
-b Search only for binaries.
-m Search only for manual sections.
-s
Search only for sources.
-u Search for unusual entries. A file is said to be
unusual if it does not have one entry of each requested
type. Thus whereis -m -u * asks for those files
in the current directory which have no documentation.
Other options are also available for changing or limiting directories in which to search. For more
information type man whereis from a shell tool prompt.

11.13.8

Who

Usage: who
This function will show the login names of all users on the computer you are currently logged in on.

11.14

Shells and dotfiles

A shell is a program that serves as an interface between the user and the operating system. The shell is
a command line interface as opposed to a graphical interface like the windows. That is, the user types a
command line into the shell for execution. Although much work can be done solely through the graphical
interface, some things can be done more efficiently with the command lines, and some things absolutely
require the use of the command line.

11.14.1

.cshrc & .login

When a user first logs in, a shell called csh (C SHell) is started. This shell first reads the contents of the
file .cshrc (C SHell Run Commands) in the users home directory and performs the commands in that
file. This file is very similar to the autoexec.bat file in MS-DOS. After that is done, the shell reads the
contents of the file .login in the home directory and performs the commands in that file. After the shell
is done with the commands in the .login file, it is ready to read commands from the user. This is when
the user generally starts openwindows.
Other shells are started for every cmdtool window that is started under openwindows. Each of these
shells also reads the .cshrc file and performs the commands in it. These other shells do not read the
.login file, only the first (login) shell does that. You can put commands you want every shell to perform
in the .cshrc file. Such commands might include setting the prompt to something other than the default.
One of the abilities of the shell is to alias a command to another. For instance, say you normally run
the command verylongprogramname and you get tired of typing it. You could alias it to something else
like myprog. Then, you would just have to type myprog to start verlongprogramname. The format of
the alias command is:
alias substitute_name original_program_name
So for verlongprogramname, the alias would be
alias myprog verlongprogramname
Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.15 Further Reference

225

Assuming your login is mylogin, this file allows the login mylogin to login to any machines in the lab
from grieg, beethoven, and spot without giving a password. Generally, you would list all the machines
in the bechtel lab. There is a program called rhosts.setup which will create a .rhosts file for you and put
each of the lab machines in it. If you want to add other machines like spot or tramp, you will have to
edit .rhosts by hand.
The example above also allows buddy to log into any of the machines in the lab using your account
from spot. buddy would log in with the command rlogin -l mylogin bechtel. The -l means that
buddy wants to be mylogin on bechtel instead of buddy. This format is also useful if you have
different login names on different machines.

11.14.4

.signature

This file is used when you post news (see the section on news for information on how to get started with
news). When you post an article on news, this file is appended to your post like a signature. Generally
people will put their real name and e-mail address into the .signature file so others reading news will
know who they really are and how to reach them. Some people al from spotso include a humorous or
thoughful saying that they identify with. People reading news will often remember a saying better than a
name. However, dont make the .signature file too long. Generally, four lines or less is always acceptable.
As you increase the size of the file, you increase the risk of people sending you nasty e-mail saying they
dont like waiting for your .signature to be sent over their slow modem. A page long .signature, no
matter how cute it may be, will definitely bring about such mail.

11.14.5

.mailrc

This file will contain various setups for your mail. One usefull application is the definition of aliases to
shorten the length of e-mail addresses. For example, by having the following inside your .mailrc file:
alias bicanic bicanic@cvvaxa.swan.ac.uk
you simply have to address your e-mail to bicanic rather than to: bicanic@cvvaxa.swan.ac.uk

11.15

Further Reference

You can find more information on any of the topics discussed in this section in the following:
The UNIX Programming Environment by Brian W. Kernighan and Rob Pike. Prentice Hall Software Series.
Learning the UNIX Operating System by Grace Todino and John Strang. OReilly and Associates, Inc.
And any of the numerous reference guides and users manuals available in the lab.

11.16

Remote Loggin; Telnet

Telnet is your key to accessing applications on Internet host computers located around the world. In
a TCP/IP environment telnet is used to login to any computer on the network. Your first connection
to a UNIX computer is made using telnet unless you login via a directly connected serial terminal. So
what is telnet? It is terminal emulation program with a limited set of commands for you to remember.
Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.17 File Transfer Protocol (ftp)

11.17.1

227

Definitions

FTP: The Internet standard file transfer protocol. An ftp program is a user interface to this protocol
which allows the transfer to and from a remote network host.
FTP Client: The local program which allows connection to an FTP server for the purpose of sending
or receiving files.
FTP Server: An Internet host which allows clients to connect and transfer files to or from the hosts.
Anonymous FTP: Use of ftp to transfer files to or from a server which allows anyone to connect. The
FTP server allows a user login ID of anonymous or guest and accepts any password input.
The accepted courtesy on the Internet is for the use to provide his or her Internet email address.
ASCII File: Text files are files that you can display on your screen and/or pull into a text editor.
For example, AUTOEXEC.BAT and CONFIG.SYS are text files in DOS. Files you would usually
transfer in ASCII mode include: readme files, source code, uuencoded, binhex, PostScript and
HTML files. Files transferred in ASCII mode are translated so that they appear to be the same
on the local machine as the remote. Text is stored differently on different types of computers. PC
text is represented differently than Mac text. Neither PC nor Mac text is represented the same
as Unix text. Those files are usually ASCII files: Text (.txt, tex, .asc); Source code (.c, .f, .for);
e-mail messages; uuencoded files; PostScript (.ps); Hypertext (.htm, .html).
Binary File: Binary files are not text files. This includes many file types such as: executables, images,
sound, movies, spreadsheets, databases, word processing, and compressed files. Files transferred
in binary mode are copied exactly, bit-for-bit.
Those files are usually binary: Spreadsheets (.xls, ...); Databases (.dbf, .dbt); Word Processing
(.doc, wp); Compressed files (.Z, .zip); Images (.gif, .tif, .tiff, .jpg, .jpeg, bmp, pcx); Sounds (.au);
Movies (.mpg, .mpeg, .mov).
Download: An FTP client receiving a file from an FTP server using the get command is downloading
the file.
Upload: An FTP client sending a file to an FTP server using the put command is uploading the file.

11.17.2

Connecting to an FTP Server

To establish a connection with a remote host (FTP server) from the command line, simply type ftp
<host name>. Once the connection is made, the remote host will require the user enter a valid username
and password. To establish an anonymous ftp session, the username is anonymous and the password is
your full internet email address.

11.17.3

Basic Commands

The words with the less-than (<) and greater-than (>) signs are not literal, but indicate a real,
situtationally-dependent word should be substituted. The information contained within the brackets
([ and ]) are not required.
cd <directory>: Change current directory to the indicated directory. Similar to DOS, there are several
unique inputs for <directory>. They are / (go to the top most directory) and .. (go to the
next higher directory).
Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.18 Standard Unix Editors

229

VI modes: VI has two modes of operation, INPUT mode, and EDIT mode. To get from INPUT mode
to EDIT mode hit the ESC key. Then to get back to EDIT mode, hit the <ESC> key.
Exiting the Editor: You must be in EDIT mode to be able to exit VI, so always make sure by hitting
the <ESC> key. To exit from VI and have the file changes applied to the actual file, need to be
in the editing mode of the editor and type: :wq and hit RETURN. It is possible to exit the editor
without applying any changes. To exit without saving the file, type: :q!. To save the current file
to a new file name, type: :w filename.
VI references: There are many sources of information on the VI editor. The first place you should
look are the users manuals located in the Lab. Most book stores that carry computer books will
also have books specific to the VI editor.
Some useful vi commands are summarized in Table 11.1.

11.18.2

Emacs

Emacs is a freely available editor which has been enhanced by thousands of enterprising contributors.
It is distributed by the Free Software Foundation and is available in both source code and precompiled
forms. (You can ftp a copy from the /pub/gnu directory at prep.ai.mit.edu or one of numerous mirror
ftp sites. ) It supports both character-based and X Window environments and runs under a wide variety
of operating systems, including Unix, DOS, and Windows. Emacs has been written by programmers
for programmers. Its single best feature is that it is infinitely extensible by means of a built-in LISP
interpreter. Almost every command in Emacs is actually a tiny little LISP program that acts upon your
text files. To extend Emacs, you simply modify the existing programs or add a few of your own.
Emacs is known as a modeless editor, meaning that it is always ready to both accept text as input
and act upon that text via user commands. You never switch between command and input modes
in Emacs.
We need to start with some terminology. A buffer, in emacs terms, is where editing takes place. It
can contain a file, or hold new input from the user that is not yet attached to a file. Each buffer can have
a different file in it, and each is treated seperately. The name of the buffer is displayed at the bottom of
the window in what is called the status line. The name of the buffer will generally be the same as the
file in the buffer, if any. The special buffers *scratch* and *help* are exceptions as they do not have
files associated with them.
Also, each buffer can also be in a different mode. The mode of a buffer describes how emacs will act
when editing in that buffer. For instance, if a buffer is in C mode, emacs will try and treat the text as C
source code. In doing so, it will perform certain formating of the code as the user types it in. Likewise, if
it is in Fortran mode, it treats the text as Fortran source. Fundamental mode is the basic mode, which
doesnt try to treat the text in any special way. The scratch buffer starts in Lisp Interaction mode.
In this mode, emacs will try to interpret the text in the same way it does the .Emacs file when it first
starts up. Dont worry about how it works now. The mode the buffer is in is also displayed in the status
line.
The status line gives some other information too. If the file in the buffer has been modified, two *s
will be displayed at the left of the status line. When you save the buffer back into the file, the *s will
be removed.
Go ahead and experiment in the scratch buffer. Dont worry about the text already there. If you
have read it, its purpose has been completed and it can now be discarded or altered. Some of the more
commonly used command keys are listed below.

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft

11.19 Other Editors

231

The keys on the numeric keypad (Home, PgUp, arrows) should do what the keys say. Go ahead
and try them on the scratch buffer, although there is not enough text initially for PgUp and PgDn to
do anything. Try typing several short lines to fill a couple of pages, then try these keys. You can get
numbers by holding down the shift key.

11.19

Other Editors

Victor E. Saouma

Computing Literacy for Undergraduate Engineering Students

Draft
Bibliography

You might also like