Professional Documents
Culture Documents
COMPUTING LITERACY
For Undergraduate Engineering Students
% Dimension of elements
1 ! r_, " _# :$ r% & F1 ! " #
1
A=[ft,Sigma2,(fc-Sigma2)];
2 ! r_, " _# :$ r% & F2 ! " #
1 if (sigma(1)<=ft && sigma(1)>0)
w_nod=C1;
' (') (* + ,- /.0 * 1 2 3 4 elseif (sigma(1)<=0 && sigma(1)>Sigma2)
g1 ! r_, " _# :$ D ! 1 ! r, " # , r, r# 5 D ! 1 ! r, " # , r# 6 r 5 D ! 1 ! r, " # , " , " # 6 r2 for h=1:16
g2 ! r_, " _# :$ D ! g1 ! r, " # , r, r# 5 D ! g1 ! r, " # , r# 6 r 5 D ! g1 ! r, " # , " , " # 6 r2 w_nod(h)=C1(h)+M1(h)*sigma(1);
end
' (' elseif (sigma(1)<=Sigma2 && sigma(1)>=fc)
F1 ! " _# $ Exp ! m ! 7 # " # for h=1:16
8 9 m: ; < w_nod(h)=C2(h)+M2(h)*(sigma(1)-Sigma2);
end
= > ? ' (A@ + * > 0 * else
eqdiff $ Simplify B Factor ! g2 ! r, " # # r3C % D w_nod=zeros(1,14);
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 end
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 >
Victor E. Saouma
Dept. of Civil Environmental and Architectural Engineering
University of Colorado, Boulder, CO 80309-0428
Draft
Contents
81
4.1.1.4 Accessing Mathematica . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.1.5 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.1.1.6 Notebook Front End . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.1.1.6.1 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.1.1.6.2 Cell Brackets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.1.1.7 Brackets, Parentheses, and Braces . . . . . . . . . . . . . . . . . . . . . . 84
4.1.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.2.1 Basic Arithmetic Operation . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.2.2 Approximate Numerical Values . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.2.3 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.1.2.4 Derivatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.2.5 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.2.6 Algebraic Formulae . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.2.7 Solving equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.1.2.8 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.1.2.9 Graphics and Three-Dimensional Plots . . . . . . . . . . . . . . . . . . . 88
4.1.2.10 Interfacing with Mathematica . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.1.2.10.1 Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.1.2.10.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.1.2.11 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.2.12 Graphics hardcopy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.2.13 Input file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.3 Some Mathematica Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.3.1 Basic Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.1.3.2 Mathematical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1.3.3 Some Mathematica Constants . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1.3.4 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.1.3.5 Recall of Previous Expressions . . . . . . . . . . . . . . . . . . . . . . . . 92
4.1.3.6 Assignment of Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.1.3.7 Brackets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.1.3.8 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.1.3.9 Interrupting Mathematica . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.1.3.10 Transformation of Algebraic Expressions . . . . . . . . . . . . . . . . . . 93
4.1.3.11 Differentiation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.1.3.12 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.1.3.13 Summation & Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.3.14 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.3.14.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.3.14.2 Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.3.14.3 Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.3.14.4 Numerical Values . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.3.15 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.1.3.16 Vectors & Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.1.3.17 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.1.3.17.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.1.3.17.2 Plot Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.1.3.17.3 3 Dimensional Plots . . . . . . . . . . . . . . . . . . . . . . . . . 96
5.8.2 Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
135
5.8.2.1 infiltration.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
5.9 montecarlo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
5.9.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
5.9.2 Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
5.9.2.1 montecarlo.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
5.10 3dplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
5.10.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
5.10.2 Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
5.10.2.1 cont.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
5.10.2.2 pix.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
5.10.2.3 smooth.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
5.11 zec . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
5.11.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
5.11.2 Listing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
5.11.2.1 linregress.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
5.11.2.2 zec.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
5.12 Stress/Strain Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
5.12.1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
5.12.2 Sample Output: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
5.12.2.1 Example 1: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
5.12.2.2 Example 2: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
5.12.2.3 Example 3: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
189
9.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
9.1.1 Program Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
9.1.1.1 Main Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
9.1.1.2 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
9.1.1.3 Recursive Subprograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
9.1.1.4 Subroutines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
9.1.1.5 †Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
9.1.1.6 † Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
9.1.2 Derived Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
9.1.3 Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
9.1.3.1 Pointer Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
9.1.3.2 Pointer Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
9.1.3.3 Dynamic Memory Allocation for Pointers . . . . . . . . . . . . . . . . . . 195
9.1.3.4 Pointers to Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
9.1.3.5 Pointers as a Tool for Linked Lists . . . . . . . . . . . . . . . . . . . . . . 196
9.2 Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
9.3 Mendeleev . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
9.4 Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
227
11.18“Standard” Unix Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
11.18.1 vi Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
11.18.2 Emacs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
11.19Other Editors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
List of Figures
5.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
5.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
5.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Draft
List of Tables
Chapter 1
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.
2 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 Availability
4 MATLAB is available in the CAD lab (PC/Windows version), as well as in the Bechtel Laboratory.
5 A relatively inexpensive Student Edition is available from Prentice Hall and can be purchased from
the Buffalo Chip.
6 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.
7 Fig. 1.1.3 illustrates the content of the default directory containing your source code.
8 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.
9
1 Other similar products include IDL, and MATHEMATICA for symbolic computations.
Draft
Chapter 2
2.1 Syntax
2.1.1 Matrix Operations
2.1.1.1 Matrix Definition
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
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,:)
41
ans =
3 -1 5
z=[y(1,:);y(3,:)]
z =
3 -1 5
5 -3 9
diag(v)
ans =
0.2000 0 0
0 1.4000 0
0 0 2.6000
+ addition
− subtraction
∗ multiplication
b power
0
transpose
\ left division
/ right division
5 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
>> x=A\b
x =
1
2
EDU>> triu(lux)
ans =
4.0000 2.0000 3.0000
0 6.0000 11.5000
0 0 -6.2917
EDU>> tril(lux)
ans =
4.0000 0 0
-0.2500 6.0000 0
0.5000 -0.9167 -6.2917
EDU>> tril(lux,-1)
ans =
0 0 0
-0.2500 0 0
0.5000 -0.9167 0
EDU>> diag(lux)
ans =
4.0000
6.0000
-6.2917
EDU>> eig(x)
ans =
4.4123
12.9438
2.6440
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
1
0.1
45
0.8
1
0.6
0.4
0.8
0.4 0.8
0.9
0.6 0.2
0.7
0.4 0
−0.2 0.6
0.2
−0.4
0
1 0.3
−0.6 0.5
0.5 1
0 0.5
−0.8
0 0.2
−0.5
−0.5
−1
−1 −1 −1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
−5
1
0.5 1
0 0.5
0
−0.5
−0.5
−1 −1
9 Note that alternatively you may generate the image within a loop, and insert a pause after each one.
2.2.7.1 Theory
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)
P P
x
dx
y,u
w
M
δV
P i V+ δx dx
V
δv P
δx
dx
M+ δM
δx dx
θi i P
P
j
P
θj
dx
Figure 2.10: Simply Supported Beam Column; Differential Segment; Effect of Axial Force P
d4 v d2 v
EI −P 2 =w (2.29)
dx 4 dx
(e) Tolerance
63
Test your program by solving Eq. 2.33 and compare the number of flops (floating point operations) with
the preceding solution.
Chapter 3
3.1 Background
3.1.1 Numerical Integration and Differentiation
Rb
1 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.
Z b Z b
F (x)dx ≈ P (x)dx (3.1)
a 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 ) (3.2-a)
Xn
= li (x)F (xi ) (3.2-b)
i=1
3In Newton-Cotes integration, it is assumed that the sampling points are equally spaced, Fig. 3.6, thus
we define Z b Z bXn n Z b
X
P (x)dx = li (x)dxF (xi ) = li (x)dxF (xi ) (3.3)
a a i i a
or
Rb Pn (n)
Approximation P (x)dx = W F (xi ) (3.4)
a
(n) R b i=1 i (n)
Weights Wi = a i
l (x)dx = (b − a)Ci
(n)
where Ci are the “weights” of the Newton-Cotes quadrature for numerical integration with n equally
spaced sampling points.
Draft
3.1 Background
R1
−1
P (x)dx
67
P3
P (x) = i=1 li (x)F (xi )
(x−x2 )(x−x3 ) 1
l1 (x) = (x1 −x2 )(x1 −x3 ) = 2 x(x − 1)
(x−x1 )(x−x3 )
l2 (x) = (x2 −x1 )(x2 −x3 ) = −(1 + x)(x − 1)
(x−x1 )(x−x2 )
l3 (x) = = 1 x(1 + x)
(3) R(x13 −x1 )(x3 −x2 ) 1 R 21
W1 = l1 (x)dx = 2 −1 x(x − 1)dx = 31
(3) R−11 R1
W2 = l2 (x)dx = −1 −(1 + x)(x − 1)dx = 43
(3) R1−1 R1
W3 = l3 (x)dx = 12 −1 x(1 + x)dx = 13
R1 R1−1
P3 (3)
−1
F (x)dx ≈ −1
P (x)dx = i=1 Wi F (xi ) = 13 [F (−1) + 4F (0) + F (1)]
which is Simpson’s rule
8 MATLAB’s functions for numerical (definite) integration and differentiation are shown in Table 3.2.
Numerical Integration
trapz trapezoidal numerical integration
quad numerical function integration; Simpson’s rule
quad8 Newton-Cotes 8 panel rule
diff approximate derivatives
9 For example, let us recall the expression for the center of gravity
Z
ydA
y= (3.5)
A
and moment of inertia
Z Z
Ixx = y 2 dA Iyy = x2 dA (3.6-a)
A A
cg
Ixx = Ixx + Ad2y Iyy = cg
Iyy + Ad2x (3.6-b)
and moment of inertia for a given cross section
for a rectangular cross (width b, height h) section we would have
Z
ydA
y = (3.7-a)
A
Z h
b ydy
0
= (3.7-b)
bh
h
= (3.7-c)
2
Chapter 4
MATHEMATICA
4.1 Background
4.1.1 Introduction
4.1.1.1 What is Mathematica ?
4.1.1.2 Availability
7Mathematica 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.
8 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
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).
11If 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.
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.
5. Plotsin(π sin x + y) for −3 < x < 3 and −3 < y < 3 using 33 grid points, no display of the axes.
4.3 References
1. Wolfram, S. “Mathematica: A System for Doing Mathematics by Computer second edition, Addison-
Wesley, 1991.
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 arches
5.1.1 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
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; (RAy )(140) + (80)(3.75) − (30)(80) − (20)(40) + RAx (26.25) = 0
⇒ 140RAy + 26.25RAx = 2.900
(+ - ) ΣFx = 0; 80 − RAx − RCx = 0
(+ 6) ΣFy = 0; RAy + RCy − 30 − 20 = 0
(+ )
ΣMzB = 0; (Rax )(60) − (80)(30) − (30)(20) + (RAy )(80) = 0
⇒ 80RAy + 60RAx = 3, 000 (5.1-a)
Draft
5.1 arches
= wR
2 [θ − sin θ] |θ=π
θ=0 =
wR
2 [(π − sin π) − (0 − sin 0)]
105
= π2 wR (5.4-a)
Next we determine the horizontal reaction
Z θ= π
2
(+ ) ΣMB = 0; −(HC )(R) + (Vc )(R) − |wRdθ
{z } R
| cos
{z θ} =0
θ=0
dP moment arm
Z θ= π
2
π wR
⇒ HC = 2 wR − 2 cos θdθ
θ=0
π θ= π
= 2 wR − 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 deriva-
tion:
1. Starting with CY
Z θ=π
(+ )
ΣMA = 0; −(CY )(2R) + |wRdθ
{z } |R(1 +{zcos θ)} = 0
θ=0
dP
moment arm
Z θ=π
wR
⇒ CY = 2 (1 + cos θ)dθ
θ=0
wR wR
= 2 [θ − sin θ] |θ=π
θ=0 = 2 [(π − sin π) − (0 − sin 0)]
= π2 wR (5.6-a)
2. Next we determine the horizontal reaction
Z θ= π
2
(+ ) ΣMB = 0; −(Cx )(R) + (Cy )(R) − |wRdθ
{z } R
| cos
{z θ} =0
θ=0
dP moment arm
Z θ= π
2
π wR
⇒ Cx = 2 wR − 2 cos θdθ
θ=0
π θ= π
= 2 wR − 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 θ
π π
−( − 1)wR cos θ + wR sin θ − wRdα sin θ + V = 0 (5.8)
| 2 {z } |2 {z } α=0
Cx Cy
h π π i
⇒ V = wR ( − 1) cos θ + (θ − ) sin θ (5.9)
2 2
Axial Forces: Similarly, if we consider the summation of forces in the axial direction (ΣF N = 0):
107
Z θ
( π2 − 1)wR sin θ + π2 wR cos θ − wRdα cos θ + N = 0 (5.10)
α=0
N = wR (θ − π2 ) cos θ − ( π2 − 1) sin θ (5.11)
Moment: Now we can consider the third equation of equilibrium (ΣMθ = 0):
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 (5.15-a)
α=0
N = wR (θ − π2 ) cos θ − ( π2 − 1) sin θ (5.15-b)
6. The virtual force δP will be a unit vertical point in the direction of the desired deflection, causing
a virtual internal moment
R π
δM = [1 − cos θ − sin θ] 0≤θ≤ (5.18)
2 2
Z
wR2 h π i R
π
2 π
1 ·∆
|{z} = 2 (1 − sin θ) + (θ − ) cos θ · · [1 − cos θ − sin θ] |{z}
Rdθ
θ=0 |EI 2 {z 2 } |2 {z }
δP dx
φ δM
wR4 2
= 7π − 18π − 12
16EI
4
= .0337 wR
EI (5.19-a)
5.1.2 Listing
5.1.2.1 arches.m
Equations used for calculation of shear force, axial force, and bending moment are as follows:
π π
V = ωR[( − 1) cos θ + (θ − ) sin θ]
2 2
π π
N = ωR[(θ − ) cos θ − ( − 1) sin θ]
2 2
2 π π
M = ωR [ (1 − sin θ) + (θ − ) cos θ]
2 2
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
Bending Moment
3000
90
120 60
1000
150 30
−1000
−3000
180 0
210 330
240 300
270
5.2 beam1
5.2.1 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 the main program
M2deflection.m converts bending moments to deflections by integration
P2M.m converts point loads to moment using a formula
P2V.m converts point loads to shear using a formula
w2M.m converts uniform loads to moment using a formula
w2V.m converts uniform loads to shear using a formula
• Continuous Load
113
ωb
R1 = (2a + b)
2L
ωb
R2 = (2c + b)
2L
M = R1 x for (x < a)
ω
= R1 x − (x − a) for (a ≤ x ≤ a + b)
2
= R2 (L - x) for (x ≥ a + b)
V = R1 for (x < a)
(x − a)(−R2 − R1 )
= + R1 for (a ≤ x ≤ a + b)
b
= −R2 for (x ≥ a + b)
%get the BM
M=P2M(P,a,L,dx);
4
x 10
115
Bending Moment
4
0
0 4
2 4 6 8 10 12
x 10
1
Shear
−1
0 2 4 6 8 10 12
0
Displacement
−0.5
0 2 4 6 8 10 12
%
%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 | . |
% /\ /\
117
% |----A----|
% |------------L------------|
% |-------B-------|
% |---> x
%get b
b=L-a;
%make a vector x
x=(0:dx:L);
%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
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;
%make a vector x
8
x 10 2*Theta = 22.46 degrees
Tmax
0.5
P1
Tau xy 2*Theta
S2 S1
0
C Sigma x
P2
−0.5
−1
Tmin
−5 0 5 10 15
7
x 10
Tmax2
150
100 Tmax1
Tmax3
50
Tau xy
0 S3 S2 S1
Sigma x
−50
−100
−150
Chapter 6
1 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
3 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:
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.
4 Increasingly the distinction between PC and workstation is being blurred. Currently, most new PC’s
are computationally more powerful than the immediate past generation of workstations.
5 Major distinction between PC and Workstation is highlighted by table 6.1.
Feature PC Workstation
Processor Intel Motorola
Memory 8-16 Mb 32-64 Mb
Operating System Windows 95/NT Unix/Motif
RISC N Y
Monitor 15”-17” 19”-21”
Resolution 1024x1024 1024x1024
Bit Planes 8 8-24
Graphics Accelerators Y Y
Networking Novell Ehternet
Editors Word Vi, Emacs, Crisp
Virtual Memory N Y
Primary Application Everything Scientific Computing
Source of Software Microsoft Public-Domain, GNU, Vendors
Graphics Open GL Open GL, X
7 To begin with, use your favourite editor to create the following file ello.f5
program Hello
print *, ’Hello, world’
end program Hello
9 In the Bechtel Lab, you have access to the fortran compilers listed in Table 6.2.
10 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
5 This classic example was first introduced by XX & xx in their introductory book on C, and has since then become the
ndata=ndata+1
169
end do count
mean=sum/real(ndata)
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.
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 num-
ber 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’.
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.
34 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.
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
7.1.8 Style
171
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
dol=1,20
a(l,k)=b(l,k)+c(l,k)
end do
end 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 maxi-
mum 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 subrou-
tine. It can be especially difficult to debug a subroutine with multiple return statements and for
7.2 Assignment
173
Chapter 8
8.1 Background
8.1.1 Definition
1 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
2Whereas 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
3 It is conventially assumed that the first subscript of a two-dimensional array represents the row, and
is an example of one dimensional array where the subscript may range from -10 to +22.
{\tt real dimension(-10:25, 20:40):: grid}
matrix.
Draft
8.1 Background
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
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))
Chapter 9
9.1 Background
9.1.1 Program Units
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.
3 Program and procedure can share data through the module unit.
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
return
191
17Fortran 90 supports recursion. If a subprogram calls itself, directly or indirectly, the keyword
recursive must appear in the subprogram statement.
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 function’s
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 pre-
defined.
21 The general format to reference a subroutine is through the following executable statement
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
10.3 Make
201
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.
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, O’Reilly and Associates, Inc.
may prove very helpful.
10.4 Debugger
Written by Johannes Hermanrud
Menu Bar There are five menu options each with their corresponding submenus. Each menu and
submenu are briefly described below:
Display Subwindow. This area shows the values of variables specified with the display command.
205
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.
clear [n] Clear breakpoints on line n, if n is not given, clear the breakpoint last stopped at.
207
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
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.
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.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.
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/...
~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
..
r Read.
213
w Write.
x Execute.
X Give execute permission if the file is a direc-
tory or if there is execute permission for one
of the other user classes. For example:
s Set owner or group ID. This is only useful with
u or g. Also, the set group ID bit of a direc-
tory may only be modified with ‘+’ or ‘-’.
t Set the sticky bit to save program text between
processes.
will set the permission such that the user, group, and others can read from and write to the file
“junk.tex”.
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 what’s 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.
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.
If you wish to copy the contents of one directory to another directory this can be done as follows:
> ls *.f
example either name filename or otherfile can be used to call up the file, they are both valid names for
215
> 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.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.
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 won’t 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.
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:
this will restore file1.f to it’s normal size and strip off the .gz extension.
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:
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:
this will restore file1.f to it’s normal size and strip off the .Z extension.
printcolor fn
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.
foreground, but when the console is idle, the machine will devote more time to the background process.
221
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. Process’s set with 0 will run fast, process’s set with a nice number of 19
will only run when nothing else wants to. If you do not use the nice command, a process’s 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 process’s 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 immedi-
atley.
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
11.13.7 Whereis
223
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.
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, don’t 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
don’t 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:
you simply have to address your e-mail to bicanic rather than to: bicanic@cvvaxa.swan.ac.uk
The UNIX Programming Environment by Brian W. Kernighan and Rob Pike. Prentice Hall Soft-
ware Series.
Learning the UNIX Operating System by Grace Todino and John Strang. O’Reilly and Asso-
ciates, Inc.
And any of the numerous reference guides and user’s manuals available in the lab.
11.17.1 Definitions
227
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.
VI modes: VI has two modes of operation, INPUT mode, and EDIT mode. To get from INPUT mode
229
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.
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
doesn’t 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. Don’t 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. Don’t worry about the text already there. If you
have read it, it’s purpose has been completed and it can now be discarded or altered. Some of the more
commonly used command keys are listed below.
The keys on the numeric keypad (Home, PgUp, arrows) should do what the keys say. Go ahead
231
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.
Bibliography