Professional Documents
Culture Documents
Computing
Computing
DRAFT
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 . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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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
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
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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 . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.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. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
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 . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
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.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
66
67
69
74
4.1
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
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.
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
Draft
Chapter 2
Syntax
2.1.1
Matrix Operations
2.1.1.1
Matrix Definition
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
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
b
0
\
/
addition
subtraction
multiplication
power
transpose
left division
right division
Victor E. Saouma
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
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
5
1
1
0.5
0.5
0.5
0.5
1
Note that alternatively you may generate the image within a loop, and insert a pause after each one.
Victor E. Saouma
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)
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)
Draft
2.2 Assignment
63
(e) Tolerance
Victor E. Saouma
Draft
Chapter 3
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)
(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
P3
+ 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
cg
+ Ad2y
Ixx = Ixx
Iyy =
A
cg
+
Iyy
Ad2x
(3.5)
(3.6-a)
(3.6-b)
(3.7-a)
(3.7-b)
(3.7-c)
Draft
Chapter 4
MATHEMATICA
4.1
Background
4.1.1
Introduction
4.1.1.1
What is Mathematica ?
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.
4.1.1.2
5
Availability
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
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
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
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).
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.
Victor E. Saouma
Draft
4.3 References
101
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
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
(5.1-a)
Draft
5.1 arches
105
wR
2 [
wR
2 [(
= 2 wR
sin ] |=
=0 =
HC
=
=
2 wR
2 wR
(5.4-a)
=
2
|wRd
{z }
=0
wR
2
dP
R
| cos
{z }
=0
moment arm
=
2
cos d
=0
(5.5-a)
(CY )(2R) +
CY
=
=
wR
2 [
sin ]
wR
2
=
=0
Cx
=
=
2 wR
(1 + cos )d
=0
wR
|=
=
=0
2 [(
= 2 wR
|wRd
{z } |R(1 +{zcos )} = 0
dP
moment arm
2 wR
(5.6-a)
=
2
=0
wR
2
|wRd
{z }
dP
=
2
R
{z }
| cos
=0
moment arm
cos d
=0
(5.7-a)
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)
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)
(5.16-a)
(5.16-b)
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)
Draft
5.1 arches
109
=
=
5.1.2
Listing
5.1.2.1
arches.m
i R
wR2 h
dx
wR4 2
7 18 12
16EI
4
.0337 wR
EI
(5.19-a)
Equations used for calculation of shear force, axial force, and bending moment are as follows:
V
N
M
1) cos + ( ) sin ]
2
2
2
= R [ (1 sin ) + ( ) cos ]
2
2
R[(
Victor E. Saouma
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
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
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
Victor E. Saouma
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
%
%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
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
Draft
151
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
Tmax2
150
100
Tmax1
Tmax3
Tau xy
50
S3
S2
S1
Sigma x
50
100
150
150
100
50
50
100
150
200
Victor E. Saouma
Draft
Chapter 6
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
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
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
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.
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
6.1.1.2
Computer Software
is a trademark of AT&T.
Victor E. Saouma
Draft
6.2
6
157
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
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
Draft
7.1 Background
169
ndata=ndata+1
end do count
mean=sum/real(ndata)
32
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
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
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
write(6,900)A
format(f10.2)
Victor E. Saouma
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
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
(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
Draft
Chapter 8
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
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)
is an example of one dimensional array where the subscript may range from -10 to +22.
{\tt real dimension(-10:25, 20:40):: grid}
Draft
8.1 Background
8.1.6
177
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
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
Draft
Chapter 9
Background
Program Units
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 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.
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
23 Contrarily to functions, a subroutine use the argument list to identify both input and output values
to a subroutine.
24
25
26
27
28
Victor E. Saouma
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
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
10.4
Debugger
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
Draft
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.
Victor E. Saouma
Draft
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
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
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
Draft
11.6 Shell
11.5.2
211
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
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
Draft
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.
11.7.3
Copying Files
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
Draft
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
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
11.8.1
Enscript
11.8.2
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
Draft
11.9
217
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
11.9.2
Compressing Files
Victor E. Saouma
Draft
11.10
Spooling Files
11.10.1
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
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
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.
11.13
Utilities
11.13.1
du
11.13.2
Find
11.13.3
Script
Draft
11.13.7
223
Whereis
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
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
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
Draft
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
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
Draft
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
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
Draft
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
Draft
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
Draft
Bibliography