Beruflich Dokumente
Kultur Dokumente
ENGINEERING
Course Title: COMPUTER METHODS IN CIVIL ENGINEERING
• Class definition, Object instances, Inheritance, Generic programming concept, files and I/O classes
• Definition of a computer
A computer is a device capable of solving problems or manipulating
data by accepting data, performing prescribed operations on the
data, and displaying the results in the desired form. The computer is
therefore a useful tool for data (or information) input, storage,
processing and output.
A computer system includes computer hardware, software and
people.
Types of computers
Electronically, all computers work about the same way. Computers differ widely in size and use. However,
all computers are similar in what the hardware does. The following types of computers can be identified
(i) Micro-computers
(like your desktop personal computer (PC) are designed for personal use, relatively low price and modest
data processing tasks.
(ii) Mini-computers
These are moderate sized and perform more complex tasks with larger amounts of data. Minicomputers
might be used in a small engineering office or a local bank branch to send transaction data to a head
office computer.
(iii) Mainframe-computers
These are large, expensive and can process billions of characters of data rapidly and fill entire room.
(iv) Super- computers
These are built to minimize distance between circuit boards and operate at very high speed for complex
uses, such as designing airplanes, animating complex movie sequences graphically or solving complex
engineering formulas having billions of steps mathematically. Super-computers are the main servers in
the internet system.
Computer applications
• Education
Computers are useful for promoting learning experiences. From the
toddler to the full grown adult, educational computer tools are
available. Computers are useful for learning about Computers and
learning about other subjects, i.e. using Computer Assisted Learning
software. Learning is usually interactive and can be reinforced over and
over. For children, the advent of Multimedia has made learning fun.
They often don't realize it when they're playing that they are also
learning.
Computer applications
• Banking & Finance
Computers are very useful for handling financial transactions, most
especially the storage and processing of huge amounts of information
kept by financial institutions. Computers enhances Customer service,
through the provision of up to date and timely information for their
Customers. Computers additionally assist with the monitoring of
operational costs, to ensure cost effectiveness and profitability of
operations. In some financial institutions, Computers are used to
identify trends and provide timely information for present and future
management decision making.
Computer applications
• Recreation
On your average PC, you can play a variety of games. With the
games, you could be the sole player, play against the Computer or
you and a friend could play against each other.
Computer applications
• Security
Computers are useful for storing information about crimes, criminals
and suspects. This can be very useful in crime detection and
prevention. Such systems can be interfaced with photograph capturing
and fingerprint systems. They can also be linked to mobile radio
communication systems over a wide area to enable in the fast and
efficient sharing of information on criminal activities. Such systems
would possess enquiry facility for historical and analytic purposes.
Computer applications
Other Applications
There are so many other areas where the impact of the computer is
being felt such as Medicine, Law, Sports, Entertainment, Media,
Building and Construction. In every situation the Computer performs
different functions relating to production. Computer based activity is
referred popularly to as Information Technology (IT).
Introduction to Operating Systems
• Before 1995, the O.S. that was in vogue was mainly Dos. Among the
several DOS operating system includes Ms-Dos, PC-Dos, PC-Mos, Unix,
etc. Dos consist of commands classified into internal and external
commands. To be able to use Dos effectively, one was required to learn
as many commands and their usage (syntax) by heart. All the application
programs that run under Dos (controlled) can only be operated by
remembering commands. The problems of remembering commands
among others become an uphill task to many Dos users. To compound
the problem, it was not possible under Dos to run more than one
application software at a time.
Historical Development of MS-DOS to Windows (O.S.)
• Just as the 1980s saw the PC revolution, the 1990s started seeing the
Windows revolution. In 1995, Microsoft released, not only a different
version of windows, but made Windows itself an Operating system.
Since then, all releases of Window are simply new version of the
Windows O.S. Presently there are windows 97, 98, 2000, Wnidows NT,
Windows XP, Windows Vista, Windows 7, Windows 8, Windows 10 and
Windows Phone 7.
MS-DOS and its commands
• The new system (Windows O.S.) was designed to allow a transition
between the Dos-based system and the purely Windows operating
system. To this end, Ms-dos now became an application under
Windows O.S. Gust as windows was a graphical operating environment
under Ms-dos). The implication of this design is that Dos-based
application programs can still be run under Windows operating
system. Similarly, most Dos commands, not all, that were associated
with Ms-dos can still be used by those addicted to Dos at the Dos
prompt environment in Windows. Therefore, for the benefit of those
in the category of Dos-addict, including users who have not been able
to upgrade their system to run Windows '95 and these later versions.
Some MS-DOS commands
• Below is a list of Ms-dos commands. After each command press enter.
• (a) CLS - CLear Screen command
• The Ms-dos clear screen command wipes the screen and gives you a
'blank slate' on which to work. To clear the screen, you must type
the command in its abbreviated form as follow: C:\>cls
Some MS-DOS commands
• (b) Format command
• Formatting erase all the information in the reformatted disk. Computer responses
during formatting operation. The Computer formatting message in Ms-dos varies
depending on what is to be formatted such as:
• A Hard disk-"WARNING: ALL Data on non-removable disk, drive C will be formatted.
Proceed with format Y/N."
• A New Diskette "Insert New Diskette in Drive A and press enter when ready"
• Previously used Diskette "Saving Unformatted information"
• After the message (or probably your response), your computer will
proceed to format, showing on the screen the percentage of format
level as it goes.
Example: C:\>Format A:
Some MS-DOS commands
• (c) Unformat command
• This command is used to undo a disk format. You may have accidentally formatted the
Disk you have been using. You may use Unformat with both floppy Disks Hard disks. But
note that this command cannot always guarantee full reconstruction of a disk completely.
• C:\>UnformatA:
• (d) Changing Drives
• When you start Ms-dos, it uses one of your Disk Drives as the current, or active Drive.
• To change from one active Disk Drive to another, simply type the
letter of the new drive you want to use followed by a colon (:).
Example: If C is the current drive and I want to use drive A,
I will change drive as follow: C:\>A:
• The Ms-dos prompt changes from C:\> to A:\>
Some MS-DOS commands
• (e) CHKDSK (CHECK DISK) command
• This command carries out an analysis of the disk specified or of the current drive and
provides information on total disk space, hidden files, number of directories, amount
of bad sectors on the disk, free disk space, and total memory left. CHKDSK [drive:] If
Drive letter is not specified, it will make analysis of the current drive.
• (f) SCANDISK command
• This command provides a more reliable disk verifying and management tool. With
Scandisk, data wrongly written into bad sectors on a disk can now be re-allocated.
Moreover, surface scan of the disk can also be performed. It is a good practice to scan
your computer thoroughly at least once every week.
• SCANDISK [drive:]
• e.g. C:\>SCANDISKA:
Some MS-DOS commands
• (g) DISKCOPY command
• This command is used to create an exact copy of the original disk.
Diskcopy is recommended for a floppy disk that contains information
you would like to duplicate against any eventuality. Diskcopy works
only with floppy disks and because it makes a character-by-character
duplicate, it works only with disks of the
• same size and capacity.
FILE MANAGEMENT commands
• DISKCOPY [diskl] [disk2]
• Diskl is the letter of the drive that contains the disk you want to
• copy (source diskette).
• Disk2 Is the letter of the drive you are copying to (target diskette)
• Example: C:\>diskcopy a: a: When you are using the same drive as
in the example above, your computer will prompt you when to insert
the source disk and the target disk.
Some MS-DOS commands
• (h) MAKE DIRECTORY (MD-command)
• The command, MD tells Ms-dos to create a New directory.
• MD [drive:] path. Example: Suppose you are at the root directory C to
create a directory Cupboard type :
• C:\>MD\Cupboard (This can also be written as C:\>MD Cupboard).
• To create a directory called Cupboard in a diskette (drive A), while still in C,
type:
• C:>MD A:Cupboard
• or
• A:\>MD\Cupboard
Some MS-DOS commands
• (i) CHANGE DIRECTORY (CD or CHDIR) command
• The CD command allows you to change from the Current directory to another. (A Current
directory is the directory you are presently)
• CD [drive:] [Subdirectory name.] Example:
• Examine this line: C:\Chaptl\Chapt2\Chapt3> Here, Chapt3 is the Current Directory, and
Chapt2 Chaptl and C:\ are called parent directories.
• To change to the parent (one level up) from the current directory, type CD., as follows:
• C:\Chaptl\Chapt2\Chapt3>CD„ enter The response of Ms-dos would be
• C:\Chaptl\Chapt2> This is now the current directory)
• But, if we had wanted to change straight to the root, the command would be:
C:\Chaptl\Chapt2\Chapt3>CD\ Enter
• (Here, backslash (\) indicate root directory)
Some MS-DOS commands
• (j) REMOVE DIRECTORY (RD) command
• To remove a directory from Root Directory type:
• C:\>RD Cupboard
• To remove a directory from Diskette type:
• C:>RD A:Cupboard
• or
• A:\>RD\Cupboard
Some MS-DOS commands
• (k) WILD CARD characters
• Dos uses Wild Cards as a shortcut in executing repetitive commands that use
similar file names or extensions. Example:
• . To list all the files contained in this storage location, we
• would type: DIR*.* . To list all the files with the extension 'doc', type DIR *.doc
• . To delete all the files that have letter "a" as the second
• Alphabet, DEL ?a*.* . To copy all the files starting with letter B regardless of
• the extensions, Copy B*.*
FILE MANAGEMENT commands
(i) DIR command
This command means the Directory information of the files in your
disk. The DIR command displays a list on the Monitor of the names
and attributes of all files on the Hard disk or diskette.
DIR [drive:] [filename] /p/w
Command options:
You can use DIR with certain options to obtain a better display of
your storage information.
DIR -List all the files in the current directory
DIR/P -pauses when the screen display is full and waits for
you to press any key to see the next display.
DIR/W -gives a wide display of the names of the files in a
directory.
FILE MANAGEMENT commands
DIR/A:D -displays the files whose attributes are the
DIRECTORIES only. This simply means, that the directories will
be displayed.
DIR/0:N To list all the files in alphabetical order. (O is for sort
order, and N for Alphabetical. Dos recognizes five sort orders: N for Alphabetical, E by
Extension, S by Size, D by date and G by directories. So, if I want to list only the
Directories on my Hard
disk and arrange the listing alphabetically, and display this list page by page.
Type: DIR/A:D/0:N/P
But DIR/A:-D/0:N/P (means only the files that are
not directories)
FILE MANAGEMENT commands
(ii) RENAME command
The rename command, abbreviated REN allow you to change the
name of one or more files.
REN [drive:] Namel Name2
Namel is the name of the file to be renamed
Name2 is the New name.
Introduction to Object Oriented Programing (OOP) using Java
Introduction to Visual Basic Programming
Find the Visual Basic icon and double click (nothing new). Also note the various
number of windows:
• Now click on the View Form button to see an interface set up to run simple
programs. The interface can also let you begin to experiment with input
and output through the form's components.
• Click on the View Code button to display modules of code. You need to find
the code for object Display and procedure Click. You may erase all the code
that is there between the first and last lines. Keep the first and last lines
intact. The Basic programs that you are to enter and try out are listed
below
Introduction to Visual Basic Programming
• Prefix Control
• Cbo Combobox
• Chk Check box
• Cmd Command button
• Dir Directory list box
• Drv Drive list box
• Fil Filelistbox
• fra Frame
• Frm Form
• Grd Grid
Table 3.1. Use these prefix abbreviations before control names.
• Property Description
• BackColor Specifies the command button's background color.
• Cancel Determines whether the command button gets a Click event if the user presses Esc.
• Caption Holds the text that appears on the command button.
• Default Determines if the command button responds to an Enter keypress even if another
control has the focus.
• Enabled Determines whether the command button is active.
• Font Produces a Font dialog box in which you can set the caption's font name, style, and size.
• Height Holds the height of the command button in twips.
• Left Holds the number of twips from the command button's left edge to the Form window's left
edge.
Table 4.1 ctd. Common command button properties.
• TabIndex Specifies the order of the command button in the focus order.
• TabStop Determines whether the command button can receive the focus.
• ToolTipText Holds the text that appears as a tooltip at runtime.
• Top Holds the number of twips from the command button's top edge to the Form window's top
edge.
• Visible Determines whether the command button appears or is hidden from the user. (Invisible
controls cannot receive the focus until the running code changes the Visible property to True.)
• Width Holds the width of the command button in twips.
Putting Code into Visual Basic
• Boolean A data type that takes on one of two values only: True or False. True
and False are Visual Basic reserved words, meaning that you cannot use them
for names of items you create.
• Byte Positive numeric values without decimals that range from 0 to 255.
• Date Holds date and time values. The date can range from January 1, 100,
to December 31, 9999. (In the years following 9999, people will have to use
something other than Visual Basic!)
Table 5.1ctd. The Visual Basic data types
• Decimal A new data type not yet supported in Visual Basic except in a few
advanced situations. The Decimal data type represents numbers with 28
decimal places of accuracy.
• Integer Numeric values with no decimal point or fraction that range from
-32,768 to 32,767.
• Long Integer values with a range beyond that of Integer data values.
Long data values range from -2,147,483,648 to 2,147,483,647. Long data
values consume more memory storage than integer values, and they are
less efficient. The Long data type is often called long integer.
Table 5.1ctd. The Visual Basic data types
• Object A special data type that holds and references objects such as controls and forms.
• Single Numeric values that range from -3.402823E+38 to 3.402823E+38. The Single data type is
often called single-precision.
• String Data that consists of 0 to 65,400 characters of alphanumeric data. Alphanumeric means
that the data can be both alphabetic and numeric. String data values may also contain special
characters such as ^, %, and @. Both fixed-length strings and variable-length strings exist.
• Variant Data of any data type and used for control and other values for which the data type is
unknown.
• Scientific Notation
Creating VBA Functions For MS Excel
• They are very useful and powerful if you know how to program them
properly. One main reason we need to create user defined functions
is to enable us to customize our spreadsheet environment for
individual needs.
Creating VBA Functions For MS Excel
• To create this application, insert the data control into the new form.
Place the data control somewhere at the bottom of the form. Name
the data control as data_navigator. To be able to use the data control,
we need to connect it to any database. We can create a database file
using any database application but I suggest we use the database files
that come with VB6
Creating database applications in VB
• Last but not least, insert another label and name it as cus_name and
leave the label empty as customers' names will appear here when we
click the arrows on the data control. We need to bind this label to the
data control for the application to work. To do this, open the label's
DataSource and select data_navigator that will appear automatically.
• You can also add other fields using exactly the same method. For
example, you can add adress, City and telephone number to the
database browser
Runtime Interface after additions
Creating database applications in VB
• One more thing that we need to do is to bind the label to the correct
field so that data in this field will appear on this label. To do this, open
the DataField property and select ContactName. Now, press F5 and
run the program. You should be able to browse all the customers'
names by clicking the arrows on the data control.
INTRODUCTION TO MATLAB
A Quick Tutorial on
MATLAB
Gowtham Bellala
MATL
AB
MATLAB is a software package for doing numerical
computation. It was originally designed for solving linear
algebra type problems using matrices. It’s name is
derived from MATrix LABoratory.
Scalars are matrices with only one row AND one column
Generating
Matrices
A scalar can be created in MATLAB as follows:
>> x = 23;
A matrix with only one row is called a row vector. A row vector
can be created in MATLAB as follows (note the commas):
>> y = [12,10,-3]
y =
12 10 -3
A matrix with only one column is called a column vector. A
column vector can be created in MATLAB as follows:
>> z = [12;10;-3]
z =
12
10
-3
Generating
Matrices
MATLAB treats row vector and column vector very differently
A(2,4)
A(17)
sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ;
repmat – replicates and tiles a matrix NOTE: The resulting matrix must
be rectangular
• >> b = [1,2;3,4]
• b =
• 1 2
• 3 4
• >> b_rep = repmat(b,1,2)
b_rep =
Matrix Addition
Increment all the elements Adding two matrices
of a matrix by a single value >> xsy = x +
>> x = [1,2;3,4] y xsy =
x = 7 9
1 2 11 13
3 4 >> z = [1,0.3]
>> y = x + 5 z =
y = 1 0.3
6 7 >> xsz = x + z
8 9 ??? Error using =>
plus Matrix
dimensions must agree
Matrix Multiplication
Matrix multiplication Element wise
>> a = [1,2;3,4]; (2x2) multiplication
>> a = [1,2;3,4];
>> b = [1,1]; (1x2) >> b = [1,½;1/3,¼];
>> c = b*a >> c = a.*b
c c
= =
4 6 1 1
1 1
>> c = a*b
??? Error using ==>
mtimes
Inner matrix
dimensions must
agree.
Matrix Element wise operations
>> a = [1,2;1,3]; Element wise power operation
>> b = [2,2;2,1]; >> c = a.^2
c =
Element wise division 1
>> c = a./b 1 9
4
c =
1 >> c = a.^b
0.5
0.5 3 c =
Eleme t wise multiplication 1
n =
4
>>
c a.*b 1
c = 3
2
4
Matrix Manipulation
functions
zeros : creates an array of all Ex: x = zeros(3,2)
zeros, Ex: x = ones(2)
ones : creates an array of all Ex: x = eye(3)
ones, : generates uniformly distributed random numbers in
eye : creates
[0,1] an identity matrix,
rand : Diagonal matrices and diagonal of a matrix
diag : returns array dimensions
size : returns length of a vector (row or column)
length : Matrix determinant
det : matrix inverse
inv : evaluates eigenvalues and eigenvectors
eig : rank of a matrix
rank : searches for the given values in an array/matrix.
find
MATLAB inbuilt math functions
Elementary Math
functions
abs - finds absolute value of all elements in the
sign matrix
sin,cos,… - signum function
asin,acos… -- Trignometric functions
Inverse trignometric
functions - Exponential
exp - natural logarithm, logarithm (base 10)
log,log10 - round towards +infinity, -infinity respectively
ceil,floor - round towards nearest integer
round - real and imaginary part of a complex matrix
real,imag - sort elements in ascending order
sort
Elementary Math
functions
sum,prod - summation and product of
elements
max,min - maximum and minimum of
arrays
mean,median – average and median of arrays
std,var - Standard deviation and
variance
>> t = linspace(0,6,1000);
>> y = zeros(1,1000);
>> y(t()<=1) = t(t()<=1);
>> y(t()>1) = 1./
t(t()>1);
>> figure
>> plot(t,y);
>> xlabel‘t values’;
>> ylabel‘y values’;
Subplot
s
Syntax: subplot (rows, columns, index)
>>
subplot(4,1,1)
>> …
>>
subplot(4,1,2)
>> …
>>
subplot(4,1,3)
>> …
>>
subplot(4,1,4)
>> …
Importing/Exporting
Data
Load and
Save
Using load and save
- if statements
- switch statements
- for loops
- while loops
- break statements
‘if’ statement
The general form of the ‘if’ Example 1:
statement is >> if i ==
>> if expression j
>> a(i,j) = 2;
>> … >> elseif i >= j
>> elseif expression >> a(i,j) = 1;
>> … >> else
>> else >> a(i,j) = 0;
>> … >> end
>> end
Example 2:
>> if
>> (attn>0.9)&(grade>60
>> end) pass = 1;
‘switch’ statement
switch Switch among Example :
several cases based on >> x = 2, y = 3;
expression >> switch x
>> case x==y
The general form of the >> disp('x and y are
switch statement is: equal');
>> switch switch_expr >> case x>y
>> disp('x is greater than
>> case
y');
case_expr1 >> otherwise
>> … >> disp('x is less than
>> case y');
case_expr2 >> end
>> … x is less than y
>> otherwise
>> … Note: Unlike C, MATLAB doesn’t need
BREAKs in each case
>> end
‘for’
loop
for Repeat statements a Example 1:
specific number of times >> for x = 0:0.05:1
>> printf(‘%d\n’,x)
The general form of a >> end ;
for statement is
>> for Example 2:
variable=expression
>> a = zeros(n,m);
>> …
>> … >> for i = 1:n
>> end >> for j = 1:m
>> a(i,j) = 1/(i+j);
>> end
>> end
‘while’ loop
Example 1:
while Repeat • >> n = 1;
statements an indefinite
number of times • >> y = zeros(1,10);
• >> while n <= 10
The general form of a >>
• y(n) = 2*n/(n+1); n
while statement is >>
= n+1;
>> end
>> while expression
>> …
>> … Example 2:
>> end
• >> x = 1;
• >> while x
• >> %execute statements
• >> end
Example:
>> y = 3;
>> forprintf(‘%5d’,x)
x = 1:10
>> ; if (x>y)
>> break;
>> end
>> end
1 2 3
4
Efficient
Programming
Efficient Programming in MATLAB
Avoid using your own functions, MATLAB’s functions are more likely
to be efficient than yours.
Example
1
Let x[n] be the input to a non causal FIR filter, with filter
coefficients h[n]. Assume both the input values and the filter
coefficients are stored in column vectors x,h and are given
to you. Compute the output values y[n] for n = 1,2,3 where
19
y[n] h[k ]x[n k
]
k 0
Solution
for n = 1 to 20
Solutio
n
Method 1: Method 2 (avoids inner loop):
>> y = zeros(20,1); >> y = zeros(20,1);
>> y(1) = 1; >> y(1) = 1;
>> for n = 2:20 >> for n = 2:20
>> for m = 1:n >> temp = 1:n;
>> temp = temp + m^3; >> y(n) = y(n-1)*sum(temp.^3);
>> end >> end
>> y(n) = y(n-1)*temp;
>> temp = 0 Method 3 (avoids both the loops):
>> end >> X = tril(ones(20)*diag(1:20));
>> x = sum(X.^3,2);
>> Y = tril(ones(20)*diag(x))+ …
triu(ones(20)) – eye(20);
>> y = prod(Y,2);
Getting more
help
•Where to get help?