Ad PDF
Ad PDF
EXCEL for
Civil Engineers
Gunthar Pangaribuan
1
- This book is intended to introduce a beginner level of using Microsoft Excel in civil
engineering practices
- A direct translation
Copyright © Gunthar Pangaribuan 2016. No part of the book may be translated, reproduced or transmitted
by any form or by any means without permission in writing from the author. Unless for private use, sharing,
distributing and modifying the associated files for any purpose are prohibited.
www.engbookspdf.com
PREFACE
Microsoft Excel learning is perceived as more attractive from time to time and it is
probably the most widely software‐learning topic written into books, websites, courses,
tutorial videos, groups, etc. Favored by many people because Excel is relatively easy to
operate and giving "completely" results by showing spreadsheet form (rows and columns),
images, text, tables, charts, and so on. Talking about Excel for applied engineering
calculation cannot be separated from the discussion on Visual Basic for Application (VBA)
macro, which is the programming language of Microsoft Visual Basic for the automation of
certain tasks. This is due to macro like any other programming language capable of doing
iterative calculation or repeating the calculation process with ease. There is a unique
combination between worksheet as user‐interface and VBA, which turned out to be a lot
makes it easy for users to create a program.
This book also discussed the depiction in AutoCAD software. Why? Because the drawing
creation process can be done through Excel formulas or macros, and this will enhance a
series of producing program. The advantage of an AutoCAD drawing creation is no doubt
that relies on high image accuracy with a myriad of features it will certainly be a challenge
to create drawings. With the ease of working with Excel, coupled with a lot of given
examples in this book, it is expected to increase the interest of the reader to create new
original application programs. Thus, each model or even a specific model of calculation will
be an exciting challenge for a programming job is already enjoyable.
Gunthar Pangaribuan
ii
www.engbookspdf.com
CONTENTS
PREFACE ................................................................................................................................................... ii
Chapter 1: BASICS OF EXCEL...............................................................................................................1
1.1 Worksheet and Workbook ............................................................................................................ 1
1.2 Data Type .............................................................................................................................................. 2
1.3 Formula.................................................................................................................................................. 5
1.4 Built‐In Function................................................................................................................................ 7
1.5 Array Formula..................................................................................................................................... 9
1.6 Data Formatting.............................................................................................................................. 11
1.7 Error Message.................................................................................................................................. 11
1.8 Printing ............................................................................................................................................... 12
1.9 Making Charts .................................................................................................................................. 13
1.10 Engineering Drawing.................................................................................................................... 15
1.11 Visual Basic for Application ....................................................................................................... 24
1.11.1 Creating Macro ............................................................................................................ 25
1.11.2 Recording Macro ........................................................................................................ 27
1.11.3 Procedure ...................................................................................................................... 29
1.11.4 Running Macro ............................................................................................................ 31
1.11.5 VBA Dictionary ............................................................................................................ 32
Chapter 2: EXCEL FUNCTIONS......................................................................................................... 33
2.1 Math and Trigonometry Functions......................................................................................... 33
2.2 Logical Functions............................................................................................................................ 36
2.3 Lookup Functions........................................................................................................................... 38
2.4 Text Functions ................................................................................................................................. 40
2.5 Data Analysis Functions .............................................................................................................. 43
2.5.1 Linear Regression ...................................................................................................... 43
2.5.2 Polynomial Regression ............................................................................................ 52
2.5.3 Interpolation ................................................................................................................ 53
2.5.4 Statistical Data............................................................................................................. 59
2.5.5 Circular Reference ..................................................................................................... 65
iii
www.engbookspdf.com
Chapter 3: CREATING MACRO ......................................................................................................... 69
3.1 Function Procedure....................................................................................................................... 69
3.2 Sub Procedure.................................................................................................................................. 74
3.3 Control Structures.......................................................................................................................... 76
3.3.1 Looping ........................................................................................................................... 76
3.3.2 Branching....................................................................................................................... 79
3.4 User Defined Function Problems............................................................................................. 83
3.5 Structure of Program.................................................................................................................... 97
3.5.1 Input Output Form..................................................................................................... 97
3.5.2 Work With Modules .................................................................................................. 98
3.5.3 Tips.................................................................................................................................100
3.6 Chart Macro.....................................................................................................................................102
3.7 Manipulation on Program Steps ............................................................................................108
Chapter 4: MATRIX PROGRAM..................................................................................................... 112
4.1 Matrix Definition...........................................................................................................................112
4.1.1 Types of Matrix..........................................................................................................112
4.1.2 Matrix Operation ......................................................................................................115
4.2 Program for Matrix Operations..............................................................................................124
4.3 Matrix Method for Structural Analysis................................................................................132
4.3.1 Upper Structure ........................................................................................................132
4.3.2 Sub Structure .............................................................................................................134
Chapter 5: NUMERICAL METHOD ............................................................................................... 135
5.1 Numerical Integration ................................................................................................................135
5.2 Numerical Differentiation.........................................................................................................138
Chapter 6: PROGRAM FOR 2D FRAME STRUCTURE ANALYSIS......................................... 144
6.1 Case Example..................................................................................................................................144
6.2 Sign Convention for Diagram ..................................................................................................160
6.3 Application ......................................................................................................................................162
Chapter 7: PROGRAM FOR 2D TRUSS STRUCTURE ANALYSIS .......................................... 163
7.1 Case Example..................................................................................................................................164
7.2 Application ......................................................................................................................................176
iv
www.engbookspdf.com
Chapter 8: BEAM ON ELASTIC FOUNDATION.......................................................................... 180
8.1 Case Example..................................................................................................................................182
8.1 Application ......................................................................................................................................187
Chapter 9: LATERALLY LOADED STRUCTURE........................................................................ 189
9.1 Case Example..................................................................................................................................189
9.2 Application ......................................................................................................................................196
Chapter 10: ONE DIMENSIONAL CONSOLIDATION ............................................................... 199
10.1 Application 1 ..................................................................................................................................205
10.2 Application 2 ..................................................................................................................................207
Chapter 11: AUTOCAD SCRIPT FILE........................................................................................... 210
11.1 Creating Scripts in Worksheet................................................................................................210
11.2 Creating Scripts in VBA..............................................................................................................231
REFERENCES ...................................................................................................................................... 240
ATTACHMENT: PROGRAM CODE................................................................................................. 241
v
Gunthar Pangaribuan
Graduated from Indonesia Institute of Technology and earned a bachelor degree in Civil
Engineering. Getting started with a career in geotechnical engineering services and became
his major work which he has spent over 10 years. During the time, he has created numerous
computer programs especially for completion of geotechnical problems using ExcelVBA
AutoCAD the magic trio he relies on. Some of the programs are presented in this book. In
2012, he joined the oil and gas company as a facility engineer. The current activities and
interests include, traveling, social media, tea, music, band, and rock guitar solo.
vi
www.engbookspdf.com
CHAPTER 1
BASICS OF EXCEL
The work performed by Excel is basically the job of entering data which is then processed
to obtain the desired results. It is, in principle, the same as entering data into an electronic
calculator. However, the data entered here consists of various types and coupled with
existing Excel facilities makes it possible to present the appearance of numbers, text,
associated tables, graphs and a database. This makes Excel becomes well integrated to
create a reporting text and the problem analysis as well.
Each version of Excel to be developed to always make changes and additions of new
facilities, while is still maintaining compatibility with previous versions. But the changes do
not alter the basic features of this software as a worksheet for computing applications. In
this book, we will be working with Microsoft Excel 2007.
Figure 1.1 shows the elements of a workbook. At the top of the page there is a title bar
displays the workbook name. Underneath, there is a Ribbon, new interface intoduced in
Excel 2007, which is a navigation tool replaces the menu and tool bars in earlier Excel
version as a tool of access to Excel commands. All commands are grouped and placed into
tabs for particular purposes, thus a tab contains groups of commands.
Worksheet is divided into rows and columns. In Excel 2007, the number of columns and
rows have been improved from previous versions. Columns are from A to Z, then AA, AB to
XFD (16,384 columns), while the rows start from 1 to 1,048,576. The intersection point of
column and row forms a cell as a place to fill data. Each cell has an address referred to by a
column and a row, for example cell B4 is a cell in column B and 4th row. The address of
selected cell can be seen in the Name Box below the Ribbon.
www.engbookspdf.com
A collection of cells is called a cell range, forming an array extending horizontally or
vertically. For example range A1: A5 is a collection of cells from A1 to A5, forming an array
of 5 x 1 or the range A1: C5 form a 5 x 3 array, and so on.
The name of the worksheet can be replaced by other names, by clicking twice on the sheet
tab, press Delete to clear the name, then write the new name; or by right‐clicking on the
tab and then on the shortcut menu click Rename to change its name.
a. Text: alphabet characters and text: A, B, ‐Z, AB, A2, Computers ...
c. Date: the date data typically refers to the setting of a computer calendar or
formulated in the calculation.
d. Hours: Data of hours generally are referred to computer time setting or formulated
in the calculation.
e. Formula: mathematical expressions that calculate two or more values produce a new
value.
f. Function: a function that is used for various applications such as calculations, finance,
mathematics and trigonometry, statistics, database, logic and others.
www.engbookspdf.com
Quick Access Toolbar Tittle Bar Close
e
C ommand Tab Close Window
Command
ds related to the tab
Ribbo
on
Formulla Bar
Name Box
Active Cell
Scroll Bar
Sheet Tab
Fig
gure 1.1: Ex
xcel 2007 Worksheet
W
Ta
able 1.1: Exccel Basic Co
ommands
Sh
hortcut
Name Descriiption
o Icon
or
Offiice Button Icon to basicc commands below:
SSave a file with
w the naame of the workbook
k
Sav
ve
t
that is beingg done
SStore the filee with anotther name in
nto a folderr
a
and directoory, or to a disc. By default file
e
extension o .xlsx is given (free macros). Iff
of
Sav
ve As Alt+FA
t file conttains macro
the o (VBA) an
nd needs to
a
activate each time it is opened, an n extension
o .xlsm exteension mustt be given.
of
New
w O
Open a new workbook
Opeen O
Open an exissting workb
book
Prin
nt P
Print a work
ksheet throu
ugh the prin
nter device
Closse C
Close the wo
orkbook (Cllose Window
w icon)
An Introd
duction to Excel
E for Civiil Engineerss 3
www.engbookspdf.com
Exitt C
Close the program and exit Excel (iicon Close)
Quick Access
Too
olbar:
Und
do C
Cancel the laast job
Red
do R
Repeat the last job
Tab
b HOME
Copy the daata of a celll or range of cells to
C
a
another loccation. To select
s the data to be
Cop
py
c
copied or cu
ut, then clicck on the ceell or range
o cells wherre the data is then presss Ctrl+C
of
Move the data to
M o another location.
C
Commands such as Cut, Copy and
d Paste can
Cut b found in the pop‐up
be p menu by clicking
c the
r
right mousee button on
n the highliighted cells
o by pressing Ctrl+X
or
Put the dataa into a new
P w cell or ran
nge of cells.
P
Paste commmand is don ne after preeceding Cutt
Paste o Copy. To
or o place thee data, clicck the neww
location, th
hen press Enter
E or by
b pressingg
C
Ctrl+V
Display Inseert dialog box.
D b Used to insert a
Inseert > Cells Alt+IE n
new cell, row
r or column at th he pointerr
p
position (higghlighted ceell)
Inseert > Sheet Rows
R Alt+IR Insert a new
w row at the pointer position
Inseert > Sheet
Alt+IC Insert a new
w column at the pointerr position
Coluumns
Alt+HO
Forrmat .> Row F
Format roww, consistss of the row
r heightt
(H
Home >
Height ssetting, to hiide and to unhide
u row
Fo
ormat)
F
Format colu
umn, consistts of the collumn width
Alt+HO
Forrmat .> Column
C s
setting, autoomatic wid dth (autofit selection),
(H
Home >
Widdth hide and show colu
h umns, and d showingg
Fo
ormat)
information n of the standard colummn width
Alt+HO
F
Format cell such as nummbers, textt, font used,
Forrmat > Cell (H
Home >
borders, colors and worrksheet pro
b otection
Fo
ormat)
An Introd
duction to Excel
E for Civiil Engineerss 4
www.engbookspdf.com
Table 1.2 Operators and mathematical relationships
Operator Description
+ Summation
– Subtraction
* Multiplication
/ Division
% Percent
^ Exponentiation
Relationships
= Equal to
> Greater than
< Less than
<> Not equal to
>= Greater then or equal to
<= Less than or equal to
1.3 FORMULA
By definition, a formula is a mathematical expression to calculate the results of two or more
values. Formula can consist of numbers, mathematical operators, functions, reference cell
or range of cells. Cells and cell range are often given a name, for example "A" to B2, or "B"
for a range of D2: D6. Naming cells will be discussed later in this section. All formulas begin
with an equal sign (=). For example, in cell B4 is written the following formula:
www.engbookspdf.com
When a formula to be copied, it needs to be considered what is the type of cell in the
formula. Relative cell is the cell that will adjust to its new place when copied. Cell C1 that
contain formula =A1+B1 will be =C2+D2 in Cell E2. The result is as shown in Figure 1.2.
Absolute cell is a cell that does not change the address if copied to another place. The
notation is to add $ before the name of a column or row number, for example: $A$4. Adding
$ in the name of any column or row number will only change one address. Column A in $A4
will remain when copied, but the row number will adjust to its new location. And vice versa
with cell A$4. Such cells are called semi‐absolute cell.
A B C D E F
1 20 30 =A1+B1
2 =C2+D2
3 =$A$1+B1
4 =$A$1+D2
5 =$A1+B1
6 =$A2+D2
7 =A$1+B7
8 =C$1+D8
9
10
Figure 1.2: Copied formula and the results in spreadsheet
Formula stating cell relationships or range of cells, for example, =B4+C30 or =SUM (A4:
C20) are more difficult to read than the mathematical relationship with the more practical
variable name, for example, =x+n or SUM(B). Name of cell or cell range is created by
clicking Formula > Define Name. This name applies to all sheets in a workbook. If it only
represents the specific sheet, for example, Sheet1, the writing is Sheet1!x, i.e. to the variable
x in Sheet1. The use of variables is highly recommended because it will simplify a formula.
The names used and the locations can be seen in Name Manager and you can also create,
edit and delete a name.
www.engbookspdf.com
1.4 BUILTIN FUNCTION
Excel has many built‐in functions to build complex formulas, some of them are shown in
Table 1.3. Functions such as mathematic and trigonometry or statistic, for example, are the
most common functions used in engineering practices e.g. to produce calculation data sheet
in laboratory soil testing. Before using a function, it is advised to know well the function
and its arguments. The reference could be found the Help menu or press F1.
A B
1 x y
2 ‐1.0 ‐5.0
3 ‐0.5 0.0
4 1.0 5.0
5 2.0 4.0
6 3.0 0.5
7 4.0 ‐5.0
8 5.0 ‐12.0
Y‐
9 Slope 9 Slope Y‐intercept
intercept
10 ‐1.204 0.537 10 ={LINEST(B2:B8,A2:A8)} {=LINEST(B2:B8,A2:A8)}
Figure 1.3: Array formula for linear regression and the results
Array formula is entered by pressing Ctrl+Shift+Enter and Excel will automatically insert
the formula in brackets ({}). To display values returned by LINEST function, make LINEST
formula in cell A10 as shown in Figure 1.3, and then select the range A10: B10 > press F2 >
Ctrl+Shift+ Enter.
Alternatively, the INDEX function can be used to return the values, as shown below. LINEST
has two results indexed sequentially that are Slope and Y‐intercept.
Y‐
9 Slope intercept 9 Slope Y‐intercept
10 ‐1.204 0.537 10 =INDEX(LINEST(B2:B8,A2:A8),1) =INDEX(LINEST(B2:B8,A2:A8),2)
Format Displayed
0.00 2343.00
0.00E+00 2.34E+03
##0.0+0 2.3E+3
#,##0.00 2,343.00
#,##0.00% 234,300.00%
0.0 ”m” 2343.0 m
Column width and row height can be adjusted by: first way, by dragging the mouse (hold
the left mouse button while moving) when the pointer position at the boundaries of the
column and row headings (there is a sign " " or " "), or second way is by right‐clicking the
mouse on the column or row heading and from the shortcut menu click Row Height or
Colomn Width, then enter desired value in the textbox. The other way is through Home >
Format.
Messages Remarks
Cell contains number, date or time that is wider than the cell
#####
width or minus result in the date and time format
1.8 PRINTING
Before printing the worksheet to paper, you can set the area by blocking the area that will
be printed (press Shift + " " or " " or drag the mouse). Afterward, click the Page Layout
tab > Print Area > Set Print Area. The print area can be seen in Office Button > Print
> Print Preview or to press the shortcut key Ctrl+F2. Printing then performed through
> Print > OK or pressing Ctrl+P.
The limits of printing page can also be specified through the View tab > Page Break
Preview instead current Normal view. This will show all the data in worksheet to be
printed with a page number. You can also adjust the boundaries of the printing page by
dragging the mouse on the blue boundary line.
Page configuration is then set through the Page Layout tab. Click the Print Titles in the
Page Setup group, and a Page Setup dialog box will appear with several sheets tabs which
are Page, Margins, Header/ Footer, and Sheet. Page is to select the orientation and size of
paper, and the scale of worksheet on paper; Margins is to set the boundaries of the text in
the paper; Header/Footer is to make custom header and footer; and Sheet is to set print
area, showing grids, row and column headings, and the print order.
Enter x and y‐values data in the Chart Data Range by clicking a button at the right side of
the input box and then point the pointer to cell A2 and drag the mouse from cell A2 to cell
B8. Click OK and a chart will be created as shown in Figure 1.5. In the chart, the regression
line is also shown with the associated equation. Regression line is created by clicking
mouse on the data in the chart (at point or a line), then right click > Add Tendline > Linear
> checked the Display Equation on Chart. Furthermore, if you want to work with the chart
thoroughly, click the graph area to display Chart Tools tab where commands are grouped
in accordance with their task name, which are Type, Data, Chart Layouts, Chart Styles
and Move Chart.
Note:
As designed for office applications, Excel offers various types of charts. However, we will
not discuss many different types of charts, and but only focused on Scatter chart type
with straight lines that frequently used in this book.
A straight line of XY Scatter chart type is determined by the given coordinates of both ends
required for its input data. If both ends of the line called joint, then a line segment is formed
by the coordinates of two joints. Thus, there will be a series of joint data put into a
worksheet table to create straight lines.
To make it easier to understand the intent and purpose of this discussion, below is given
examples and the followed steps.
Example 1
DDRCreate 3 continuous lines drawing through 4 points (1 to 4), as shown in figure below.
x y
Joint 1 0 0
To create continuous lines as the figure above, it takes the following steps:
1. First step: click on the Insert tab > Scatter > Scatter with Straight Lines and
Markers.
2. Chart Area displays nothing because no data on it as shown below. Click Select
Data on the Ribbon interface to display the Select Data Source dialog box.
4. Following Step 3 is to enter the line coordinate values i.e. series x and series y‐
values. When needed, give a name for the series in the Series name input box.
5. Click OK to end.
The intended joint coordinate and lines for chart depiction can be summarized as below:
Coordinate
Line Joint x1 y1 x2 y2
1 1 2 0.0 0.0 1.0 1.0
2 2 3 1.0 1.0 2.0 3.0
3 3 4 2.0 3.0 3.0 6.0
Thus it can be stated that the first line (no.1) is a line created by given joint 1 and 2
coordinates (refers to the figure).
In step 4, what we do is to enter x1 and x2 range of values (colored yellow) into the Series
X values input box, while the Series Y values is filled by column y1 and y2 range of values
(colored green). To enter x‐coordinates, press Ctrl+left mouse button click at x1 column
and repeat left mouse button click at x2 column to get the range of cells. Do the same way
to enter y‐coordinates.
Repeat step 3 to 5 to make 2nd and 3rd line. The result will be shown as below:
As in Example 1, to simplyfy the portrayal of the drawing it needs to produce joints and
lines coordinate tables. The buiding is composed of 6 joints and 6 straight lines that can be
built up with the following numbering system:
The joinnt coordinattes for assiggning lines on the righht table is obviously
o t repetitio
the on of
inputtingg task of thhe previous joint coorddinates on the left tabble. To avoid d repeated data
entry maanually, VLO OOKUP fun nction can be used by adopting
a thee x, y joint coordinates
c data
of the leeft table as a referencee table to obtain
o x1, y1
y and x2, y2 y coordinaates of the right
table. Th
he formulas in the work ksheet are shown
s as folllows:
To get th
he drawing, do the sequ
uence steps as in Example 1.
An Introd
duction to Excel
E for Civiil Engineerss 19
Example 3
Draw the following truss structure that consists of 21 lines and 12 joints. The joint
coordinates are tabulated as below:
Joint x y
1 1.0 0.0
2 1.5 2.5
3 2.0 5.0
4 2.5 10.0
5 3.0 15.0
6 3.5 20.0
7 4.0 15.0
8 4.5 10.0
9 5.0 5.0
10 5.5 2.5
Before creating the drawing of truss, it is convenient to form lines coordinates as required
for Series X and Series Y input data. The coordinates of truss lines are tabulated as the
following:
Line Joint x1 y1 x2 y2
1 1 2 1.0 0.0 1.5 2.5
2 2 3 1.5 2.5 2.0 5.0
3 3 4 2.0 5.0 2.5 10.0
4 4 5 2.5 10.0 3.0 15.0
5 5 6 3.0 15.0 3.5 20.0
6 6 7 3.5 20.0 4.0 15.0
7 7 8 4.0 15.0 4.5 10.0
8 8 9 4.5 10.0 5.0 5.0
9 9 10 5.0 5.0 5.5 2.5
10 10 11 5.5 2.5 6.0 0.0
11 2 12 1.5 2.5 3.5 2.5
12 12 10 3.5 2.5 5.5 2.5
13 3 12 2.0 5.0 3.5 2.5
14 12 9 3.5 2.5 5.0 5.0
15 3 8 2.0 5.0 4.5 10.0
16 3 9 2.0 5.0 5.0 5.0
17 4 9 2.5 10.0 5.0 5.0
18 4 8 2.5 10.0 4.5 10.0
19 4 7 2.5 10.0 4.0 15.0
20 5 8 3.0 15.0 4.5 10.0
21 5 7 3.0 15.0 4.0 15.0
Next example is to draw truss structure subjected to horizontal load so that each joint will
be shifted as far as n unit. Suppose that the displacement at the joints will be from 0 at
supports to maximum +0.5 unit at joint 6 (at the top), so it will be in a range of 0 < n < 0.5 to
the right direction. The table of joints coordinates is then modified and labeled for two
conditions, before and after loading, where n is used in the calculation. It will show as
follow:
It is noticed that only the x‐values will be changed by adding the horizontal displacement
value of n, from 0 at Joint 1 to a maximum of 0.5 units at the Joint 6. Joint 1 and 11 are fixed
supports so their positions remain in place before and after loading.
After forming the joints coordinates table, next is to create lines coordinates table of Series
X and Y. There are now 42 Series X and Y to be created for the condition of before and
after loading. Table below shows lines coordinates before and after loading:
The drawing of truss lines before and after the horizontal loading are shown in chart
below, which are in blue and red, respectively.
VBA can also serve as a programming language to solve many problems in science and
technology field, for instance to solve a complex iterations and the analysis of civil
structures that are not easily or can not be done rely on the built‐in functions and
spreadsheet standard commands. In this respect, the analogy of using macro is therefore a
repetitive calculation in an effort to get new output when new input is entered.
1.11.1
1 CREATING MACR
RO
To go to
o the window where th he VBA proggramming language is created, cliick Visual Basic
B
to open Visual Basiic Editor (V
VBE) windoow > click th
he Insert menu
m > Moddule to show w the
following window:
VBA pro
ogramming language
l is written in a module th
hat has been added before by Inse
ert >
Module.. Below is an exampple of VBA A programm ming language (progrram code) in a
procedure in a mod
dule:
An Introd
duction to Excel
E for Civiil Engineerss 25
VBA readds, analyzess and manip pulates Exceel's objects through
t theeir properties and meth
hods.
A VBA coode for an object
o is ord
derly compo osed of the object name, a period, followed by y the
property
y or method d. The propeerty is an attribute of an n object andd is always accompanie
a ed by
an equall sign (=), while
w the method is the action
a carriied out withh the object.
In the co
ode created
d above, Seleect and CleaarContents are called method,
m whhereas Selection
in the second row iss an object refers to Raange object in the first row.
r Value on
o the third
d row
is a prooperty of th
he Range object with the value of o 10. The code abovee is intendeed to
remove the existingg value in th
he range A1 1 on Sheet1 and replace it with a newn value of
o 10.
The Worrksheets ("SSheet1") codde refers to active sheeet name, in this
t case is Sheet1.
S
To see the
t available objects in Excel, you can acccess through the Obje ect Browse er by
clicking the icon on VBE tooolbar or pr ess F2. Seleect the Exceel libraries in
i the pull down
d
menu as shown belo ow:
An Introd
duction to Excel
E for Civiil Engineerss 26
Objects are classified into Classes (on Class window) and their Members (on Members
window) that could be a property, a function or a constant. Names, Cells, FormulaArray
for instance, are members of the Range class. Excel’s objects are arranged in a hierarchy;
objects contain other objects from top level to down level. Code below shows an example of
an object hierarchy from the Application object to the Range object:
In the code, Range is the property of the Worksheet object that returns a Range object. It
uses Range(arg) syntax where arg is name of the range (A1) to return a Range object
represents cell A1. Moreover, Worksheet is the property of the Workbook object that
returns a Worksheet object, Workbook is the property of the Application object that
returns a Workbook object, and the top level of this hierarchy is the Application object that
is Excel.
1. Click the Developer tab > Record Macro to display the Record Macro dialog box
with the default name of Macro1 for macro name as shown below:
4. Press Delete to delete the contents of range A1 to E10 and then place the pointer in
cell A1.
The recorded macro is stored in the workbook, and to see the code you have to open the
Visual Basic Editor window through Developer tab > Visual Basic. The code is created as
the following:.
In the recorded macro above there are VBA statements such as Range (), Select, Selection
and ClearContents. You may a bit familiar with these statements that have been briefly
explained in the previous section.
The recording macro tool is very useful for writing complex code or you may indeed never
imagined before, like how to manipulate a chart object such as to copy, to create a title, to
change the colors, making marker, automation for creating lines, and so on. This can all be
done without the need to understand more about the Excel’s object hierarchy that such
“long” and may be a bit confused.
• Sub procedure, procedure that begins with Sub, its name and ended with End Sub
• Function procedure, begins with Function, its name and ended with End Function
• Event procedure, works when there is a certain event, for example, open a
workbook, click the button, activate the worksheet, and so on.
1. Sub Procedure
Syntax:
[statements]
[Exit Sub]
[statements]
End Sub
Remarks
Public Optional. Indicates that the Sub procedure is accessible to all other
procedures in all modules. If not defined, the procedure by default is Public
Private Optional. Indicates that the Sub procedure is accessible only to other
procedures in the module where it is declared
Friend Optional. Used only in a class or object module. Can be accessed from other
procedure in all modules in a workbook
Static Optional. Indicates that the Sub procedure's local variables are preserved
between calls.
name Required. Name of the Sub; follows standard variable naming conventions.
2. Function Procedure
Syntax:
[statements]
End Function
3. Event Procedure
Syntax:
Remarks:
The most frequently used of Event procedure is clicking a button (command button) on
the worksheet. Here is the example code:
The steps and examples of the above procedures will be shown in next chapters.
1. Through the Developer tab > Macros > select the macro name > Run. Function
procedure, Private Sub procedure and Sub procedure written with argument, can
not be run by this way.
2. Clicking Button (Form Control) or the Command Button (Active X control) on the
worksheet.
The second way is commonly used because it is done by only one step. However, it can be
done in two ways, which are as follows:
Create a button through the Developer tab > Insert > Form Controls > Button >
there is a sign "+" on worksheet, and place it on worksheet by dragging the mouse,
the same way to determine its size as well. The Assign Macro dialog box will be
displayed as below. Enter the name of a macro that to be executed and then click
OK.
When a command button is created, the code program is inactive or when the Design Mode
is enabled. Before run macro, click the Design Mode to disable (until it looks unselected).
y = f (a,b,c,…)
Arguments are written after the function name, between parentheses, which are the values
used to perform the operation. The argument can be a numerical value, text, references or
range of cell, name, label or a function.
Excel functions are listed by category such as, math and trigonometry, statistics, finance,
logic, and so on. In addition, Excel also provides macrosheet and Visual Basic for
Applications (VBA) to create a function that is defined by the user (user‐defined function).
Syntax:
ABS(number)
Example:
ABS(4) = 4
ABS(‐4) = 4
SQRT(ABS(‐81)) = 9
Syntax:
INT(number)
Example:
INT(8.9) = 8
INT(‐8.9) = ‐9
TRUNC
Makes a number to an integer by removing the fractional part of the number. To specify the
precision of the truncation, enter a specified number of digits after the number.
Syntax:
TRUNC (number,number_digits)
Example:
TRUNC(8.9) = 8
TRUNC(‐8.9) = ‐8
TRUNC(PI ()) = 3
ROUND
Syntax:
ROUND(number,num_digits)
Example:
ROUND(3.25,1) = 3.3
ROUND(3.247,0) = 3
ROUND(32.47,‐1) = 30
ROUNDOWN
Syntax:
ROUNDDOWN (number,number_digits)
Example:
ROUNDDOWN(3.3,0) = 3
ROUNDDOWN(66.8,0) = 66
ROUNDDOWN(3.14159,3) = 3,141
ROUNDDOWN(‐5.24621,2) = ‐5.24
ROUNDDOWN(1550.24621,‐2) = 1500
ROUNDUP
Syntax:
Example:
ROUNDUP (3.3, 0) = 4
ROUNDUP (66.8, 0) = 67
The num
mber resulteed by multip
plying correesponding components of arrays
Syntax:
SUMPRO
ODUCT(arraay1,array2,…
…)
Examplee
SUMPRO
ODUCT(1,2,3
3) = 1 x 2 x 3 = 6
SUMPRO
ODUCT({1,2,3},{4,5,6}) = 1 x 4 + 2 x 5 + 3 x 6 = 36
SUMPRO
ODUCT({1,2,3,”hello”},{{4,5,6,5}) = 36
3
Syntax:
Examplee 1:
An Introd
duction to Excel
E for Civiil Engineerss 36
Studentss who FAIL L with exam m score > 45 have chan nce to takee a supplem
mentary exaam to
increasee their scorees. Use the fu
unction to find
f out the name of stuudent:
AND
Syntax:
Examplee 1:
AND(2*2
2=4,2+2=4) Return
ns TRUE
AND(2<100,4<100,102<100) Return
ns FALSE
Examplee 2:
(2 x Exam
m score + 1 x Course sccore) / 3.
An Introd
duction to Excel
E for Civiil Engineerss 37
COUNTIF
Syntax:
COUNTIF(range,criteria)
Example 1
Looking for the number of students with specified value for Example 2 above:
COUNTIF(D2: D6,60) = 2
OR
The result is TRUE if one of its arguments is TRUE. Generally nested the IF function.
Syntax:
OR(logical1,logical2, ...)
Example:
Search for a value based on the column index in the table data arranged vertically
Syntax:
VLOOKUP(value,table,col_index,range_lookup)
Example
The experimental result of laboratory test is affected by the size and weight of the used
tools. This example shows how to use VLOOKUP function to read the size and weight of the
ring based on the Ring Calibration table. Suppose it is intended to search the diameter and
A B C D E F
RING
1 CALIBRATION
2
Ring Height Diameter Weight Area Volume
3 No. (cm) (cm) (gram) (cm2) (cm3)
4 1 1.950 5.000 32.850 19.635 38.288
5 2 2.000 5.000 32.000 19.635 39.270
6 3 2.000 5.000 33.440 19.635 39.270
7 4 2.000 5.000 34.980 19.635 39.270
8 5 1.950 5.000 33.700 19.635 38.288
9 6 1.925 4.985 32.000 19.517 37.571
10 7 2.000 5.000 33.000 19.635 39.270
11 8 1.975 5.125 34.000 20.629 39.711
VLOOKUP result:
A B C D E F
Ring Diameter Weight
14 No. (cm) (gram)
15 3 5.000 33.440
16 7 5.000 33.000
A B C
Ring
Diameter (cm) Weight (gram)
14 No.
15 3 =VLOOKUP(A15,$A$4:$F$11,3) =VLOOKUP(A15,$A$4:$F$11,4)
16 7 =VLOOKUP(A16,$A$4:$F$11,3) =VLOOKUP(A16,$A$4:$F$11,4)
HLOOKUP
Search for a value based on the row index in the table data arranged horizontally. The
application of HLOOKUP are almost identical to VLOOKUP, in exception that row index is
needed to lookup the value.
Syntax:
HLOOKUP(value,table,row_index,range_lookup)
Example
Transpose (Copy > Paste Special > Transpose) the Ring Calibration table to arrange table
data as shown below. After that, use HLOOKUP the same way as VLOOKUP example above
to search the diameter and weight of ring no. 3 and 7.
Ring No. 1 2 3 4 5 6 7 8
Height (cm) 1.95 2.00 2.00 2.00 1.95 1.93 2.00 1.98
Diameter (cm) 5.00 5.00 5.00 5.00 5.00 4.99 5.00 5.13
Weight (gram) 32.85 32.00 33.44 34.98 33.70 32.00 33.00 34.00
Area (cm 2) 19.64 19.64 19.64 19.64 19.64 19.52 19.64 20.63
Volume (cm3) 38.29 39.27 39.27 39.27 38.29 37.57 39.27 39.71
=LEFT(text,num_chars)
=MID(text,start_num,num_chars)
Example
A B
1 ENGINEERING ENG =LEFT(A1,3)
2 745.56 RING =RIGHT(A1,4)
3 ENGINEER =MID(A1,1,8)
4 745.5 =LEFT(A2,5)
CONCATENATE
Combines two or more strings from different cells into one string
Example
A B C D
1
Civil
2 Civil Engineer Engineer
3
4 Point Coordinate
5 x y z
6 2.0 4.0 0.0 2,4,0
7 2.0 4.0 ‐1.5 2,4,‐1.5
8 2.0 4.0 ‐1.5 (2,4,‐1.5)
Example
A B C D
1
Civil
2 Civil Engineer Engineer
3
4 Point Coordinate
5 x y z
6 2.0 4.0 0.0 2,4,0
7 2.0 4.0 ‐1.5 2,4,‐1.5
8 2.0 4.0 ‐1.5 (2,4,‐1.5)
D
1
Civil =A2&" "&B2
2 Engineer
3
y = Ax + B (2.1)
where:
The accuracy of the straight line over a number of points data is evaluated by a total
deviation E, which is the sum of squares of the distance e between the points data and the
fitted points:
n n
E = ∑ e = ∑ ( Axi + B − y i ) 2
2
i (2.2)
i =1 i =1
∑[y i − f ( xi )]
2
R2 = 1− i =1
2
n
1⎛ n ⎞ (2.3)
∑i =1
y − ⎜⎜ y i ⎟⎟
2
i
n ⎝ i =1 ⎠
∑
R2 value varies from 0 to 1. R2 = 1 is when the regression line coincides with the data. In
polynomial regression, the higher‐order of polynomial, the closer R2 value to = 1.
Regression in Excel can be obtained using the TREND function, SLOPE, INTERCEPT and
LINEST or with Trendline, a regression line from data relations in an XY coordinate
system. Trendline is created by the following steps: right‐clicking the mouse when the
pointer is on one of the points data in the graph to display a box menu > click Add
Trendline to display the Format Trendline dialog box > select Linear for linear
regression.
The soil shear strength determination from a laboratory test obtains the result as shown in
Figure 2.1. In general, the depiction of data generated from the test is rarely a straight line
to show failure envelope, therefore, it needs a fitted straight line to represent the data.
In directt shear test, the failure envelope is a straight line that is expressed
e in
nto equation
n:
τ = c + σn tan φ
c cohesion intercept
σn normal sttress
An Introd
duction to Excel
E for Civiil Engineerss 45
Shear strength in this model is a linear function over the normal stress, where c and tan φ
respectively expresses Y‐axis intercept and the slope of the line.
In Chart, a regression can be done with Trendline by the following steps: right clicking
mouse when the pointer is on one of the points data on Chart to display a box menu. From
the box menu select Add Trendline to display Format Trendline dialog box > Linear >
Backward to intercept Y‐axis > click Display Equation on Chart. The result is as shown in
Figure 2.1.
The values of A and B that are shown in line equation, y = Ax + B in direct shear test are
equal to those calculated with the following functions:
B = Y‐intercept = INTERCEPT(Y,X)
Shear angle φ therefore can be calculated with ATAN function (in degree):
=ATAN(SLOPE(Y,X))*180/PI()
=INDEX((LINEST(Y,X
X),1) to obtaain Slope,
=INDEX((LINEST(Y,X
X),2) to obtaain Y‐interccept
In practiices, TRENDD function isi entered in a series ofo worksheeet formulas to obtain fitted
f
points reepresents a series of daata (array Y, array X). The
T formula can be writtten as follo
ows:
Shear sttrength can also be exxpressed in major σ1 anda minor σ3 principall stresses in n the
triaxial test
t by plottting ½(σ1 – σ3) againnst ½(σ1 + σ3). The strress condition that fit to a
number of points data
d is referred to as modified faailure envellope, which
h expressed into
equation n:
φ = sin–1(tan α)
a
c=
cos φ
Examplee 2: Logarith
hmic Regresssion
It is often found thaat the data relationship from a testt is presenteed where th
he X‐axis is made
m
in log scaale as show
wn figure 2.22. The equattion 2.1 now
w becomes:
y = A ln (x) + B (2.4)
An Introd
duction to Excel
E for Civiil Engineerss 47
The example data here is adopted from laboratory liquid limit (LL) test, i.e. to determine
soil moisture content at 25 blows. Below are the related informations:
• Moisture content (Wn) = [(weight of wet soil ‐ weight of dry soil) / (weight of dry
soil)] x 100%.
• Water content' (Wn') = fitted Wn in the semi‐log relationship.
• N = blows number
85.00
80.00
Water Content (%)
y = -10.887ln(x) + 105.972
75.00
70.93
70.00
65.00
Data
Figure 2.2 shows the LL test result and a regression line created through Add Trendline
command. The fitted Wn value (Wn') that represents a number laboratory Wn for each N
value can be obtained through the equation below:
y = ‐10.887ln(x) + 105.972
3 Water Fitted
4 Content (%) Wn (%)
5 Wn Wn’
6 =100*(C6‐D6)/(D6‐B6) =TREND(Wn,LOG10(N),LOG10(E6))
7 =100*(C7‐D7)/(D7‐B7) =TREND(Wn,LOG10(N),LOG10(E7))
Liquid Limit (%) =TREND(Wn,LOG10(N),LOG10(25))
The relationship of Wn 'and N in sheet above is a regression line as pictured in Figure 2.2.
In the third example, we will examine on the data that is formed in log‐log scale in the XY
coordinate system. The given data is the standard sieve size (US) for the particle size
distribution of the granular material as shown in Figure 2.3.
Slope and Y‐intercept are respectively the constants a and c in equation 2.5, where the
formulas for this series are, respectively:
Figure 2.4: Chart from Figure 2.2 data series where TREND is used to obtained the
fitted points
In Equation 2.6, m = a positive integer and the equation is called a polynomial function of
order m. Linear regression is a special form of polynomial regression with m = 1, A = ai and
B = ao.
A B
Temp Unit Mass
1 (oC) (gr/cm3)
2 X Y
3 4 1.00000
4 16 0.99897
5 17 0.99880
6 18 0.99862
7 19 0.99844
8 20 0.99823
9 21 0.99802
10 22 0.99780
11 23 0.99757
12 24 0.99733
13 25 0.99708
14 26 0.99682
15 27 0.99655
16 28 0.99627
17 29 0.99598
18 30 0.99568
Figure 2.5: Example of two data series for polynomial regression
Example
Figure 2.5 shows two data series from the relationship between water density and
temperature, where X‐coordinate is the temperature ( oC) and the Y‐coordinate is the water
Figure 2.6 shows chart of the plotted data from Figure 2.5 and regression lines created
using Trendline that consist of Linear and Polynomial of order 2 and 3. It is apparently
seen that the polynomial regression is much better than linear regression for this data
series. The fitted points produced from order 2 and 3 regression seemed like really
coincides with the data and are only distinguished by the value of R2, where order 3 (red
curve) the value of R2 = 1. Excel 2007 provides the type of polynomial regression up to
order 6.
Figure 2.6: Regression analysis using Trendline for data series in Figure 2.5
2.5.3 INTERPOLATION
In an engineering calculation, sometimes it only needs a data interpolation without resolve
it into regression analysis. Here is to find y‐value that correspond to known x‐value a line
segment, based on a number data (x i, yi) tabulation, where xi may continuously be
increased or decreased. Linear interpolation of y‐value corresponds to x‐value is:
yi +1 − yi
y = yi + ( x − xi ) (2.7)
xi +1 − xi
where ( x − xi )( x − xi +1 ) ≤ 0 and x i ≠ x i +1
ln( yi +1 ) − ln( yi )
ln( y) = ln( yi ) + ( x − xi ) (2.8)
xi +1 − xi
where ( x − xi )( x − xi +1 ) ≤ 0 and x i ≠ x i +1
y x − xi y
ln = ln i + 1 (2.9)
yi x i +1 − x i yi
Or,
( x − xi ) /( xi +1 − x i )
⎛y ⎞
y = yi ⎜⎜ i +1 ⎟⎟ (2.10)
⎝ yi ⎠
In Excel, the interpolation value can be obtained by TREND function. Data series for this
function is a line segment formed by xi, yi and xi + 1, yi + 1.
Data X Data Y
0 ‐1
1 0
2 4
3 5
4 ‐1
5 ‐2
6 0
7 3
Plotted in chart:
The interpolation values are in column D, which correspond to new values entered in
column C. The y‐value that correspond to a x‐value that lies between 0 ‐ 1 in cell C3 is
shown in cell D3; the y‐value that correspond to a x‐value that lies between 1 ‐ 2 in cell C4
is shown in cell D4, and so forth.
TREND function and Equation 2.7 can also be used to interpolate x‐values from known y‐
values, by replacing the variable x with y and vice versa in Equation 2.7, or by switching x
and y‐argument in TREND function. The formulas are shown in the worksheet above at row
12, columns C and D.
A sands soil sample of 1,000 grams weight is taken and placed in the sieving machine for a
sieve analysis test. The results are presented in Table 2.2, showing sieve size used and
percent finer. The percent finer (or percent passing) is calculated based on cumulative
weight of soil retained on each sieve. Chart of log grain sizes versus percent finer of soil is
presented in Figure 2.7.
A B
1 Sieeve Size Finer
2 (
(mm) %
3 9.50 100.00
4 4.75 97.80
5 2.36 95.48
6 1.18 88.50
7 0.60 70.60
8 0.30 24.10
9 0.15 2.40
10 0.00
Plotted in
i chart:
An Introd
duction to Excel
E for Civiil Engineerss 57
Figure 2.7: Semilog interpolation for the data of Table 2.2
Notes:
In a statistical data presentation, it is convenient to make the data from observation into
histogram to see the data distribution. In histogram, the observed data plotted against its
frequency distribution and thus, we can get a visual summary and give quick impression on
the observed data.
Example
The following is concrete compressive strength data selected randomly from 40 samples
obtained from the test of characteristics compressive strength of concrete:
To simplify data distribution, the result data divided into several classes within interval
(taken) = 5 kg/cm2, and then tabulated in Table 2.3. The scores from each class of data is
called class frequency, which is represented by height of the bar. To ease data distribution
process into classes can be done by using a function macro or custom function. The
discussion on custom function will be in the next chapter in the topic of user defined
function.
Class
Interval Mid Point Frequency Percent Cumulative
kg/cm2 kg/cm2 N (%) (%)
360‐365 362.5 3 7.5 7.5
365‐370 367.5 3 7.5 15.0
370‐375 372.5 4 10.0 25.0
375‐380 377.5 4 10.0 35.0
380‐385 382.5 5 12.5 47.5
385‐390 387.5 6 15.0 62.5
390‐395 392.5 6 15.0 77.5
395‐400 397.5 4 10.0 87.5
400‐405 402.5 3 7.5 95.0
405‐410 407.5 2 5.0 100.0
40 100.0
Histogram chart of Figure 2.8 is made based on Table 2.3 data. To create a histogram take
the following steps: click Insert tab > Column > Column clusterd > Select Data > Add >
Series Values: select range "Percentage" > OK. Click Edit for Horizontal Axis Labels >
insert range "Mid Point".
To create cumulative frequency chart as Figure 2.9, select the type of XY scatter chart
with smoothlines and markers > Select Data > Add > Series X values: select range "Mid
Point" > Yvalues: select range "Cumulative".
The classification or data distribution is generally defined into three statistical parameters,
which are, range, mean and standard deviation. Range is the difference between the lowest
and the highest values of data. From the concrete compressive strength test result, there is
a range of 48.24, from the lowest 361.23 to the highest 409.47 in kg/cm2 units. The mean
or average is the sum of the data values divided by the total number of data (n). From the
test, the mean is obtained = 384.87 kg/cm2. If a set of data values are divided into M classes,
the mean formula is written as follows:
M
∑m x
i =1
i i
x= (2.11)
n
Where,
Mean is a value that commonly used to represent values of a set of data. In consistent with
this, several measurements are made to state deviation, and one of them is the formulation
of mean square deviation (MSD). The MSD is also called the variance, and the formula is:
∑ m (x
i =1
i i − x) 2
(2.12)
n
Another measurement to be used is the standard deviation (S), which is the square root of
MSD:
∑ m (x
i =1
i i − x) 2
S= (2.13)
n
Through Equation 2:13, the standard deviation from the test result as in Table 2.3 is
calculated = 12:49 kg/cm2, and with divisor of (n ‐ 1), calculated from the sample, MSD and
S is respectively calculated 394.74 and 16.12 kg/cm2. The standard deviation is a measure
of dispersion of a set of data values from its mean; where a big or small of the value
indicates the quality of job execution.
Normal Distribution
From the histogram and measurement of statistical parameters above, it can now be drawn
a normal distribution curve. The normal distribution function is,
2
1 ⎛ x− x ⎞
− ⎜⎜ ⎟
1 2 ⎝ S ⎟⎠
f ( x, S , x) = e (2.14)
S 2π
For log‐normal distribution, it can be obtained by replacing x with ln(x) in Equation 2.14.
Figure 2.10 and 2:11 show normal distribution curve that fits with the percent frequency
data in Table 2.3. Figure 2.12 shows the formulas used in the presentation of the test result.
100
90
ffrequency (%)
80
70
60
Data
50
Normal
Cumulative
40
30
20
C
10
0
360 370 380 390 40
00 410
Con
ncrete compres
ssive strength (k
kg/cm2)
Figure 2.11: Cu
umulative normal
n disttribution curve that fits
fi to data of
o Table 2.3
An Introd
duction to Excel
E for Civiil Engineerss 63
A B C D E F G
Class
1 Interval Mid Point Frequency Percent Cumulative Normal Normal
2 kg/cm2 Kg/cm2 (%) (%) Cum.
3 k N f
4 360‐365 362.5 3 7.5 7.5 3.2 3.7
5 365‐370 367.5 3 7.5 15.0 6.1 8.2
6 370‐375 372.5 4 10.0 25.0 9.8 16.1
7 375‐380 377.5 4 10.0 35.0 13.4 27.8
8 380‐385 382.5 5 12.5 47.5 15.7 42.5
9 385‐390 387.5 6 15.0 62.5 15.6 58.3
10 390‐395 392.5 6 15.0 77.5 13.2 72.9
11 395‐400 397.5 4 10.0 87.5 9.6 84.4
12 400‐405 402.5 3 7.5 95.0 5.9 92.1
13 405‐410 407.5 2 5.0 100.0 3.1 96.5
14 40 100.0
15
16 Mean = 384.87 kg/cm 2
17 S= 12.49 kg/cm2
F G
1 Normal Normal
2 Cumulative
3
4 =500/($E$17*SQRT(2*PI()))*EXP(‐0.5*((k‐$E$16)/$E$17)^2) =NORMDIST(k,$E$16,$E$17,TRUE)*100
5 =500/($E$17*SQRT(2*PI()))*EXP(‐0.5*((k‐$E$16)/$E$17)^2) =NORMDIST(k,$E$16,$E$17,TRUE)*100
D E F
15
16 Mean = =SUMPRODUCT(k,n)/SUM(n) kg/cm2
17 S= =SQRT(SUMPRODUCT(n,(k‐E16)^2)/SUM(n)) kg/cm2
Figure 2.12: Data presentation from the test result to obtain normal distribution and
the formula used in spreadsheet
Mean : =SUMPRODUCT(k,n)/SUM(n)
Normal : =500/(S*SQRT(2*PI()))*EXP(‐0.5*((k‐Mean)/S)^2)
Mean and standard deviation are respectively, calculated using Equation 2:11 and 2:13.
The actual scale for normal function (Equation 2.14) is determined from the interval used,
in this case were taken 5 kg/cm2. Multiply then by 100 to get the depiction in percent (%).
Excel has also the other ways to make distributions, such as Exponential, Weibull, Gamma
and Poisson.
Select to allow
iterative calculation
Example 1
Result : 1 x iteration
A B A B
1 4 1 4
2 =B2 =(A1+A2)/3 2 0 1.33333
5 x iterations
A B
1 4
2 1.97531 1.99177
100 x iterations
A B
1 4
2 2 2
In short, it can be explained herein about the iteration method ‐ to describe the
way of Excel executes Example 1. Formulas in cell A2 and B2 are interrelated and
have the form: x = f(x) and calculated by the following equation:
xn+1 = f(xn),
where: xn = predicted value of x at iteration nth
n = number of iterations
At n = 5, x5 = 1.97531 → x6 = 1.99177
And so on.
Application of Excel iteration can also be applied to solve system of linear equations, to
obtain unknown variables of equations. For an example, to obtain values of x, y which
satisfy the equations below:
2x + 3y = 7
3x ‐ 2y = 4
2x + 3y = 7 x = (7 – 3y)/2; y = (7 – 2x)/3
3x – 2y = 4 x = (4 + 2y)/3; y = (4 – 3x)/2
Next, convert the formed x and y into formulas and placed them in cell B2 until C3 as
shown in the worksheet below. In order to perform iteration, the cell must be linked which
is in this operation the formula in cell B3 and C2 are to be interrelated.
10 x iterations
11 x iterations
Example 2
1 x iteration
A B C A B C
1 0 10 10 1 0 10 10
2 10 =(B1+B3+A2+C2)/4 =B2 2 10 5 5
5 x iterations
A B C
1 0 10 10
2 10 8.64128 8.64128
3 10 6.18032 6.18032
4 0 0 0
100 x iterations
A B C
1 0 10 10
2 10 8.75 8.75
3 10 6.25 6.25
4 0 0 0
In the cell B2 formula, the initial value for B3 and C2 are taken = 0. The value of B2 will be
used as the initial value in the cell B3 formula, where C3 = 0. The values obtained are then
used as a predicted new value in the next iteration.
In its application, for examples, the Excel iterative calculation or circular reference can be
used in the solution of linear simultaneous equations, slope stability analysis using Bishop
method (where the safety factor is on both sides of the equation), and the solution for
seepage below dam using finite difference method.
Some UD functions are made by combining formulas and built‐in functions. UD function is
made in macrosheet or using VBA. Macrosheet is a sheet where macro is created by XLM
language, the original Excel macro language that is still maintained, at least until the Excel
2007. Figure 3.1 shows the UD functions to obtain cosine of an angle in macrosheet and
VBA.
A
1 COSD
2 =RESULT(1)
3 =ARGUMENT("X",1)
4 =RETURN(COS(PI()*X/180))
Figure 3.1: Function in Macrosheet (left) and VBA (right)
User hass to determmine formulas used in the operatiion of functtion of the input variaables,
which is defined by ARGUMENT. A variablle can refer a name or cell
c referencce of worksheet,
such as "x" of COSDD for a cell in
i the workksheet. A forrmula can be
b given a name
n to sim
mplify
writing the next formulas.
f T
The processs in writinng a function is endeed by RET TURN
statemen nt, which reeturns the function
f vallue. Below is
i an exampple of macro
osheet macro to
calculatee volume of a cube:
MVOL fu
unction is ussed in the worksheet
w as follows:
An Introd
duction to Excel
E for Civiil Engineerss 70
Tablle 3.1: Data
a Types in Macroshee
M et
V
Value Data Type
T
1 Nu
umber
2 Teext
4 Logical
8 Reeference
16 Error
64 Array
Creating
g Function in Visual Basic
B for Ap
pplication (VBA)
(
T
Table 3.1: Data
D Typess in VBA
Data Ty
ype R
Range
Integerr ‐
‐32,768 to 32,767
3
Long (lo
ong integerr) ‐
‐2,147,483,6
648 to 2,147
7,483,647
An Introd
duction to Excel
E for Civiil Engineerss 71
Single (single precision) ‐3.402823E38 to ‐1.401298E‐45 ( ‐ values)
1.401298E‐45 to 3.402823E38 (+ values)
Double (double precision) ‐1.79769313486231E308 to ‐4.94065645841247E‐324 (‐)
4.94065645841247E‐324 to 1.79769313486232E308 (+)
Currency ‐922,337,203,685,477.5808 to 922,337,203,685,477.5807
String (variable length) 0 to approx.2 billion characters
String (fixed length) 1 to approx. 65,400 characters
Byte 0 to 255
Boolean (logika) TRUE or FALSE
Date 1 Januari 100 to 31 Desember 9999
Object Any object reference
Variant (with numbers) Any numeric value up to the range of Double
Variant (with characters) 0 to approx.2 billion characters
Such as Excel, VBA also has many built‐in functions that have names similar to Excel built in
functions, say, Cos function in Figure 3.1 or Abs to find the absolute value of a number.
Some Excel built‐in functions can also be used in VBA by using the prefix Application.
Figure 3.2 is an example where Excel built‐in functions are used in UD functions MLIN to
obtain linear regression parameters. MLIN returns an array result (multiple result) which
is the slope of the line and the intersection with Y‐axis (Y‐intercept).
Notes:
• Module with Option Explicit requires all variables are to be declared. If not, VBA will
show an error message "Variable not defined". To declare a variable use Dim,
ReDim, Private, Public and Static statement.
Example
Example
• Use Type..End Type with the example below to define a user‐defined data type.
In Excel‐VBA programming, the value of input data is taken from the value of the cell or
range of cells on worksheet or a Range object with value as shown by its Value property. So
typing in the value in the cell in the worksheet with numbers, text, and so on actually is to
set the value on Value property of these cells. Cells property is commonly used to express
the Range object with the syntax Cells (row_index, column_index), i.e. cell (1,1) to return a
Range object of cell A1.
Here is an example to set a number to a cell in VBA languange, which sets the value of cell
A1 = 10:
Value is the default property of the Range object, therefore negligible or means no need to
be written again. If no object qualifier or an objects before period (Worksheets () above),
then a range of cells are on the active sheet, in this case from which the macro runs, for
example via a command button on the worksheet. Use an object qualifier before the range
of cells if the data is not located on the active sheet with the writing of Worksheet ("sheet
name").
To complete this topic of discussion, the following is a simple example of Sub procedure
named Pro_Sub1:
In creatiing large sccale applicattion prograam, normally, the program is dividded into sevveral
sub‐proggrams or prrocedures SubS and/or with some functions that t each haandles a speecific
task then they calleed with Calll statementt or the namme of functiion. The advantages off this
An Introd
duction to Excel
E for Civiil Engineerss 75
division are to make a programming become more focused, more readable and if an error
occurred it can be quickly addressed. Chapters 6 to 10 show the examples of such
computer programming.
3.3.1 LOOPING
Do While...Loop or Do…Loop While
Repeats a set of statements while a condition is TRUE. If condition becomes FALSE, the
program will exit the looping and move to the next code.
Syntax:
Do While condition
[statements]
[Exit Do]
[statements]
Loop
Example
Repeats a set of statements until a condition becomes TRUE. If a condition becomes FALSE,
the looping will be discontinued.
Syntax:
Do Until condition
[Statements]
[Exit Do]
[Statements]
Loop
Example
For…Next
Syntax:
[statements]
[Exit For]
[statements]
Next [counter
Example
Syntax:
[statements]
[Exit For]
[statements]
Next [element]
Example
Syntax:
[Case expressionlist‐n
[statements‐n]]
[Case Else
[elsestatements]]
End Select
Example
If…Then…Else
Executes a set of statements because of certain condition, when it is not appropriate then
move to another state of condition.
Syntax:
statement(1)
statement(2)
Else
statement(3)
End If
Branching is usually nested in a looping. If the condition is met, the program will exit the
looping with Exit command. If...Then…Else branching can also be combined with And, Or, or
Not statement to state the expression or the relationship between two expressions.
Syntax:
For…or Do Until…
statement(1)
statement(2)
End If
Next…or Loop
Goto…Gosub…Return
Example
Syntax
With
Syntax:
With object
[statements]
End With
Example:
Solution
If a and b express length and width respectively, area in macro can be expressed as a
function of (a, b) = a x b. If the name of the function is Area, the expression is:
Area (a, b) = a x b.
To solve this problem, we will use macrosheet languange. Insert a macrosheet by right‐
clicking on the worksheet Sheet tab > Insert > MS. Excel 4.0 Macro > OK. Type the macro
as follows:
Afterward, we have to define the function name so that it can be recognized by Excel and
incorporated it into Excel functions. The steps are as follows:
2. Click the Formula tab > Define Name to show the New Name dialog box as below.
Enter a macro name in the name text box. Macro name will automatically be
referred to cell A1 with step 1 above.
4. Click OK.
Now back
b to the worksheet. Area functtion is writteen as follow
ws:
Problem
m2
In macro
o, area can be
b expressed as:
function(m,c,a,b) = (½.mb2 + cb
b) ‐ (½ma2 + ca)
An Introd
duction to Excel
E for Civiil Engineerss 84
Now, based on the area formulation above, find the area between y = x + 2, X‐axis, between
a = ‐1, b = 3. The name of function is INAREA.
Solution
Problem 2 in chart:
Before applying the function, perform step no.1 to 4 as in Problem 1. The use of function in
worksheet as follows:
Solution
n
An Introd
duction to Excel
E for Civiil Engineerss 86
Function
ns that created in VBA will automaatically be entered
e into
o Excel funcctions collecction.
The use of the functtion in work
ksheet is as follows:
Problem
m4
1 ⎡ 2MN V V + 1 ⎛ 2MN
N V ⎞⎤
σ y =σ0 ⎢ . + tan −1 ⎜ ⎟⎥
4π ⎢⎣ V + V1 V ⎜ V − V1 ⎟⎥
⎝ ⎠⎦
where,
M = b/y
N = l/y
V = M2 + N2 + 1
An Introd
duction to Excel
E for Civiil Engineerss 87
V1 = (MN
N)2
Solution
n
An Introd
duction to Excel
E for Civiil Engineerss 88
The advaantage to co onvert an eqquation or formula
f into
o a function
n is that it greatly simp
plifies
the calcuulation. Thee above equaation with a condition V1 > V certaainly would be very lenngthy
and requ uires a lot attention
a if b built intto worksheeet formula. It is more easily solveed by
typing itt into VBA coode.
Now, giv
ven a founddation withh a size of 3 x 3 m is subjected to uniform pressure of o 10
ton/m . The vertical stress diistribution of each intterval depth
2 h of 0.5 meeters below
w the
center of
o the found
dation is sho
own in the worksheet
w a below:
as
• Boussinesq ‐ Newmark equation iss intended to t find vertical stress below a cornner of
a rectangular area, therrefore, below w a center a foundatio on of 3 x 3 m is obtainned 4
arrea with the
t same size,
s with 1.5 x 1.5 m dimensiion. Furtheermore, forr the
co
ontribution of four corn ners it shalll be calculatted = 4 σy.
• D
Division by 0 is not allowed in the calculation,, therefore the t value en ntered in ceell A8
sh
hall be an appproach = 0 (take, for example,
e y = 0.0001).
An Introd
duction to Excel
E for Civiil Engineerss 89
Chart is created through Insert tab> Scatters with smoothlines and markers > Select
Data > Add and then select x and y‐data. To modify the chart click once on chart area then
click Chart Tools tab > Chart Layout > Layout 1, and then add chart titles by clicking once
on the title, select Edit Text to type. The depth orientation is made to increase downward
by right clicking the Y‐axis > Format Axis > Axis Option > Values in reverse order.
Problem 5
Solution
(xn,f(xn))
(p,0) (xn+1,0) x
Thus, by induction it obtains tangent line: y ‐ f(xn) = f '(xn) (x ‐ xn) which intercepts X‐axis at
point (xn + 1,0), where:
f ( xn) )
xn + 1 = xn –
f ' ( xn )
Macro
This equ
uation formm can be fou
und in the geotechnica
g al engineeriing to find the embedm
ment
depth of retaining wall with Free‐Earth h Support Method. Th he use of the functioon in
worksheeet is as belo
ow:
Problem
m6
Table X is a numbeer of randomm numeric data from 0 ‐ 100. Creeate macro to calculatee the
amount of data in Table X with a range of values
v from
m Y to Z.
A B C D E F G
1 Tabel X
2 77.58 73.27
7 22.2
21 70.40 81.40
8 52.5
57 98.34
3 68.58 21.86
2 62.3
37 37.61 51.24
5 12.4
41 18.55
4 60.92 22.26
2 35.0
01 23.76 63.34
6 32.8
81 83.16
5 98.27 63.85
6 30.9
97 34.98 64.44
6 70.4
49 17.96
6 71.23 79.63
7 74.2
21 100.00 37.95
3 3.94
4 95.27
7 10.62 20.69
2 5.82
2 74.81 95.09
9 37.4
48 0.74
An Introd
duction to Excel
E for Civiil Engineerss 92
Solution
Macro
I J K Formula at Column K
2 0.0 50.0 19 =DNUM(X,I2,J2)
3 50.0 100.0 23 =DNUM(X,I3,J3)
4 0.0 100.0 42 =DNUM(X,I4,J4)
Argument X is an array argument, in this example is the name that has been defined for the
table data in a range A2 to G7. Argument array can be also written in the following manner,
range(A2:G7) or a certain range, for example range(B2:C7), range(A7:G7) and so on. One
of the simplicities of using function in Excel because it is well supported by the spreadsheet
to create variable names, writing function and put the result at once.
Problem 7
Create a macro for linear interpolation example in Chapter 2.5.3. Use Equation 2.7 to solve.
Solution
Macro
Interpolaation in Chaart:
Y value
Example
An Introd
duction to Excel
E for Civiil Engineerss 94
Problem 8
Create a macro for semilog interpolation example in Chapter 2.5.3. Use Equation 2.10 to
solve.
Solution
Macro
Notes:
• Character "c" and "r" can not be used for variable names in macrosheet, because C
and R stand for column and row, respectively. However, you can define a variable
names such as "c_" or "r_", "cx" or "rx" and so on.
1. R
Read input data
d from the worksheeet
2. To execute data
d input by
y VBA
3. Print the results to the worksheet
w
In large data processsing eitherr from the in nput data orr from proggram executtion, a comp puter
program mming (codiing) must be b planned and a manageed properly y. It is inten
nded in order to
make thee program flow
f becomes simple (n not complexx), saving co
oding, and itt is easy to solve
s
if an error is occurrred. In this section,
s the three of th
he above steeps will be discussed
d th
hat is
how to create
c Inputt Form, Outtput Form and a writing code in VB BA module. In I this topicc, we
are goingg to create a civil structtural analyssis program
m.
Figure
e 3.4: InputtOutput Ex
xample Forrm
An Introd
duction to Excel
E for Civiil Engineerss 97
Figure 3.4 shows that how much the input data entered in the form does not change the
row numbers for data output. It thus obtains a fixed input‐output form and does not
depend on the size of the input data, so that code of read ‐ print steps can be specified in
the program.
Contrary to the input data, it is possible to extend the output data downward because end
of the row is not a boundary that has to be identified for program input. Therefore, the data
presented here following the common way in presenting the results of the structure
analysis extending downward to improve readability.
For the convenience, Author distinguishes each procedure into three modules according to
their tasks as follows:
Module 1 consists of data provision from input‐output form (see Figure 3.3), which is
mainly from: geometry data, materials data, determination of node support or fixities and
load data. Module 1 is the main module, which controls the process of read ‐ execution ‐
print.
Procedures in module 2 are associated with the theory of the structure and the analytical
methods used, e.g. building stiffness matrix, generate load matrix and compute nodal
displacement. Module 2 works based on data provided by Module 1.
Procedures in module 3 are associated with the presentation of data in graphical form, e.g.
for 1). Input data: geometry of the structure and loads, and 2). Data output: displacement,
moment and shear distribution. Module 3 works based on data provided by Module 1 and
Module 2.
Figure 3.5 shows in general how Excel‐VBA programming structure is depicted in a chart.
Figure 3.6 shows a chart of programming structure in real world; consist of main
procedures (abbreviated to facilitate in writing) that exist in TRUSS2D, program for truss
analysis as presented in Chapter 7.
Fig
gure 3.6: Ex
xcelVBA prrogrammin
ng structurre for truss analysis (T
TRUSS2D)
An Introd
duction to Excel
E for Civiil Engineerss 99
3.5.3 TIPS
In desiggning macro os, the mov
vement bettween work ksheet and Visual Basic Editor (V VBE)
window is often done becausse both win ndows are interconneccted. To opeen VBE, clicck on
Visual Basic
B icon Developer
D tab and fro
om VBE clicck Microsoft Excel ico on to go bacck to
worksheeet, or by pressing sho ortcut Alt+FF11 on both h windows. Actually, to acceleratee the
process of displayin ng window is
i to place together
t in the
t monitorr screen as shown in Fiigure
3.7. Thuss, if a VBA program
p cod
de is executed, its interraction to th
he worksheeet can be vieewed
simultanneously.
1. In
n the worksheet wind dow click Restore Dow wn icon in the top rigght corner, then
drag the sheet to the lefft, place it ap
pproximately half size of the moniitor screen. Drag
th
he mouse poointer on thhe worksheeet window endse to adjuust its size.
2. Next, go to th
N he VBE wind dow, in the same way place
p it on th
he right side of the monitor
sccreen. Ther e are now already
a bothh these wind
dows simulttaneously.
3. Now, go to the
N t VBE by clicking itss window. Click C Close VBA Proje ect icon to close
V
VBA Project window on n the left so only VBA module
m is noow visible (to
( display back,
b
cllick icon Prroject Explorer or preess Ctrl+R). To start from f the firrst line presss F8
annd press F8 8 again to continue
c to the next linne. If you want
w to jump p to the dessired
line press Ctrrl+F8 at thee cursor. Eaach line to be executed is marked in n yellow.
4. Press F9 to select
s progrram line at which
w execu
ution will stop (breakp point) when n you
ruun macro byb clicking Run Macro o (F5). Thee other way y is to click
k the left bar at
program linee that you want
w to set a breakpoiint until red
d dot appeaars. Click onn the
reed dot to remove.
An Introd
duction to Excel
E for Civiil Engineerss 100
Through step 1 and 2, the movement between worksheet ‐ VBE is simply done by clicking
one window without losing another window. This kind of method is very helpful if you
want to run the program and see the results at once (through step 3 and 4).
The above steps are very helpful in developing flow of program and solve errors as well.
Running step 3 and 4 is actually the process of tracing errors (debugging) by using
commands in the Debug menu and it is also similar to the process of program verification
(testing) by running code line by line. Testing and debugging is a routine activity to build a
program that requires a number of control structures (branching and looping). A condition
where a program is paused for the purpose of developing the code is called break mode.
One of error type that may occur is when element of an array smaller or larger than the size
that has been assigned to, so when program is running it will show an error message box
"subscript out of range". For example in a looping where the number of process exceeds the
subscript of an element. To get to the location where an error occurs clicks Debug, and
Reset to stop the program.
In Chapter 1 we have discussed how to make lines in the worksheet with formulas and
tables. In this section, it will be created using macro instead of what has done manually. For
a case, Example 3 of Chapter 1.10 will be used here ‐ which is to create truss structure
drawing with joint and coordinate tables as shown below:
Table of joints
Joint x y
1 1.0 0.0
2 1.5 2.5
3 2.0 5.0
4 2.5 10.0
5 3.0 15.0
6 3.5 20.0
Table of Coordinates
Line Joint x1 y1 x2 y2
1 1 2
2 2 3
3 3 4
4 4 5
5 5 6
6 6 7
7 7 8
8 8 9
9 9 10 Data is programmed
10 10 11
11 2 12
12 12 10
13 3 12
14 12 9
15 3 8
16 3 9
17 4 9
18 4 8
19 4 7
20 5 8
21 5 7
By creating macro, the data of x1, y1, x2, y2 of above table do not need to be formulated
because it will automatically be created by the program. The Macro is shown as follows:
• Block 1 is th
B he same to that
t done using
u VLOOKUP formu ula in Chaptter 1. This is the
emptied linee coordinatees in the sh heet table above
a becauuse it is now processeed by
V
VBA. Figure out this, fo ormulas as many as 21 1 rows x 4 columns (8 84 formulass) for
crreating 21 lines
l be is simply
s replaaced with only
o 6 VBA statements
s without lim
mit to
any a numbeer of lines th hat will be created, 100
0 or 200, 100 00, etc.!
• B
Block 2 is code to activaate a Chart that
t to be manipulated,
m , in this casee is Chart1. Note
th
hat, we will never (ev ver) create a new Charrt (Charts.A Add) becau use it will make
m
coode longeer. Instead, we will proceedp maanually (through Inse ert > Charrts >
Scatters) an nd format th he chart as desired.
d To identify
i a ch
hart name right‐click on n the
C
Chart Area > Assign Ma acro, and th
hen see the name in thee Macro Na ame text boxx.
• B
Block 3 is steeps that we do with Ad dd Series in
n the Select Data Sourcce dialog bo ox for
data entry (ssee Chapterr 1). This VB BA looping replaces jo ob for line coordinates
c data
entry which takes a longg time when n done manually.
An Introd
duction to Excel
E for Civiil Engineerss 105
If you want to go further in creating chart it can be continued by setting its properties, such
as line color, marker style and color, or line style (continuous, dashed). The following is
code to set the Chart properties (code enclosed by red lines)
Algorithm is closely related to the use of the control structures in program that are
branching and looping that have been discussed earlier. In array data basis such as
structural analysis, it is necessary to have little bit of knowledge how to manipulate of
program steps or flow of array data using control structures. For examples, is to read and
print data, changing the composition of elements of an array and create integer variables
for storing data.
Example 1
Given a simple example; look at an array data in the worksheet as shown below. Build
elements of array on the left side to be as on the right side, where only the main diagonal
value will still remain while the other = 0.
Here is a code to solve Example 1, starts from reading the data, manipulating the data (code
in red line) and print the results:
Example 2
Create an elements of an array in Example 1 in sequence from bottom to top or from the
largest subscript (myArray (6,6)) to the smallest (myArray (1,1)).
An Introd
duction to Excel
E for Civiil Engineerss 110
Example 3
Assemble the upper triangular array on the left side into the arrangement shown on the
right side, as below.
This example is made as an exercise for readers to make their own code. As previous
examples, the data manipulation in this example is done and completed within two looping.
Use always the Debug menu to verify the program steps. Good luck and hopefully these
examples are helpful to develop your Excel‐VBA skill.
Note:
If you are a beginner in program algorithm, it is fine because your lesson has just started
here. Run the program code of Example 1 and 2 step by step using the Debug menu (for
example by pressing F8) and be focused on the code in the red lines. In break mode, see
how the algorithm for both examples and try to understand the idea behind those code
writing. After you have understood, try to solve Example 3 or any problem you define by
yourself, for example that are developed from Example 1 and 2.
The calculation using matrix operation is very suitable and easy to be performed by a
computer. Thus, in line with rapidly growth of computer usage, matrix method is becoming
very popular and widely used instead of the analysis with manual method. It is widely used
in mathematical siences or in civil engineering field.
Example:
The notation for a matrix is usually used [] and () or {} for row or column matrix. A matrix
can be written [A] = [aij], where aij is element of the matrix, i = 1,2, .. m and j = 1,2, ... n.
Subscript m indicates the number of rows and n for the number of column, or called has
order (m x n). If m = n, then called a square matrix.
Example: {1 2 3 4}
3. Square Matrix
Diagonal matrix
⎡1 0 0 0⎤
⎢0 2 0 0 ⎥⎥
⎢
⎢0 0 3 0⎥
⎢ ⎥
⎣0 0 0 4⎦
⎡ a11 0 0 0 ... 0 ⎤
⎢a a 22 0 0 ... 0 ⎥⎥
⎢ 21
⎢ a31 a 32 a33 0 ... 0 ⎥
⎢ ⎥
⎢ a 41 a 42 a 43 a 44 ... 0 ⎥
⎢ − − − − ... 0 ⎥
⎢ ⎥
⎢⎣ am1 am2 am3 am 4 ... a mn ⎥⎦
Scalar matrix is a diagonal matrix where the diagonal elements are the same number.
⎡4 0 0 0⎤
⎢0 4 0 0⎥⎥
⎢
⎢0 0 4 0⎥
⎢ ⎥
⎣0 0 0 4⎦
Unit matrix
Unit matrix is a scalar matrix in which the value of elements = 1. This matrix is also
called identity matrix and generally denoted by [I]. Multiplying by [I] will return the
origin matrix.
⎡1 0 0 0⎤
⎢0 1 0 0⎥⎥
⎢
⎢0 0 1 0⎥
⎢ ⎥
⎣0 0 0 1⎦
Band Matrix
Band matrix is a square matrix (n x n) where the non‐zero elements are grouped and
form a diagonal elements band.
Symmetric matrix
Example:
If [A] and [B] are two matrices that have equal dimension, then they can be added.
Example
⎡ 2 4 3⎤ ⎡0 − 3 2 ⎤
[A] = ⎢1 5 4⎥ , [B] = ⎢ 4 2 − 3⎥
⎣ ⎦ ⎣ ⎦
⎡ 2 + 0 4 − 3 3 + 2⎤ ⎡2 1 5⎤
[A] + [B] = ⎢ 1 + 4 5 + 2 4 − 3⎥ = ⎢ 5 7 1⎥
⎣ ⎦ ⎣ ⎦
Subtract [B] from [A] is equal to add [A] with [‐B] or written: [A] ‐ [B] = [A] + [‐B].
Matrix Multiplication
Multiplication of two matrices, [A] (m x n) by [B] (n x p) will return [C] of order (m x p).
When do the matrix multiplication the number of columns [A] must be equal to the number
of rows [B].
or written as,
m
cij = ∑ aik bkj
k =1
⎡ a11 a12 ⎤
⎢ ⎡b11 b12 ⎤
[A] = ⎢ a 21 a 22 ⎥⎥ , [B] = ⎢b b ⎥
⎢⎣ a31 a32 ⎥⎦ ⎣ 21 22 ⎦
⎡ a11 a12 ⎤
⎢ ⎡b11 b12 ⎤
a 22 ⎥⎥ ⎢
[C] = [A] x [B] = ⎢ a 21
⎣b21 b22 ⎥⎦
⎢⎣ a31 a32 ⎦ ⎥
Example 2
⎡2 3⎤
⎢ ⎡ 3 3⎤
[A] = ⎢ 4 1 ⎥⎥ , [B] = ⎢ − 1 5⎥
⎢⎣ 7 4 ⎥⎦ ⎣ ⎦
⎡2 3⎤
⎢ ⎡ 3 3⎤
[C] = [A] x [B] = ⎢ 4 1 ⎥⎥ ⎢ ⎥
⎢⎣ 7 4 ⎥⎦ ⎣ − 1 5⎦
⎡ 3 21⎤
⎢ ⎥
= ⎢11 17 ⎥
⎢⎣17 41⎥⎦
Matrix Inverse
Division is not defined in a matrix operation, for it used the inverse of a matrix. Matrix
inversion is only done on square matrix and written with the notation [ ] ‐1 . Multiplication
by matrix inverse is a division by the matrix. For example: [A] x [B] = [C] where [A] is a
square matrix, the equation can be written into a division operation: [B] = [A] ‐1 [C]. [A] ‐1 is
called the inverse of [A].
If [A] is a matrix of order (m x n), then the transpose of [A] is a matrix of order (n x m) or
written as [A]T. Rows and columns of [A] become the columns and rows of [A]T.
[B] = [A]T
bij = aji
Example
⎡1 2 3⎤
[A] = ⎢ ⎥
⎣4 5 6⎦
⎡1 4⎤
⎢ 5 ⎥⎥
[A]T = ⎢ 2
⎢⎣ 3 6 ⎥⎦
([A]T)T = [A]
Many problems in civil engineering are represented by systems of "n" linear equations with
unknown number "n" and this can be solved using matrix methods. It is often, the number
of equations equal to number of unknowns.
3x + 2y = 9
5x – y = 2
⎡3 2 ⎤ ⎡ x ⎤ ⎡9 ⎤
⎢5 − 1⎥ ⎢ y ⎥ = ⎢ 2⎥
⎣ ⎦⎣ ⎦ ⎣ ⎦
where,
Simply to say that the solution of systems of "n" linear equations in matrix form as
expressed in Equations 4.2 is finding {X}, where [A] and [B] are known values. There are
many methods used out there to solve Equation 4.2, some will briefly be discussed in
examples below.
Example
2x + 3y = 7 …(1)
3x – 2y = 4 …(2)
Elimination
Eliminate x from both equations by subtracting Equation 2 from Equation 1 that has
been given a multiplying factor (Eq. B1):
3x – 2y = 4 …(2)
13 13
y=
2 2
y =1
Back Substitution
⎧ x ⎫ ⎧2⎫
Thus, solution for the unknowns {X}: ⎨ ⎬ = ⎨ ⎬
⎩ y ⎭ ⎩1 ⎭
[A]{X} = {B}
[I]{X}=[A]‐1{B}
{X}=[A]‐1{B} (4.3)
Example
2x + 3y = 7
3x – 2y = 4
In this example the matrix inverse will be found using by Gauss‐Jordan method. The
solution is to put the unit matrix [I] next to coefficient matrix [A] such that when the
process is finished [A] become [I] and the previous [I] become matrix inverse [A] ‐1.
The overall process can be just expressed as:
[ A M I ]→ [ I M [A]-1 ]
⎡2 3 ⎤
[A] = ⎢ ⎥
⎣ 3 − 2⎦
⎡2 3 ⎤ ⎡1 0⎤
⎢ 3 − 2 ⎥ ⎢0 1 ⎥
⎣ ⎦⎣ ⎦
⎡ 3 ⎤ ⎡ 1 0⎤
⎢1 ⎢ ⎥
2⎥ 2
⎢3 − 2⎥ ⎢ 0 1⎥
⎣ ⎦ ⎢⎣ ⎥⎦
⎡ 6 ⎤⎡ 1 ⎤
⎢1 2 ⎥ ⎢ 2 0⎥
⎢ − 13 ⎥ ⎢ 3 1⎥
⎢0 ⎥ ⎢− ⎥
⎣ 2 ⎦⎣ 2 ⎦
2
Step 3: Multiply row 2 by −
13
⎡1 ⎤
⎡ 3 ⎤⎢ 0 ⎥
⎢1 2 ⎥ ⎢ 2 2⎥
⎢0 1 ⎥ ⎢ 6 − ⎥
⎣ ⎦ 13
⎣ 26 ⎦
3
Step 4: Add row 1 to row 2 times −
2
⎡8 6 ⎤
⎡1 0⎤ ⎢ 52 26 ⎥
⎢0 1⎥ ⎢ 6 2⎥
⎣ ⎦⎢ − ⎥
⎣ 26 13 ⎦
⎡8 6 ⎤
⎢ 52 26 ⎥
[A]‐1 = ⎢ 6 2⎥
⎢ − ⎥
⎣ 26 13 ⎦
{X} = [A]‐1.{B}
⎡8 6 ⎤
⎧ x ⎫ ⎢ 52 26 ⎥ ⎧7 ⎫
⎨ ⎬=⎢ 6 2 ⎥⎨ ⎬
⎩ y⎭ ⎢ − ⎥ ⎩4⎭
⎣ 26 13 ⎦
⎧104 ⎫
⎧ x ⎫ ⎪ 52 ⎪
⎨ ⎬ = ⎨ 26 ⎬
⎩ y⎭ ⎪ ⎪
⎩ 26 ⎭
⎧ x ⎫ ⎧ 2⎫
⎨ ⎬=⎨ ⎬
⎩ y ⎭ ⎩1 ⎭
3. Iterative Method
This method is actually an approach and done by taking initial value of the unknown
then corrected or refined to enter the next value. We have examined the iterative
method on the example above in the previous discussion in Chapter 3. Here is now
an example from a system of three linear equations:
5x + 4y +3z = 12 (4.4)
4x + 7y + 4z = 15 (4.5)
3x + 4y + 4z = 11 (4.6)
The iterative process is quite long, so in this example we will be working with help
of a computer through Excel iteration.
Next, convert the equations into worksheet formulas and enter in cell B2, C3 and D4.
However, until this stage no iteration to be done because the formulas are still
standing on their own equations.
The value of x, z of Equation 4.5 = value x of Equation 4.4 and z of Equation 4.6
1 x iteration:
10 x iterations:
20 x iterations:
50 x iterations:
The iteration process of finding {X} of Equation 4.4 is actually to make x, y, z to the same
value on the worksheet columns B, C and D in satisfying the given equations. It appears that
they are very close at 50th iteration and by rounding obtained:
⎧ x ⎫ ⎧1⎫
⎪ ⎪ ⎪⎪
⎨ y ⎬ = ⎨1⎬
⎪ z ⎪ ⎪1⎪
⎩ ⎭ ⎩⎭
Matrix Multiplication
In the following example is given a program to calculate the multiplication of two matrices.
The program is named MMULT1, input data and the results will be done on Sheet1.
Example
where,
⎡ 2 3⎤
⎡ 3 3⎤
[A] = ⎢⎢ 4 1 ⎥⎥ , [B ] = ⎢ ⎥
⎢⎣ 7 4⎥⎦ ⎣− 1 5⎦
We know that the multiplication of a matrix is the multiplication of element row in one
matrix by element column of other matrix. If done manually as in the example of Section
4.1.2, code to get [C] is:
In this example, [A] has order 3 x 2 and [B] has order 2 x 2 to return [C] of order 3 x 2. Input
data of elemen [A] is made on a range of cells (6,2) to cell (8,3), while element [B] on a cell
range (6.5) to cell (7.6). To run the program, click the command button that has been made
For a large‐sized matrix, the given MMULT1 example is inefficient in term of wasting time
and coding to write code for all matrix (row) operations one by one. Instead, use ForNext
looping for reading input data, to process and print the results. This way saves a lot of code
writing.
The code program of above matrix multiplication can be modified by giving the row and
column indices (i, j and k) to [A], [B] and [C], which is done in three looping below:
In a looping above, m and n represents number of rows and columns of [A], respectively,
while n and p represents number of rows and columns of [B]. In the following example, we
will use the modified program code to multiply a 6x6 matrix by a 6x3 matrix. The program
is named MMULT2.
Matrix multiplication can also be done in a worksheet using Excel built‐in function MMULT
(array1, array2). For MMULT2 procedure example, a formula can be written as follows:
= MMULT(B6:G11,J6:L11).
To print the result use INDEX function or you can enter the formula above as an array
formula. See about array formula in Chapter 1.5.
Matrix Inversion
In finding an inverse of matrix, Gauss‐Jordan method is among the most popular method to
be used and programmed, with a process that has been described in the previous section.
The steps are an effort to turn a matrix to be searched its inverse (e.g. [A]) becomes an
identity matrix [I] and at the same time, [I] to [A] ‐1. That is done by elementary row
operation as ever shown in the previous example.
In the program, this can be done by taking one matrix e.g. [C], such that at the end of the
process [C] turns into [A] ‐1. In the beginning is to divide the first row by element a11 of
[A], in an effort to turn a11 = 1 so that c11 = 1 / a11 and this is analogous to that performed
in [I]. If [A] is n x n matrix, then in the first step the first column of [C] is analogous of that
performed in [I], while the second column to column n is analogous of that performed in
[A]. At the end of step 1, the value of [C] of order 3x3 can be written as follows:
⎡ 1 a12 a13 ⎤
⎢ ⎥
⎢ a11 a11 a11 ⎥
a a12 a13
[C ] = ⎢⎢ − 21 a 22 + . − a 21 a 23 + . − a 21 ⎥⎥
a a11 a11
⎢ 11 ⎥
⎢ − a31 a
a32 + 12 . − a31 a 33 +
a13
− a 31 ⎥
⎢⎣ a11 a11 a11 ⎥⎦
In the second step, the first and second column of [C] is analogous of that performed in [I],
while the third column to column n is analogous of that performed in [A], etc.
Program for finding inverse is created in VBA and provided here. It notes that matrix
inversion requires square size (say, m x m) matrix and the determinant of matrix must not
be zero. For the purpose to create worksheet form, the maximum element of matrix is
limited to m = 6, but it can certainly be made more than 6.
Example 2
⎡2 3 ⎤
[ A] = ⎢ ⎥
⎣ 3 − 2⎦
Example 3
⎡1 3 3 ⎤
[ A] = ⎢⎢1 4 3 ⎥⎥
⎢⎣1 3 4⎥⎦
VBA code:
Furthermore, to simplify the calculation we can partition element of the stiffness matrix at
the nodes that are free to displace (free nodes) and fixed (zero displacement at the
supports). If Xb represents displacements vector at the support, Xf represents
displacements vector at free nodes, Pf and Pb are the external forces vector which
correspond to their displacements, Equation 4.7 can be written as follows:
⎧ Pf ⎫ ⎡ Kff Kfb ⎤ ⎧⎪ X f ⎫⎪
⎨ ⎬=⎢ ⎥⎨ ⎬ (4.8)
⎩ Pb ⎭ ⎣ K bf K bb ⎦ ⎪⎩ X b ⎪⎭
And
The displacements vector at free nodes is then obtained using Equation 4.9 that becomes
{Xf} = [Kff]‐1{Pf}. If {Xf} is known then the internal forces of the element can be obtained. In
this relation, the internal force of element i is expressed in local coordinate and obtained by
the following equation:
where,
{Po} fixed‐end forces: reactions at end of element i due to external load directly
acting on element i
To find the support reactions, it can be directly obtained in the global coordinate of the
structure using Equation 4.10 becomes:
or,
Some equations are made in order to find force ‐ displacement relationship at the nodes,
and begins by writing the relationship between external forces at the nodes {P} and
internal forces of element {F} in principle of equilibrium.
The relationship between node displacements {X} and deformations of element {d}:
From elastic behavior of element, the relation between {F} and {d}:
Equations 4.16, 4.17 and 4.18 are the fundamental equations in the analysis using finite
element method (J.E. Bowles, 1982).
Many problems in science and technology involve the use of integral and differential
equations. If the mathematical equation model is quite simple, then it can be solved by
means of analytical method. However, many of those equations are difficult or may be
impossible to be solved analytically. Instead, it must be solved numerically or using
numerical methods.
The result of the numerical method is an approach to its exact value by means of
analytically. Thus, it is just an approximate calculation with estimated accuracy. Numerical
methods will provide many benefits if done by a computer.
has a broad sense as the area bounded by the curve y = f(x) and the X‐axis, the between x =
a and x = b.
a
(5.1)
a
Numerical integration to calculate area under the curve uses the concept of approach
whereby the area is divided into smaller pieces of area in such that, if combined the total
area of the pieces approaching the exact result. In this example we will use trapezoidal
method where the area under the curve is divided into small pieces of area with sides f(xn)
and f(xn‐1) that resembles a trapezoid as shown in Figure 5.1.
Trapezoids are having the same width for Δx, if there are n intervals (or n trapezoids) from
a to b, then the Δx = (b ‐ a) / n as shown Figure 5.1. Figure 5.2 shows the comparison
between the area obtained from the total area of the trapezoids and the exact results
obtained using Equation 5.1. The formula to find total area (L) is given by:
Δx
Ltotal = (( f ( xo ) + f ( x1 )) + ( f ( x1 ) + f ( x 2 )) + ... + ( f ( xn −1 ) + f ( x n )) (5.2)
2
Δx
= ( f (xo ) + 2 f (x1 ) + 2 f (x 2 ) + 2 f ( x 3 )) + ... + 2 f ( xn −1 ) + f ( x n )) (5.3)
2
Figure 5.2: The comparison of area resulted from trapezoids (left) and the exact one
(right)
Furthermore, to complement this discussion we will examine the given example below via
VBA.
Example
Find the area bounded by the parabola y = 4x ‐ x 2, the X‐axis, from x = a and x = b. Find also
the exact value.
Solution
VBA code
In the worksheet, the area calculated using trapezoidal method and its exact value is
respectively expressed as A_num and A_exact. This experiment shows that the smaller
width of trapezoids taken with n = 100, the closer A_num to A_exact, compared with n = 10.
However, the more thorough results requires a longer calculation process and it is certainly
suitable done with the help of computer.
The other methods for approaching area, for examples are by the Simpson method and
Gauss quadrature.
Examples:
dv d2x
F = m.a = m =m 2 (5.4)
dt dt
∂u ∂ 2u
= cV (5.6)
∂t ∂z 2
Description:
• Equation 5.4 is Newton's second law of motion that states force (F) acting on an
object = mass (m) of the object multiplied by its acceleration (a) where, acceleration
(a) is the first derivative of velocity (v) with respect to time (t) and the second
derivative of position (x).
• Equation 5.5 shows the relationships between bending moment (M) at any point on
the X‐axis and transverse deflection (v) of the beam. EI is flexural rigidity of the
beam.
• Equation 5.6 is the partial differential equation of one‐dimensional consolidation,
where u, t, z are respectively, excess pore‐water pressure, time and the depth of clay
layer. Cv is a coefficient of consolidation where the value is assumed to be constant.
Δx Δx 2 Δx 3 Δx n
f ( xi +1 ) = f ( xi ) + f ' ( xi ) + f '' ( x i ) + f ''' ( x i ) + ... f n ( xi ) + Rn (5.7)
1! 2! 3! n!
where,
Taylor series will give an estimation of the function correctly if all derivatives in the series
are taken into account, where n = infinite number. However, in practice, the use of Taylor
series is done by simply taking the first few terms of the series.
Equation 5.7 of the Taylor series can be derived into the discrete form (finite) as shown in
Figure 5.4. The estimation of first derivative of a function f'(x) is approached through
several slope of the line through the value f(x) at x = x i‐1 (point A), x = xi (point B) and x =
xi+1 (point C) as in Figure 5.4. From Equation 5.7, with respect to first derivative:
or,
∂f f ( xi +1 ) − f ( x i )
= f ' ( xi ) = − Rn (5.8)
∂x Δx
∂f f ( xi ) − f ( x i −1 )
= f ' ( xi ) = + Rn (5.9)
∂x Δx
∂f f ( xi +1 ) − f ( x i −1 )
= f ' ( xi ) = + Rn (5.10)
∂x 2Δx
If the function contains two independent variables such as f(x, y), then the derivatives in
the Taylor series will have the following form:
∂f Δx ∂f Δy ∂ 2 f Δx 2 ∂ 2 f Δy 2 ∂ n f Δy n
f ( xi +1 , y j +1 ) = f ( x1 , yi ) + + + 2 + 2 + ... n (5.11)
∂x 1! ∂y 1! ∂x 2! ∂y 2! ∂y n!
∂f f − f i, j
≈ i +1, j
∂x Δx
∂f f − f i −1 , j
≈ i +1 , j
∂x 2Δx
∂f f − f i , j −1
≈ i, j+1
∂y 2Δy
∂2 f f − 2 f i , j + f i +1 , j
≈ i −1 , j
∂x 2 Δx 2
∂2 f f − 2 f i , j + f i , j +1
≈ i , j −1
∂y 2
Δy 2
Subscript i, j on the function f(i, j) is a simplification of f(xi, yj) form. A grid points of
function values in the xy coordinate system is shown in Figure 5.5, it is used to estimate
derivative of partial differential with respect to x and y.
In Chapter 10, we will build a program using finite difference method for the one‐
dimensional consolidation based on Equation 5.6. In the process, it is necessary to put a
multiplier into input data to divide interval of the independent variables (e.g. Δx) to be
smaller so that the solution is expected close to exact result. Program is created in VBA and
of course, with the advantages of making chart automation to present the result.
www.engbookspdf.com
CHAPTER 6
PROGRAM FOR 2D FRAME STRUCTURE
ANALYSIS
The matrix program as described in Chapter 4 is now implemented for analysis of structure
in this chapter and the next few chapters. It is expected that these series of references for
Excel‐VBA programming will be complementary, as basic knowledge for readers to make
an application program.
Please differentiate between the purpose of programming in Excel and the aim to build an
executable program (using Visual Basic or C++ programming language). Using Excel means
the program as a whole to be convenient and practical for it is created case by case. Each
case is packed in such a way to utilize the facilities on the spreadsheet and then presented
as in creating a technical report. This is consistent with the nature of working with Excel.
www.engbookspdf.com
All members of the frame are made of the same linear elastic material with modulus of
elasticity, E = 2.1 x 106 ton/m2. Dimension of member AB = BC = CD = 30 cm.
V at node C = 1 ton
Sign convention represents the direction of the forces ‐ displacements with reference to
either the global coordinate or the local coordinate. It is set as follows: axial and shear
forces follow the right‐hand rule and the moments follow the right‐hand screw rule, or in
the easy way it is evident from Figure 6.1, i.e. positive when in the direction of the positive
axis.
Figure 6.1: Force and displacement components at nodes in global coordinate system
Figure 6.3: Members force and displacement components that conform to global
coordinate system
α CD
⎡ cos α sin α 0 0 0 0⎤
⎢− sin α cosα 0 0 0 0⎥⎥
⎢
⎢ 0 0 1 0 0 0⎥
⎢ ⎥
[T]i= ⎢ 0 0 0 cos α sin α 0⎥ (6.2)
⎢ 0 0 0 − sin α cos α 0⎥
⎢ ⎥
⎣⎢ 0 0 0 0 0 1 ⎦⎥
Member stiffness matrix is then superposed with other member, which altogether
form global stiffness matrix or called [K] structure. This process is written:
{X}i = [T]i{Xf}
After the displacements of member {X}i are obtained, then internal forces on each
member can be found using Equation 4:11:
From above sequence of process then we can create a simple program for frame structure
analysis named FRAME2D.
Programming:
For instance is how to assembly [K] structure. For that purpose, it requires to manipulate
program steps, so that [K] members can be placed on their position in [K] structure. The
idea is simply creating an integer variable, namely dindex, to equalize subscripts of [K]
member. Dindex reads index (numbering) of members joint displacements in the global
coordinate system and uses the subscripts to store [K] members in [K] structure and do the
superposition at once.
• Idm variable is the same displacement index as stated by dindex variable, but
declared at a different level. Idm is at public‐level, while dindex is at procedure‐
level. For more clearly understand how these variables are proceeded you can see in
FRAME2D code provided in the Attachment.
• The above code is for completion of the description (6.4).
The other thing is to partition (separation) of the structure stiffness matrix to form [Kff]
and [Kbf] as written in Equation 4.8. To do this, it uses two integer variables namely Ifr to
form [Kff] and Ifx to form [Kbf].
Notes:
• NS = no. of supports
• Variable Idj = Ifr, Irj = Ifx, but they are declared at different level which is at public and
procedure level, respectively. See FRAME2D code provided in the Attachment.
Member AB
[K]
[T]
[K]s
[K]
[T]
[K]s
1 2 3 4 5 6 7 8 9 10 11 12
1 265.78 0.00 ‐531.56 ‐265.78 0.00 ‐531.56 0.00 0.00 0.00 0.00 0.00 0.00
2 0.00 47250.00 0.00 0.00 ‐47250.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3 ‐531.56 0.00 1417.50 531.56 0.00 708.75 0.00 0.00 0.00 0.00 0.00 0.00
5 0.00 ‐47250.00 0.00 0.00 47790.15 1080.29 0.00 ‐540.15 1080.29 0.00 0.00 0.00
6 ‐531.56 0.00 708.75 531.56 1080.29 4298.28 0.00 ‐1080.29 1440.39 0.00 0.00 0.00
7 0.00 0.00 0.00 ‐59850.00 0.00 0.00 60115.78 0.00 531.56 ‐265.78 0.00 531.56
8 0.00 0.00 0.00 0.00 ‐540.15 ‐1080.29 0.00 47790.15 ‐1080.29 0.00 ‐47250.00 0.00
9 0.00 0.00 0.00 0.00 1080.29 1440.39 531.56 ‐1080.29 4298.28 ‐531.56 0.00 708.75
10 0.00 0.00 0.00 0.00 0.00 0.00 ‐265.78 0.00 ‐531.56 265.78 0.00 ‐531.56
‐
11 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 47250.00 0.00
47250.00
154
12 0.00 0.00 0.00 0.00 0.00 0.00 531.56 0.00 708.75 ‐531.56 0.00 1417.50
Partition at free nodes [Kff]
4 5 6 7 8 9
4 60115.78 0.00 531.56 ‐59850.00 0.00 0.00
5 0.00 47790.15 1080.29 0.00 ‐540.15 1080.29
6 531.56 1080.29 4298.28 0.00 ‐1080.29 1440.39
7 ‐59850.00 0.00 0.00 60115.78 0.00 531.56
8 0.00 ‐540.15 ‐1080.29 0.00 47790.15 ‐1080.29
9 0.00 1080.29 1440.39 531.56 ‐1080.29 4298.28
4 5 6 7 8 9
1 ‐265.78 0.00 ‐531.56 0.00 0.00 0.00
2 0.00 ‐47250.00 0.00 0.00 0.00 0.00
3 531.56 0.00 708.75 0.00 0.00 0.00
10 0.00 0.00 0.00 ‐265.78 0.00 ‐531.56
11 0.00 0.00 0.00 0.00 ‐47250.00 0.00
12 0.00 0.00 0.00 531.56 0.00 708.75
⎧ 0.00000 ⎫
⎪ 0.00000 ⎪
⎪ ⎪
⎪ 0.00000 ⎪
⎪ ⎪
⎪ 0.00117 ⎪
⎪− 0.00002⎪
⎪ ⎪
⎪− 0.00039⎪
⎨ ⎬
⎪ 0.00117 ⎪
Joint displacements at free nodes : {Xf} =
⎪− 0.00005⎪
⎪ ⎪
⎪ 0.00017 ⎪
⎪ 0.00000 ⎪
⎪ ⎪
⎪ 0.00000 ⎪
⎪ 0.00000 ⎪
⎩ ⎭
After getting {Xf} then member deformations are calculated by using relationship:
The result of the analysis is presented in FRAME2D input‐output form as shown in Figure
6.4 and 6.5 below:
The displayed geometry in chart window (only available in Excel 2003) from re‐inputted
data is shown below:
The results shown in Figure 6.7 and 6.8 are much better than in Figure 6.5 and 6.6. Thus, it
is convenient to divide into smaller members and for this example at least 4 smaller
members with the same length for each member. Avoid odd divisors (e.g. 5, 7, 9 etc.) so that
the results in the middle of span can be exposed.
‐ Shear force (V) is given a positive sign if rotates the member clockwise and is given
a negative sign if rotates the member counter‐clockwise.
‐ Axial force (N) is given a positive sign if pulls the member apart, and is given a
negative sign if pushes the member.
This convention is adopted in order to have same interpretation on the chart depiction of
the application programs in the next few chapters, thus it is more easily interpreted and
also design‐oriented. The program automatically differentiates the moments and forces
that occur in members section, which is blue line inside the curve for the positive
direction and red for the negative direction. The example below shows the coloring for
bending moment result:
The beam can be seen to have three main members that are, roll‐load segment, load‐roll
segment, roll‐fixed node, have lengths 3, 3 and 5 meters, respectively. In practice however
it needs to divide the beam into smaller members for exposing the result more accurately.
FRAME2D is then inputted from which each of main members is divided into 4 equal parts.
So, there are 12 members and 13 joints. When the program has run, the charts will be
shown as below.
Member of plane truss is analyzed with consideration that carries only axial force, thus,
there are two associated displacement components at both ends with respect to axial force.
Truss member is generally made of steel or aluminum connected one to another as pin
connection.
⎡ AE AE ⎤
⎢ L 0 − 0⎥
L
⎢ 0 0 0 0⎥
⎢
[K]i = ⎢ AE AE ⎥
− 0 0⎥
⎢ L L ⎥
⎢⎣ 0 0 0 0⎥⎦
⎡ cos α sin α 0 0 ⎤
⎢− sin α cos α 0 0 ⎥⎥
⎢
[T]i = ⎢ 0 0 cos α sin α ⎥
⎢ ⎥
⎣ 0 0 − sin α cos α ⎦
Given a truss structure is shown in Figure 7.1, includes numbering system in Figure 7.2 to
7.4. Each of member are made of the same linear elastic material, with E = 2,100,000 kg
/cm2 and cross‐sectional area A = 68.4 cm2.
Truss as a whole has only two degrees of freedom (DOF) which is at vector components 3
and 4, while both supports are pinned‐pinned thus will have no any translation.
Figure 7.2: Force and displacement components at nodes in global coordinate system
Figure 7.4: Members force and displacement components that conform to global
coordinate system
The first step is to build member stiffness matrix with reference to either local or global
coordinates. In the program, it is done within one looping through the member number,
and made in a separate procedure in Module 2.
Program code:
• The above code is about to build the members global stiffness matrix as shown in
Equation 7.1, and then store them to form [K] structure and do the superposition at
once.
• Each member matrix (variable M) has three indexes in it; the first and second states
rows and columns subscripts of the matrix, respectively, while the third index states
matrix of member i.
The program for truss analysis is modified from FRAME2D and named TRUSS2D. Below are
the results of each step of the analysis.
[K]AB
[K]AC
Transformation Matrix
[T]AB
[T]BC
[K]s = [T]iT[K]i[T]i
[K]s AB
[K]s AC
1 2 3 4 5 6
1 34282.08 13789.44 ‐10342.08 ‐13789.44 ‐23940.00 0.00
2 13789.44 18385.92 ‐13789.44 ‐18385.92 0.00 0.00
3 ‐10342.08 ‐13789.44 20684.16 0.00 ‐10342.08 13789.44
4 ‐13789.44 ‐18385.92 0.00 36771.84 13789.44 ‐18385.92
5 ‐23940.00 0.00 ‐10342.08 13789.44 34282.08 ‐13789.44
6 0.00 0.00 13789.44 ‐18385.92 ‐13789.44 18385.92
The next step is to partition [K] structure at free nodes and supports. Manipulation on
program steps to establish [K ff] has been discussed earlier in FRAME2D example.
{Pf} = [Kff]{Xf}
⎧ 0.00048 ⎫
{Xf} = ⎨ ⎬
⎩− 0.00054⎭
After displacements of free nodes are known, the internal forces of each member can be
determined using equation:
In this example, no external load directly acting on each member thus {Po} = 0. The
equation to determine the internal forces of member becomes:
{P}i = [K]i([T]i{Xf})
There is no external load directly acting on supports thus {Pb} = 0. The equation to
determine the support reaction becomes:
{Rb} = [Kbf]{Xf}
In this stage, we have to establish [K bf] first. It uses the same way as to establish [Kff], which
to partition using integer variables. The completed code is similar to that in FRAME2D:
⎡ 1,3 1,4 ⎤
⎢ 2,3 2,4⎥⎥
⎢
[Kbf] = ⎢ 5,3 5,4 ⎥
⎢ ⎥
⎣ 6,3 6,4⎦
⎡− 10342.08 − 13789.44⎤
⎢− 13789.44 − 18385.92⎥
⎢ ⎥
[Kbf] = ⎢− 10342.08 13789.44 ⎥
⎢ ⎥
⎣ 13789.44 − 18385.92⎦
⎧ 2.500 ⎫
⎪ 3.333 ⎪
⎪ ⎪
{Rb} = ⎨− 12.500⎬ ton
⎪ ⎪
⎪⎩ 16 .667 ⎪⎭
The results of the internal forces of members and supports reactions are then plotted on
the truss chart as shown in Figure 7.5. Negative sign is used to indicate compression state
along the member, and positive sign for tension state.
The input and output form of TRUSS2D for given truss example is as follows:
Note:
• Color coding for axial forces is the same as used in FRAME2D. Lines ‐ which are lines
that perpendicular to long section ‐ of member 1 and 3 are red; it means negative
axial forces occurred on members (compression).
- Vertical load = 40 tons and horizontal load = 2 tons, at the joint as shown in Figure
7.8.
- Selfweight of all the members.
The data of geometry, material and loading are then inputted in the input‐output form of
TRUSS2D as shown in Figure 7.9. Numbering system of a given truss bridge can be seen in
the chart window (only available in Excel 2003) or in the worksheet shown as below:
For a kind of truss, for instance, a truss tower that requires extended upward lengthwise
chart, you can change a chart aspect ratio by resizing it. To do this, take the following steps:
• Click mouse on chart > move pointer on chart border > drag the sizing handles that
located in the border to the size, e.g. like a chart size as shown below.
• The other way is to click mouse on chart > Format tab > in the Size group > enter
the value in Shape Height and Shape Width.
• If font sizes change during chart resizing, click on the chart or at any text and then
set the font size through Font Size setting on the Ribbon.
Beam loaded on elastic foundation (BOF) is a theory that is often used in force ‐
displacement prediction for the structural analysis that interacts directly with the ground.
Elastic foundation is an approach to soil behavior as a collection of linear elastic springs,
independent and one with another unrelated (Winkler soil). This theory is more solved by
numerical methods, especially by finite element method (FEM).
The fundamental of FEM for BOF used herein are Equation 4.13 until 4.18, and the
notations are used to express the relationship of external force‐displacement components
to those at nodes and internal force‐deformation components on elements of finite element
in Figure 8.1. Elastic foundation is represented by a series of spring constant at element
nodes.
The relationship between load {P} and internal forces {F} is expressed as {P} = [A] {F},
where:
The relationship between internal forces {F} and element deformations {d} is expressed as
{F} = [S] {d}, and from elastic behaviour of the beam we may write:
Notes:
Foundation displacements {X} and internal forces {F} can be obtained using Equation 4.16
and 4.18:
⎧ X1 ⎫ ⎧ P1 ⎫ M
⎪X ⎪ ⎪P ⎪
⎪ 2⎪
{
⎨ ⎬ = [ A][S][A]
X
T
}−1 ⎪ 2⎪ V
⎨ ⎬
⎪ 3⎪ ⎪ P3 ⎪ M
⎪⎩ X 4 ⎪⎭ ⎪⎩ P4 ⎪⎭ V
⎧ F1 ⎫ M ⎧ X1 ⎫
⎪F ⎪ M ⎪ ⎪
⎪ 2⎪ T ⎪X 2 ⎪
⎨ ⎬ = [S][A] ⎨ ⎬
⎪ F3 ⎪ V ⎪X3⎪
⎪⎩ F4 ⎪⎭ V ⎪⎩ X 4 ⎪⎭
Notes:
The advantage of FEM over classical solution of BOF is that properties from element and
soils that are not constant such as weights, dimensions, flexural rigidities of beam and soil
Ks along the beam can be easily incorporated into the calculation.
Given example:
Ks = 1800 ton/m3
Vertical load = 20 tons and moment load = 4 ton.m, acting in the column axis, right in the
center of the footing.
4 ton.m
0.85 m 0.85 m
0.3 m
2.0 m
The input and output data of the given example is presented in the input‐output form of
BOF in Figure 8.3. The footing structure consists of 10 members, with a continuous
numbering system as shown in the following worksheet chart:
• For a case of retaining wall or pile foundation where the soil spring is modeled on
both sides of the structure, the soil spring would always work where the one will be
active and the other will be non‐active. Thus, it is convenient to give an option to
select limits on nodes where iteration will be performed. The intended limits can be
found in Chapter 8, where BOF is modified for vertical structures.
• Sign convention of moments and shear forces for graphic despiction is to follow the
sign convention described in Chapter 6.2, which is based on the changes of structure
shape after loading. Also, blue line in the curve is for positive direction and red line
for a negative direction.
Here, no soil property is involved so that Ks = 0. There are 3 supports of the beam, which is
fixed at point A (R = 1, T = 1), pinned at point B (R = 0, T = 1) and fixed at point C (R = 1, T =
1).
Beam:
Length = 18 m
Width = 2 m
Height = 0.5 m
Load:
Theory of beam on elastic foundation can also be applied for the analysis of structures
subjected to lateral loads. Here, BOF program was slightly modified in which the
orientation of the beam is now perpendicular to X‐axis, and the external forces ‐
displacement can be set whether lead to positive or negative axis. Load on nodes profile
also to be displayed for a quick verification on inputted pressure magnitudes at both
elements ends. The program for the laterally loaded structure is named XLAT.
Find:
- Magnitude of displacements, distribution of moments and shear forces along the wall for
design purpose.
- Forces and stress acting on anchor for design purpose.
After the FE model (Figure 9.1) is established, now is to find lateral pressure behind the
wall acting from ground surface to the dredge line using active pressure coefficient from
Coulomb or Rankine. You can either input the lateral pressure to 1 node below the dredge
line.
Slight modifications were made in calculating fixed‐end forces of element to take pressure
profile that increases linearly with depth (triangular distribution) into account. See the
description on this picture:
• The above code is the same as used in the previous programs to find the equivalent
load on nodes.
• Variable Idm states displacement index of elements ends. It has been described
earlier in the previous chapters.
To generalize program where variation in the physical characteristics of the structure can
be incorporated into calculation, thus the input of height of beam, t, in BOF is replaced by
moment of inertia, I, in XLAT:
The following chart window (Excel 2003) will appear by clicking on Plot Geometry button.
It shows finite element geometry and pressure profile that have been inputted into the
program refer to Figure 9.1.
ks = As + Bs.Zn. ton/m3,
where,
As = 40(c.Nc+0.5γ.B.Nγ)
Bs = 40(γ.Nq)
Anchor rods are made of steel, with the specification shown in Figure 9.1. The value of rod
anchor spring per meter width of the wall is obtained by the formula:
www.engbookspdf.com
AE
K =
sL
12.6(2.0 × 107 )
= = 1400 ton/m.
3(6)104
Notes:
• Unit used in this example is ton ‐ meter to equalize the values of calculation
parameters used in this example.
• In the form, there is an input for joint excavation (point O) that is J excavation, as
input, in which iterative process done from the top of the wall up to this point. Note
that, iteration is not done below point O because the presence of soil spring on both
sides of the wall. Definition of the iteration and its purpose are described in Chapter
8.
www.engbookspdf.com
• To perform iterative process (to check the soil spring direction) up to joint n, enter J
excavation = n + 1. In relation with this, iteration is not performed if J excavation =
1.
• To design the anchor rod, please check the reaction force in anchor and calculated
the stress with steps below:
Check:
Paxial 14 .557
fs = = = 1 .155 ton/cm 2
A 12 .6
So, the specification chosen for the anchor rod must be adequate to resist the above
force and stress.
The result of moments and shear forces are then made into diagram shown in Figure 9.3.
For the wall design purposes, it can be taken maximum positive bending moment (blue
line) working below anchorage, while negative moments (red line) is located around the
anchor and around the wall tip.
www.engbookspdf.com
Figure 9.3: XLAT output chart
9.2 APPLICATION
Given pile foundation example with a diameter of 0.406 m embedded in sand layer to a
depth of 16 meters. Pile and soil data are as shown in Figure 9.4. Pile head is assumed as
fixed connection against rotation but free to translate.
Find:
- Maximum load applied on the pile head for its limited magnitude of displacement of the
pile head.
www.engbookspdf.com
Figure 9.4: Pile foundation example
XLAT results of this example are shown in charts in Figure 9.5, where horizontal load, H, is
adopted = 100 kPa. Displacement that occurs in the pile head is 0.0054 m (at joint 1) as
shown in the Figure. From load and displacement linear relationship, any increase of load
of 1 kPa will produce pile head displacement of 0.054 mm.
Thus, for a case where pile head displacement is limited to 5 mm, the allowed maximum
load is then = 5/0.054 kPa = 92.6 kPa.
www.engbookspdf.com
Figure 9.5: XLAT chart for pile foundation example
www.engbookspdf.com
CHAPTER 10
ONE DIMENSIONAL CONSOLIDATION
In this chapter we will apply numerical solution using finite difference (FD) method for
Terzaghi’s theory of one dimensional consolidation. This method is based on a grid of time,
t, versus depth, h, as shown in Figure 10.1. The depth of soil layer is divided into m equal
parts of thickness z, while the period of time is divided to n equal parts of interval t.
∂u ∂ 2u
= cv (10.1)
∂t ∂z 2
Finite difference forms of Taylor series for the first and second order derivatives of
functions have been shown in Chapter 5, and for both sides of Equation 10.1 can be
written:
∂u u − u i, j
= i +1, j
∂t Δt
∂ 2u u − 2 u i , j + u i +1, j
= i −1 , j
∂z 2
Δz 2
Substituting these values into Equation 10.1 obtains finite difference approach to one‐
dimensional consolidation equation as follows:
where,
cv Δt
β=
(Δz )2
cv coefficient of consolidation
www.engbookspdf.com
cv (nΔt )
TV =
(½mΔz )2 = 4βn/m (10.3)
2
Tv = βn/m2 (10.4)
∂u u − u i +1, j
= 0 , or in FD form: i −1, j =0
∂z 2 Δz
The degree of consolidation (U) at time t can then be obtained by finding area under initial
isochrone (from initial excess pore pressure distribution) and area under isochrone at time
t, given by the following equations:
U =1−
∫ u dz
0
d (10.6)
∫ u dz
0
i
open layer:
2d
U =1−
∫ u dz
0
2d (10.7)
∫ u dz
0
i
where d is the thickness of clay layer. Isochrone is a curve of excess pore water pressure,
ue plotted against depth for certain t as shown in Figure 10.2. The blue line represents a
variation of the initial u while the magenta line represents the pressure at time t.
Both Equation 10.2 and Equation 10.5 can be easily programmed, because the analysis is
based on an equilaterally grid. This looks like to build an array of function values (u) with
size of, for example, m x n (see Figure 10.1). The solution is simply taking a looping through
grid points in an array; thus, to find of excess pore water pressure at a specified period of
time (n) can be determined by giving specified value in a looping.
www.engbookspdf.com
If m and n are referred to FD grid points as shown in Figure 10.1, thus, the code for half‐
closed layer can be written:
h
t
Δt =
n
h
Δz =
m
u i‐1, j
u i, j u i, j+1
u i+1, j
www.engbookspdf.com
Figure 10.2: Isochrone example at specified time
In practice, the use of Taylor series adopts the first few terms omitting the higher order
derivatives and the error due to truncate the series can be reduced to minimum when β =
1/6. Seeing this condition, n and m can be then directly determined to satisfy a fixed β = 1/6
for both layer conditions. If m is an input data, then Equation 10.3 and 10.4 can be re‐
written to determine n as follows:
www.engbookspdf.com
In the process of finding U, the input data of depth and the initial u are automatically re‐
inputted by the program where is each multiplied by 10 (default by the Author) or m = 10 x
im in the above code. For doing so, the interpolation technique is done to get the adjacent
values. The discussion of numerical methods in Chapter 5 demonstrates that dividing
interval of the independent variables into smaller intervals provides the result closer to the
exact value, and it is similar to what we will be doing here in the process of finding U
(numerical integration) as well as final u (numerical differential).
- Re‐inputted with a divisor 10 and perform interpolation to get adjacent values using
rsdZ and RSIP variables:
Initial data:
www.engbookspdf.com
Depth Initial
(H/m) Pressure
Re‐inputted:
Depth Initial
(H/m) Pressure
www.engbookspdf.com
Figure 10.2 shows example of open layer isochrone at time t with initial u increases linearly
with depth. The area under isochrone curve between y = 0 and y = 8 is then sought. For
doing so, FDC uses trapezoidal method (in h/m unit) in which the total area is cumulative
sum of h/m segment areas done in a looping over values of re‐input dZ and IP. A detailed
code can be found in FDC program in the Attachment.
10.1 APPLICATION 1
The profile of excess pore water pressure (u) over the depth in saturated clay layer from
impact load is equal to the vertical stress distribution below foundation as in Problem 4 of
Chapter 3, as shown in table below:
www.engbookspdf.com
Depth (m) u (ton/m2)
0.0 10.00
0.5 9.76
1.0 8.63
1.5 7.01
2.0 5.49
2.5 4.28
3.0 3.36
3.5 2.68
4.0 2.17
4.5 1.79
5.0 1.49
5.5 1.26
6.0 1.08
Suppose the clay layer is half‐closed layer, where water flows across the upper limit. Given
cv = 7.19 m2/year and the thickness of layer is 6 m. Find the distribution of u and average
degree of consolidation (U) at 6 months.
Answer
www.engbookspdf.com
4.00 2.17 2.51
4.50 1.79 2.51
5.00 1.49 2.50
5.50 1.26 2.48
6.00 1.08 2.47
10.2 APPLICATION 2
From field piezometers measurement on the clay layer beneath embankment, the
distribution of excess pore water pressure, u (after subtracted by its theoretical pressure)
is shown in the table below:
Answer
www.engbookspdf.com
Notes:
• The advantage of finite difference method is that any pattern of excess pore water
pressure can be incorporated into the calculation. The input data can be based on
the initial field condition or load that works gradually, for examples, in the
completion of the consolidation problem below dam or embankment of soil.
• The purpose of FDC programming for one‐dimensional consolidation based on
numerical methods has actually been achieved, that is at the stage where the degree
of consolidation based on areas under isochrone at time t can be calculated.
However, if you wish to go further with the solution, a curve of t versus U as shown
below can also be presented. This curve is created automatically by the program to
include 10 different t values into a looping, starts with t = 0.1 (years), then t = 0.5, 1,
2, and so on, and plotted on a semi‐log chart.
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 209
www.engbookspdf.com
CHAPTER 11
AUTOCAD SCRIPT FILE
To graphically depict outputs of a program, alternatively, you can plot the outputs in
AutoCAD software instead of using Excel chart. Here, you can work further with charts
drawing with either a 2D or 3D model. The main advantage of AutoCAD is because this
software is specifically built for composing drawings.
Script file meant here is a text file that contains a sequence of commands executed by
AutoCAD. The sequence of commands can be made on a worksheet or VBA to speed up and
simplify the process of creating drawings. The script file is made by a word processor such
as Win. Notepad or Microsoft Word in ASCII format and given with a .scr extension.
Example 1
Command: line
[Enter]
www.engbookspdf.com
From the above steps, it can therefore be made the following text (script) replaces what
was done above:
Line
0,0
1,1
2,3
Open Notepad program, type the script above, and do not forget to type 2 blank spaces
after the coordinates of the last point to end the Line command. Afterward, save it with .scr
extension, for example named Line.scr. Now, open your AutoCAD, type scr at the command
prompt to display the Select Script File dialog box as below:
Select Line.scr file at the location you have placed before and click Open, then AutoCAD
will execute all commands in script file. The result is shown as below:
www.engbookspdf.com
Notes:
• AutoCAD commands consist of prompt entries that include some options that must
be entered in by the user. These options can also be 1). A command related to the
main command and, 2). Attributes to an object, for example, properties of a line, a
circle or a rectangle.
• The best way to understand a sequence of a command (e.g. Line) is firstly to trying
out it in AutoCAD, then noted down all entries, including the requested options
associated with the main command. This becomes the basis used for preparing the
script later.
Command
Entry (Coordinate)
www.engbookspdf.com
O
Options:
• Pressing Entter at the last line is to end the commmand, so lines are drrawn up to point
p
co
oordinates of the prev vious line. Pressing u is to do Undo
U commmand; undo o the
previous linee segment, while c is to t do Close
e command;; close the last segmen nt by
co
onnecting itt to the firstt segment.
• Pressing Entter on keyb board is to ende a comm mand. In scriipt, it is don
ne by givingg one
blank space or
o create a blank
b line.
An Introd
duction to Excel
E for Civiil Engineerss 213
www.engbookspdf.com
• Some AutoCAD commands display a dialog box to enter its data. To display prompt
entries entered from keyboard (i.e. line by line through the command line), use a "‐"
before the command, such as: Style, Block or Layer.
• To join two or more data between cells on a worksheet, use hyphen "&" (in
quotation marks). It is the same as used in VBA to combine string and numerical
data.
• Script can be extended vertically or horizontally. In the extended horizontally script,
any data entered to next data must be separated by an empty space, including an
empty space of pressing Enter.
• Every time you run a script file, object snap must be inactive or in off mode, so that it
gives the actual results. Click the Osnap button to make the mode on or off.
• Below are options in Text command. The letter "j" stands for Justify command,
taken from the first letter.
www.engbookspdf.com
Examplee 1 shows how
h to draaw a line using script written manually. For line depiction
which co omprises many
m segmeents (tens or
o hundredss), the man nual methodd is rarely used.
u
Creatingg AutoCAD script
s on a worksheet
w iss a way to simplify and
d shorten the job of creating
AutoCAD D drawings, by relyingg on the Excel menu such as Co opy, Paste, and its bu uilt‐in
functions.
Examplee 2
=A6&","&
&B6&" "
1. Seelect a rangge C3 to C6
6, then Cop
py by click
king the Copy icon on
n the toolbaar or
prressing Ctrl+
+C.
2. Op
pen Notepad program, and then Pa
aste (Ctrl + V) the rangge.
An Introd
duction to Excel
E for Civiil Engineerss 215
www.engbookspdf.com
3. Saave the file with the .sccr extension
n, for examp
ple, Line1.sccr and placee it, for exam
mple,
in
n the directoory C.
4. Open AutoCA
O AD. Type script or sccr at the Co
ommand prrompt, or via Tools > Run
Sccript.
5. From Directo
ory C, selectt Line1.scr file,
f and click Open.
The resu
ult is appearred as below
w:
An Introd
duction to Excel
E for Civiil Engineerss 216
www.engbookspdf.com
Example 3
In a pile foundation work, the number of blows from driving hammer to penetrate piles is
noted until it reaches a depth of 28 meters. The obtained data is presented in Table 10.1.
www.engbookspdf.com
25 120 1358
26 152 1510
27 163 1673
28 212 1885
The data in Table 10.1 will be plotted in Cartesian coordinate system, where X‐coordinate
is the number of blows/meter and the Y‐coordinate is the penetration of the pile in meter.
Thus, it is required a graph form, where the data have to fit with the form created. The
penetration depth on the Y‐axis then is made to increase downward to state depth below
ground level, while the number of blows on the X‐axis increases to the right. It looks like
below.
The position of the form is placed at the bottom right of the origin P(0,0) in AutoCAD
drawing area. The scale made is:
With such scale, script for the data on the X‐axis should be divided by 10, while the data on
the Y‐axis is divided by ‐1 for it has a negative direction to the origin P(0,0). Script on the
worksheet is created as follows:
An Introd
duction to Excel
E for Civiil Engineerss 219
Example 4
In this example a script will be created, where the cumulative blows will also be plotted on
the graph. Thus, both of number of blows/meter and its accumulation are related to the
same Y‐axis (against pile penetration). But by seeing the cumulative blows has a range of
values up to thousands, then a scale of 1 unit = 100 blows is given so that the values can
conveniently fit in the graph form.
The result of cumulative blows is drawn using Pline with line thickness 0.1 unit. To create
an AutoCAD script, a new column is then created named Script 2 (next to Script), contains
formulas as shown below:
line 1.8,‐1
1.2,‐2
0.9,‐3
1.1,‐4
1.5,‐5
2.3,‐6
2.9,‐7
3,‐8
2.8,‐9
3.4,‐11
4,‐12
4.7,‐13
4.8,‐14
7.3,‐15
9,‐16
8.1,‐17
7.8,‐18
7.8,‐19
7.4,‐20
8.2,‐21
9.1,‐22
10.1,‐23
10.8,‐24
12,‐25
15.2,‐26
16.3,‐27
21.2,‐28
0.3,‐2
0.39,‐3
0.5,‐4
0.65,‐5
0.88,‐6
1.47,‐8
1.75,‐9
2.13,‐10
2.47,‐11
2.87,‐12
3.34,‐13
3.82,‐14
4.55,‐15
5.45,‐16
6.26,‐17
7.04,‐18
7.82,‐19
8.56,‐20
9.38,‐21
10.29,‐22
11.3,‐23
12.38,‐24
13.58,‐25
15.1,‐26
16.73,‐27
18.85,‐28
In this example, we will create a Layer in AutoCAD for each pile data. For doing so, now is
given 2 piles driving data, with location name PT‐1 and PT‐2, where each pile driving data
will be put into Layer by its location name. You, who are accustomed to using AutoCAD, of
course, will understand the importance of working with Layer.
To create a layer click the menus Layer > Make, and then define the layer name. If
combined with the driving data the script is as follows:
The letter "m" can stand for Make, thus shortened to:
To customize each layer, it will be given a unique color. For example, line in layer PT‐1 is
blue, while in PT‐2 is magenta. Now, the script becomes:
Script created above is only written in the first line (row). The next line will only be the
coordinates of points entered into a layer. It is shown as below:
1.2,‐2
0.9,‐3
1.1,‐4
1.5,‐5
2.3,‐6
2.9,‐7
3,‐8
3.8,‐10
3.4,‐11
4,‐12
4.7,‐13
4.8,‐14
7.3,‐15
9,‐16
8.1,‐17
7.8,‐18
7.8,‐19
7.4,‐20
8.2,‐21
9.1,‐22
10.1,‐23
10.8,‐24
12,‐25
15.2,‐26
16.3,‐27
21.2,‐28
0.3,‐2
0.39,‐3
0.5,‐4
0.65,‐5
1.17,‐7
1.47,‐8
1.75,‐9
2.13,‐10
2.47,‐11
2.87,‐12
3.34,‐13
3.82,‐14
4.55,‐15
5.45,‐16
6.26,‐17
7.04,‐18
7.82,‐19
8.56,‐20
9.38,‐21
10.29,‐22
11.3,‐23
12.38,‐24
13.58,‐25
15.1,‐26
16.73,‐27
18.85,‐28
0.8,‐2
1.3,‐4
1.2,‐5
1.6,‐6
2.5,‐7
2.9,‐8
3.2,‐9
3.6,‐10
3.9,‐11
4.1,‐12
4.9,‐13
4.7,‐14
5.7,‐15
7.4,‐16
5.9,‐17
5.6,‐18
5.7,‐19
5.9,‐20
6.4,‐21
6.9,‐22
7.1,‐23
7.7,‐24
8.4,‐25
9.3,‐26
10.3,‐27
12.5,‐29
0.24,‐2
0.3,‐3
0.43,‐4
0.55,‐5
0.71,‐6
0.96,‐7
1.25,‐8
1.57,‐9
1.93,‐10
2.32,‐11
2.73,‐12
3.22,‐13
3.69,‐14
4.26,‐15
5,‐16
5.59,‐17
6.15,‐18
6.72,‐19
7.31,‐20
7.95,‐21
8.64,‐22
9.35,‐23
10.96,‐25
11.89,‐26
12.92,‐27
14.06,‐28
15.31,‐29
The resu
ult in AutoCA
AD:
Layers created
c in AutoCAD
A cann be seen inn a combo‐b
box for layeers, at the toop‐middle of
o the
AutoCAD D drawing area.
a Each layer can be b displayed individuaally or together with other
o
layer. To
o disable or enable a lay
yer, click the mouse on
n the light icon in thee combo‐bo
ox.
Note:
• Discussion on
D o script of AutoCAD will
w take very long tim me for theree are such many
m
drawing feattures in Au
utoCAD. The detail is beyond thee scope of this book. It is
An Introd
duction to Excel
E for Civiil Engineerss 230
expected that readers can get the ideas from the all examples above. The next step
could be started by making some drawings as Block, which is then inserted using
the Insert command. You can insert block such as markers, a shading object, an
arrow or a form into a drawing area as many as required.
Description:
overwrite Optional. Boolean value, if TRUE indicates that file can be overwritten, or vice
versa. If omitted, the value is FALSE.
unicode Optional. Boolean value, indicates whether that file is created as Unicode file
(TRUE) or ASCII (FALSE). If omitted the value is FALSE.
Example
For accessing a file that has been created, use the Open command. The Open syntax itself
consists of several parts with the descriptions that are quite detailed, however it will not be
fully written here. For the purpose of creating a script file, use the following syntax:
Descriptions:
Example 1
With the above code, thus the testfile file contains text "write this test" can be accessed in
directory C. When opened with Notepad program, it looks like this:
Example 2
Now, we will use VBA for creating script. Example 2 of Section 11.1 will be adopted for this
example, and for your convenience is re‐shown below:
To run the
t above prrogram is by b clicking the
t comman
nd button named
n Prod
duce Script. The
resultingg script file contains the following text
An Introd
duction to Excel
E for Civiil Engineerss 233
To run the script above, firstly, open your AutoCAD, then type scr in command prompt or
via Tools > Run Script. From the Select Script File dialog box, select myScript.scr, then the
line segments with the coordinates as in the script file will be created in AutoCAD.
Example 3
The code:
The use of AutoCAD D script in ciivil engineeering field iss quite popu
ular becausee both Exce l and
AutoCADD could be found eassily (who does d not have?)
h and became a must stan ndard
softwarees for civil engineers. Example 4 to 7 in th he next pagges are AuttoCAD draw wings
produce d from scrript files coontained larrge amountt of data. They T are crreated for their
respectiv
ve interestss.
An Introd
duction to Excel
E for Civiil Engineerss 236
Figure 11.1: Profile of undrained shear strength of the soil versus depth from various
test results
Example 5:
Example 7
Figure 11.6: Diagram of bending momentZ and bending momentY are displayed
together
Gunthar Pangaribuan, Aplikasi Excel untuk Rekayasa Teknik Sipil, Penerbit PT. Elex Media
Komputindo, Jakarta, 2004.
Joseph E. Bowles, Foundation Analysis and Design, Third Edition, International Student
Edition, 1982.
R.F. Craig, Soil Mechanics, Fourth Edition, Spon Press, London, 1987.
Supartono, F.X Ir. dan Ir. Teddy Boen, Analisa Struktur dengan Metode Matrix, Penerbit
Universitas Indonesia, 1984.
William Weaver, Jr., James M. Gere, Matrix Analysis of Framed Structures, Second Edition,
Van Nostrand Reinhold Company, New York, 1980.
Wiryanto Dewobroto, Aplikasi Sain dan Teknik dengan Visual Basic 6.0, Penerbit PT. Elex
Media Komputindo, Jakarta, 2003.
Module1 (TRUSS2D)
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 294
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 295
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 296
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 297
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 298
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 299
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 300
An Introduction to Excel for Civil Engineers 301
An Introduction to Excel for Civil Engineers 302
Command Button (TRUSS2D)
Module1 (XLAT)
Module1 (FDC)
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 375
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 376
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 377
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 378
www.engbookspdf.com
An Introduction to Excel for Civil Engineers 379
www.engbookspdf.com
Command Button (FDC)
www.engbookspdf.com