Sie sind auf Seite 1von 133

CVE 314 – COMPUTER METHODS IN CIVIL

ENGINEERING
Course Title: COMPUTER METHODS IN CIVIL ENGINEERING

Course Code: CVE 314


Course Units: 2 credits

Department: Civil Engineering Department


Faculty: Faculty of Engineering & Environmental Sciences
College: Science, Engineering & Technology (SET)

Semester : Rain Semester


Session: 2019/2020 Academic Session

Lecturer: RAJI, S.A.(Ph.D.)


COURSE OUTLINE

• Architecture of Computer such as RAM, ROM, OOP

• Introduction to Object Oriented Programing (OOP) using Java

• Class definition, Object instances, Inheritance, Generic programming concept, files and I/O classes

• Concurrent programming concept and database programming.

• Java swing and AWT

• Practical application to Pipe network analysis (Hardy Cross method)

• Finite Element Method

• Linear Programming and Simplex Method of Optimization

(2 credits), 30h (T), 45h(P) Tue-3-5pm


COURSE OBJECTIVES

• To introduce students to the use of computers.


• To introduce students to Object Oriented Programing (OOP)
using Java.
• Concurrent programming concept and database programming.
• Practical application to Pipe network analysis (Hardy Cross
method)
What is a computer?

• 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

• Science & Engineering (S&E)


Computers are used in S&E to promote advances that could be useful
to mankind, i.e. discovering better and more efficient ways of doing
things. They are especially useful for humanly intractable calculations
and simulation experiments. This is especially critical in situations
where it would be too risky or expensive to directly carry out the
required operation. For example, in Space exploration, underwater
exploration, testing of new drugs, etc. Computers enable S&E
professionals can carry out their practical procedures using faster, more
accurate and safer methods.
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

• What is Operating System?


An operating system is a set of programs that introduces program(s) to a computer,
initiates and controls the execution of the program(s) and schedules all the resources
and services they require, such as printer, disk storage space and memory. It acts as
an interface between the user of the computer and the computer hardware.
The Operating System(O.S.) software is responsible for managing most of your
computer's activities, including:
. the allocation of computer resources
. maintenance of files.
. running of application As a resources manager, the operating system controls the
flow of information through your computer. Data accepted by the keyboard (Input
Unit) and seen on the display or sent to a printer is all under the control of the O.S.
Introduction to Operating Systems
• As a file manager, the O.S. is used to name files, save, retrieve and
maintain program files (program files hold the information that
application software requires to work while Data files are those files
you create and use in your computer).
• The O.S. is also a vital link between the computer hardware and
application software. Without the O.S., application software such as
WordPerfect, MS-Word, MS-Excel, MS-Access,Adobe Acrobat etc.
would not function.
Types of Operating systems

• Single User Operating System


These are O. S that are designed for small microcomputers and they allow
for only a single user at a time. Examples in this category are Ms-Dos, PC-Dos.

• Multi-Access and Time Sharing Operating System


These are operating systems that serve several
microcomputers and smaller minicomputers linked together
in a network. Notable in this category are Unix, Novel,
NetWare and PC-MOS.
Classes of Operating system
Operating systems can be classified into:

• DOS (Disk Operating System) and


• Windows Operating System.
Historical Development of MS-DOS to Windows (O.S.)

• 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.)

• In 1990, Microsoft responded to this agitation by introducing Windows


3.0, a program designed to maximize productivity. This windows version
allowed several applications to run at the same time; and more
importantly, it provided a simple means of information exchange between
Applications. This windows version was then a graphical environment. Its'
menus, icons (meaningful symbols), and dialog boxes replaced the often
Cryptic Commands that Ms-Dos requires. Under windows application
(programs that run under windows), commands that were earlier
memorized were represented on screen with meaningful pictures called
icons. Certain applications were developed that could only run under
windows into memory before the application programs are invoked to run.
Historical Development of MS-DOS to Windows (O.S.)

• It became possible within the same computer to Run both DOS


programs and WINDOWS-based programs; but under the control of
DOS operating system. Under this arrangement, it became possible to
work in more than one application at a time. In 1992, Microsoft
released Windows 3.1, which provides object links to help application
share data. Multimedia was brought to the PC world. All through
these years, Windows remained a graphical environment and not an
operating system. It could not run without the Ms-Disk operating
system.
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.

C:\>REN A:Namel Name2


FILE MANAGEMENT commands
(iii) COPY command
COPY source [destination]
Examples:
* To copy a file called letter saved in cupboard to a diskette
C:\Cupboard>Copy letter A:
(Notice that I operated from Cupboard subdirectory. From the root
directory, this would be. C:\>COPY\CUPBOARD\LETTER A:)

 
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:

Main window - standard Windows application menus and shortcut buttons


Toolbar window - buttons of components to put into a form
Properties window - allow you to configure the active component
Project window - select from multiple forms and switch between layout of the
form or its code
Form window - for interface design
Code window - for entering and editing code connecting an event to an object
Introduction to Visual Basic Programming

• Visual Basic Tutorial on Net at http:/www.vbtutor.net


• Lesson 1: Introduction Lesson 2: Building a Visual Basic Application Lesson 3: Writing the Codes
Lesson 4: Working With Controls Lesson 5: Managing Visual Basic Data
Lesson 6: Working With Variables Lesson 7: Controlling Program Flow
Lesson 8: More on Program Control Lesson 9: Looping
Lesson 10: Introduction to VB Function Part1
Introduction to Visual Basic Programming
• Lesson 11: Introduction to VB Function Part2
Lesson 12: Creating VB Function For MS Excel Lesson 13: Arrays
Lesson 14: Working With Files
Lesson 15: Creating Multimedia Applications: Part I
Lesson 16: Creating Multimedia Applications: Part II
Lesson 17: Creating Multimedia Applications: Part III
Lesson 18: Creating Multimedia Applications: Part IV
Lesson 19: Creating database applications in VB-Part I
Lesson 20: Creating database applications in VB-Part II
Lesson 21: Creating VB database applications using ADO control
Lesson 22: Creating an Advanced VB database application
Lesson 23: Animation- Part I Lesson 24: Animation-Part II
Lesson 25: Animation- Part III
Introduction to Visual Basic Programming

• Lesson 12: Creating VB Function For MS Excel


• Lesson 19: Creating database applications in VB-Part I
• Lesson 23: Animation- Part I

• Loading and running a program/project


• To load a project in which you can experiment with the Visual Basic
language, do the following:
From the File menu click on Open Project…

• 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

A first Basic program


• Sub Display_Click ()
• REM - a first program with simple printing
• PRINT “Welcome to Civil Egineering Department"
• PRINT "The sum of 3+5=";3+5
• End Sub
Introduction to Visual Basic Programming

Print your program code


• Be sure you have the form design as the active window.
• Go to File then Print… menu items and check off the code box and
then click on OK.

Controls and Properties
The highlights of this topic include
•What steps are required for
application creation
•How to place and size controls
•Why various properties require
different setting methods
•Which naming prefixes work best
•Why your application's tooltips give
users added help
Table 3.1. Use these prefix abbreviations before control names.

• 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.

• Hsb Horizontal scroll bar


• Img Image
• Lbl Label
• Lin Line
• Lst List box
• Mnu Menu
• Ole OLE client
• Opt Option button
• Pic Picture box
• Shp Shape
• Tmr Timer
• Txt Text box
• Vsb Vertical scrollbar
Table 4.1. Common command button properties.

• 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.

• MousePointer Determines the shape of the mouse


cursor when the user moves the mouse over the
command button.
• Picture Holds the name of an icon graphic image
that appears on the command button as long as the
Style property is set to 1-Graphical.
• Style Determines whether the command button
appears as a standard Windows command button (if
set to 0-Standard) or a command button with a color
and possible picture (if set to 1-Graphical).
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

The highlights of this topic include


• What data types VB supports
• How to declare variables
• How to assign data to variables
• Why data type mixups can occur
• When to use operators
Table 5.1. The Visual Basic data types
• .
Data Type Description and Range

• 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.

• Currency Data that holds dollar amounts from -$922,337,203,685,477.5808


to $922,337,203,685,477.5807. The four decimal places ensure that proper
rounding can occur. VB respects your Windows International settings and
adjusts currency amounts according to your country's requirements. Never
include the dollar sign when entering Currency values.

• 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.

• Double Numeric values that range from -1.79769313486232E+308 to


1.79769313486232E+308. The Double data type is often called double-
precision.

• 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

The Need to Create VBA Functions in MS-Excel


• You can create  your own functions to supplement the  built-in
functions in Microsoft Excel spreadsheet, which are quite limited in
some aspects. These user-defined  functions are also called  Visual
Basic for Applications functions, or simply VBA functions.
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

• For example, we might need a function that could calculate the


Commission available to a staff depending on sales volume which is
quite difficult if not impossible by using the built-in functions alone.
Creating  VBA  Functions For MS Excel
• The code for VBA is illustrated below.
• When a staff attain a sale volume of  N6000, he will be paid
N6000x15%=N720.00.
• A visual basic function to calculate the commissions can be written as
follows:
• Function Comm(Sales_V  As Variant) as Variant
• If Sales_V <500 Then
Comm=Sales_V*0.03
Elseif Sales_V>=500 and Sales_V<1000 Then
Comm=Sales_V*0.06
Elseif Sales_V>=1000 and Sales_V<2000 Then
Comm=Sales_V*0.09
Elseif Sales_V>=200 and Sales_V<5000 Then
Comm=Sales_V*0.12
Elseif Sales_V>=5000  Then
Comm=Sales_V*0.15
End If
• End Function
Using Microsoft Excel Visual Basic  Editor
• To create VBA functions in MS Excel, you can  click on tools,
• select macro and then click on Visual Basic Editor as shown
Inserting MS_Excel Visual Basic Editor
• Upon clicking the Visual Basic Editor, the VB Editor windows will
appear as shown in figure below. To create a function, type in the
function as illustrated in the slide above After typing, save the  file
and then return to the Excel windows
The VB Editor
Creating database applications in VB-

• Visual basic allows you to manage databases created with different


database programs such as MS Access, Dbase, Paradox and etc. In this
lesson, we are not dealing with how to create database files but we will see
how we can access database files in the VB environment. In the following
example, we will create a simple database application which enable one to
browse customers' names. 
Creating database applications in VB

• 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

• . Let select NWIND.MDB as our database file.


•     To connect the data control to this database, double-click the
DatabaseName property in the properties window and select the
above file, i.e NWIND.MDB. 
Creating database applications in VB

• Next, double-click on the RecordSource property to select the


customers table from the database. You can also change the caption
of the data control to anything but I use "Click to browse Customers"
here. After that, we will place a label  and change its caption to
Customer Name.
The Design  Interface.
Runtime  Interface
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.

 MATLAB has since been expanded and now has built-


in functions for solving problems requiring data analysis,
signal processing, optimization, and several other types of
scientific computations. It also contains functions for 2-D
and 3-D graphics and animation.
MATLAB Variable
names
 Variable names are case sensitive.
 Variable names can contain up to 63 characters ( as of
MATLAB 6.5 and newer).
 Variable names must start with a letter and can be followed by
letters, digits and underscores.
Examples :
>> x = 2;
>> abc_123 = 0.005;
>> 1ab = 2;
Error: Unexpected MATLAB expression
MATLAB Special
Variables
 pi Value of π
 eps Smallest incremental number
 inf Infinity
 NaN Not a number e.g. 0/0
 i and j i = j = square root of -1
 realmin The smallest usable positive real number
 realmax The largest usable positive real number
MATLAB Relational
operators
 MATLAB supports six relational operators.

Less Than <


Less Than or Equal <=
Greater Than >
Greater Than or Equal >=
Equal To ==
Not Equal To ~= (NOT !
= like in C)
MATLAB Logical
Operators
MATLAB supports three logical operators.

not ~ % highest precedence


and & % equal precedence with or
or | % equal precedence with
and
Matrices and
MATLAB
MATLAB
Matrices
 MATLAB treats all variables as matrices. For our
purposes a matrix can be thought of as an array, in fact, that
is how it is stored.

 Vectors are special forms of matrices and contain only one


row OR one column.

 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 matrix can be created in MATLAB as follows (note the


commas and semicolons)
>> X = [1,2,3;4,5,6;7,8,9]
X =
1 2 3
4 5 6
7 8 9

Matrices must be rectangular!


The Matrix in
MATLAB

A(2,4)

A(17)

Note: Unlike C, MATLAB’s indices start from 1


Extracting a Sub-
matrix
 A portion of a matrix can be extracted and stored in a smaller
matrix by specifying the names of both matrices and the
rows and columns to extract. The syntax is:

sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ;

where r1 and r2 specify the beginning and ending rows and


c1 and c2 specify the beginning and ending columns to be
extracted to make the new matrix.
Extracting a Sub-
matrix
 Example :
>> X =
[1,2,3;4,5,6;7,8,9] X =
1 2 3
>> X13 =
4 5 6
X(3,1:3) X13 =
7 8 9
7
>> X22 = X(1:2 , 8
2:3) X22 =
2 3 9
5 6
>> X21 =
X(1:2,1) X21 =
1
4
Matrix Extension
 >> a = [1,2i,0.56]
• a =  Concatenation
• 1 0+2i 0.56 >> a = [1,2;3,4]
a =
>> a(2,4) = 0.1 1 2
a = 3 4
>> a_cat =[a,2*a;3*a,2*a]
• 1 0+2i 0.56 a_cat =
0 1 2
• 0 0 0 3 4 6 82
0.1 3 6 2 44
9 12 6 8

 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

and many more…


Graphics
Fundamentals
2D
Plotting
 Example 1: Plot sin(x) and cos(x) over [0,2π], on the same plot
with different colours
Method 1:
>> x = linspace(0,2*pi,1000);
>> y = sin(x);
>> z = cos(x);
>> hold on;
>> plot(x,y,‘b’);
>> plot(x,z,‘g’);
>> xlabel ‘X values’;
>> ylabel ‘Y values’;
>> title ‘Sample Plot’;
>> legend (‘Y data’,‘Z
data’);
>> hold off;
2D
Plotting
Method 2:
>> x = 0:0.01:2*pi;
>> y = sin(x);
>> z = cos(x);
>> figure
>> plot (x,y,x,z);
>> xlabel ‘X values’;
>> ylabel ‘Y values’;
>> title ‘Sample Plot’;
>> legend (‘Y data’,‘Z
data’);
>> grid on;
2D
Plotting 0t
 t
Example 2: Plot the following function y   1
1/ t
1t6
Method 1: ;
>> t1 = linspace(0,1,1000);
>> t2 = linspace(1,6,1000)
>> y1 = t1;
>> y2 = 1./ t2;
>> t = [t1,t2];
>> y = [y1,y2];
>> figure
>> plot(t,y);
>> xlabel ‘t values’, ylabel ‘y values’;
2D
Plotting
Method 2:

>> 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

load filename - loads all variables from the file “filename”


load filename x - loads only the variable x from the file
load filename a* - loads all variables starting with ‘a’
for more information, type help load at command prompt

save filename - saves all workspace variables to a


binary
save filename x,y - .mat filevariables
saves named filename.mat
x and y in
filename.mat
for more information, type help save at command prompt
Import/Export from Excel sheet
 Copy data from an excel sheet
>> x = xlsread(filename);
% if the file contains numeric values, text and raw data values, then
>> [numeric,txt,raw] = xlsread(filename);

 Copy data to an excel sheet


>>x = xlswrite('c:\matlab\work\data.xls',A,'A2:C4')
% will write A to the workbook file, data.xls, and attempt to fit the
elements of A into the rectangular worksheet region, A2:C4. On
success, ‘x’ will contain ‘1’, while on failure, ‘x’ will contain ‘0’.
for more information, type help xlswrite at command prompt
Read/write from a text
file
 Writing onto a text file
>> fid = fopen(‘filename.txt’,‘w’);
>> count = fwrite(fid,x);
>> fclose(fid);
% creates a file named ‘filename.txt’ in your workspace and stores
the values of variable ‘x’ in the file. ‘count’ returns the number of
values successfully stored. Do not forget to close the file at the
end.

 Read from a text file


>> fid = fopen(‘filename.txt’,‘r’);
>> X = fscanf(fid,‘%5d’);
>> fclose(fid);
% opens the file ‘filename.txt’ which is in your workspace and
loads the values in the format ‘%5d’ into the variable x.
Other useful commands: fread, fprintf
Flow Control in
MATLAB
Flow
control
 MATLAB has five flow control statements

- 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

•Note: In MATLAB ‘1’ is synonymous


‘break’
statement
 break terminates the execution of for and while loops
 In nested loops, break terminates from the innermost loop
only

 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 nested loops as far as possible

 In most cases, one can replace nested loops with efficient


matrix manipulation.

 Preallocate your arrays when possible

 MATLAB comes with a huge library of in-built functions, use


them when necessary

 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

 Method 1:  Method 2 (avoids inner loop):


>> y = zeros(1,3); >> y = zeros(1,3);
>> for n = 1:3 >> for n = 1:3
>> for k = 0:19 >> y(n) = h’*x(n:(n+19));
>> y(n)= y(n)+h(k)*x(n+k); >> end
>> end
>> end
 Method 3 (avoids both the loops):
>> X= [x(1:20),x(2:21),x(3:22)];
>> y = h’*X;
Example
2
 Compute the value of the following function

y(n) = 13*(13+23)*(13+23+33)*…*(13+23+ …+n3)

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?

 In MATLAB’s prompt type :


• help, lookfor, helpwin, helpdesk, demos
 On the Web : http://www.mathworks.com/support
http://www.mathworks.com/products/demos/#
http://www.math.siu.edu/MATLAB/tutorials.html
• http://math.ucsd.edu/~driver/21d -s99/MATLAB-primer.html
http://www.mit.edu/~pwb/cssm/
http://www.eecs.umich.edu/~aey/eecs216/.html
Introduction to AutoCAD
• Types of AutoCAD versions
• MS Windows environment
• Installing and Setting up AUTOCAD
• Advantages of AutoCAD drawing
• Working withAutoCAD
Start a Drawing from Scratch

A quick way to begin a new drawing is to start from


scratch, which starts a drawing that uses settings
from a default drawing template file.
To begin a new drawing using a wizard

• If necessary, set the STARTUP system variable to 1 and the FILEDIA


system variable to 1.
• On the File menu, choose New.
• In the Create New Drawing dialog box, click Use a Wizard.
• Click Quick Setup or Advanced Setup.
• Complete the wizard pages using the Next and Back buttons to move
forward and backward.
• On the last page, click Finish.
DRAWING COMMANDS

• Drawing Commands are used for drawing objects.


Examples go as follows:
• To draw lines
• Polyline
• To draw a polyline with straight segments
• To draw a line and arc combination polyline
• From the Draw menu, choose Polyline.
• Specify the start point of the polyline segment.
• Specify the endpoint of the polyline segment.
• Switch to Arc mode by entering a (Arc) on the command line.
• Return to Line mode by entering L (Line).
• Specify additional polyline segments as needed.
• Press ENTER to end or c to close the polyline.
Creating simple geometry
• To create a wide polyline
•.
• To draw a circle by specifying a center point and radius or diameter
• . To draw a rectangle
•.
• To draw a circumscribed polygon

• To draw an inscribed polygon


To draw a rectangle
•.
To draw a circumscribed polygon

To draw an inscribed polygon

To draw an arc by specifying three points

To draw an arc using a start point, a center point, and an


endpoint
• To draw an arc by specifying three points
• From the Draw menu, choose Arc 3 Points.
• Specify the start point.
• Specify a point on the arc.
• Specify the endpoint.
• To draw an arc using a start point, a center point, and an endpoint
• From the Draw menu, choose Arc Start, Center, End.
• Specify a start point.
• Specify the center point.
• Specify the endpoint.
• These are just the basic drawing commands. You are going to follow similar steps in drawing other
objects.
EDITING COMMANDS
• Erase
• Copy
• Multiple Copy
• Mirror
• Offset
• Rectangular Array
• Polar Array
• Move
• Rotate
• Scale
• Trim
• Extend
OBJECT SELECTION COMMANDS

• To pick objects directly in the drawing area


• To see a list of options at the Select Objects prompt
• To select objects within an irregularly shaped area
• To select objects crossing an irregularly shaped area
• To select objects with a fence
• To remove several objects from the selection set
OBJECT SNAP (Osnap)
• To set running object snaps
• Using Orthogonal Locking (Ortho Mode)
• To turn on or turn off Ortho mode
• Layer (Layering Objects)
• To create a new layer
• To remove an unused layer
• To change the layer of an object
• To rename a layer
• To assign a color to a layer
• To assign a lineweight to a layer
• Zoom (Zooming Objects /Drawings)
• Panning
Annotation
• To create single-line text
• To specify a text style when you create single-line text
• To Create Multiline Text
• To define a block for the current drawing
DIMENSIONING
• To create a horizontal or vertical dimension
• To create an aligned dimension
• To create a baseline linear dimension
• To create a continued linear dimension
• To plot a drawing
• Thank you for attending my class

Das könnte Ihnen auch gefallen