Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more ➡
Download
Standard view
Full view
of .
Add note
Save to My Library
Sync to mobile
Look up keyword
Like this
1Activity
×
0 of .
Results for:
No results containing your search query
P. 1
An Introduction to MATLAB

An Introduction to MATLAB

Ratings: (0)|Views: 109|Likes:
Published by Saaif Shohagh
Introduction to MATLAB
Introduction to MATLAB

More info:

Published by: Saaif Shohagh on Jan 05, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See More
See less

11/28/2013

pdf

text

original

 
An Introduction to Matlab
Version 2.2
David F. Griffiths
Department of MathematicsThe UniversityDundee DD1 4HN
With additional material by Ulf CarlssonDepartment of Vehicle EngineeringKTH, Stockholm, SwedenCopyrightc
1996 by David F. Griffiths. Amended October, 1997 and August 2001.This introduction may be distributed provided that it is not be altered in any way and that its sourceis properly and completely specified.
 
Contents
1 MATLAB 22 Starting Up 2
2.1 Windows Systems . . . . . . . . . . 22.2 Unix Systems . . . . . . . . . . . . . 22.3 Command Line Help . . . . . . . . . 22.4 Demos . . . . . . . . . . . . . . . . . 3
3 Matlab as a Calculator 34 Numbers & Formats 35 Variables 3
5.1 Variable Names . . . . . . . . . . . . 3
6 Suppressing output 37 BuiltIn Functions 4
7.1 Trigonometric Functions . . . . . . . 47.2 Other Elementary Functions . . . . . 4
8 Vectors 4
8.1 The Colon Notation . . . . . . . . . 58.2 Extracting Bits of a Vector . . . . . 58.3 Column Vectors . . . . . . . . . . . . 58.4 Transposing . . . . . . . . . . . . . . 5
9 Keeping a record 610 Plotting Elementary Functions 6
10.1 Plotting—Titles & Labels . . . . . . 610.2 Grids . . . . . . . . . . . . . . . . . . 710.3 Line Styles & Colours . . . . . . . . 710.4 Multiplots . . . . . . . . . . . . . . 710.5 Hold . . . . . . . . . . . . . . . . . . 710.6 Hard Copy . . . . . . . . . . . . . . 710.7 Subplot . . . . . . . . . . . . . . . . 810.8 Zooming . . . . . . . . . . . . . . . . 810.9 Formatted text on Plots . . . . . . . 810.10Controlling Axes . . . . . . . . . . . 9
11 Keyboard Accelerators 912 Copying to and from Word and otherapplications 9
12.1 Window Systems . . . . . . . . . . . 1012.2 Unix Systems . . . . . . . . . . . . . 10
13 Script Files 1014 Products, Division & Powers of Vec-tors 10
14.1 Scalar Product (
*
) . . . . . . . . . . 1014.2 Dot Product (
.*
) . . . . . . . . . . . 1114.3 Dot Division of Arrays (
./
) . . . . . 1214.4 Dot Power of Arrays (
.^
) . . . . . . 12
15 Examples in Plotting 1216 Matrices—Two–Dimensional Arrays 13
16.1 Size of a matrix . . . . . . . . . . . . 1316.2 Transpose of a matrix . . . . . . . . 1416.3 Special Matrices . . . . . . . . . . . 1416.4 The Identity Matrix . . . . . . . . . 1416.5 Diagonal Matrices . . . . . . . . . . 1416.6 Building Matrices . . . . . . . . . . . 1516.7 Tabulating Functions . . . . . . . . . 1516.8 Extracting Bits of Matrices . . . . . 1516.9 Dot product of matrices (
.*
) . . . . 1616.10Matrix–vector products . . . . . . . 1616.11Matrix–Matrix Products . . . . . . . 1716.12Sparse Matrices . . . . . . . . . . . . 17
17 Systems of Linear Equations 17
17.1 Overdetermined system of linear equa-tions . . . . . . . . . . . . . . . . . . 18
18 Characters, Strings and Text 1919 Loops 2020 Logicals 21
20.1 While Loops . . . . . . . . . . . . . . 2220.2
if...then...else...end
. . . . . . 22
21 Function mles 23
21.1 Examples of functions . . . . . . . . 24
22 Further Builtin Functions 25
22.1 Rounding Numbers . . . . . . . . . . 2522.2 The
sum
Function . . . . . . . . . . . 2522.3
max
&
min
. . . . . . . . . . . . . . . 2522.4 Random Numbers . . . . . . . . . . 2622.5
find
for vectors . . . . . . . . . . . . 2622.6
find
for matrices . . . . . . . . . . . 26
23 Plotting Surfaces 2724 Timing 2825 Online Documentation 2826 Reading and Writing Data Files 29
26.1 Formatted Files . . . . . . . . . . . . 2926.2 Unformatted Files . . . . . . . . . . 30
27 Graphic User Interfaces 3028 Command Summary 31
1
 
1 MATLAB
Matlab is an interactive system for doing nu-merical computations.
A numerical analyst called Cleve Moler wrotethe first version of Matlab in the 1970s. Ithas since evolved into a successful commercialsoftware package.
Matlab relieves you of a lot of the mundanetasks associated with solving problems nu-merically. This allows you to spend more timethinking, and encourages you to experiment.
Matlab makes use of highly respected algo-rithms and hence you can be confident aboutyour results.
Powerful operations can be performed using just one or two commands.
You can build up your own set of functionsfor a particular application.
Excellent graphics facilities are available, andthe pictures can be inserted into L
A
TEX andWord documents.These notes provide only a brief glimpse of thepower and flexibility of the Matlab system. For amore comprehensive view we recommend the bookMatlab GuideD.J. Higham & N.J. HighamSIAM Philadelphia, 2000, ISBN: 0-89871-469-9.
2 Starting Up
2.1 Windows Systems
On Windows systems MATLAB is started by double-clicking the MATLAB icon on the desktop or byselecting MATLAB from the start menu.The starting procedure takes the user to the Com-mand window where the Command line is indicatedwith ’
>>
’. Used in the calculator mode all Matlabcommands are entered to the command line fromthe keyboard.Matlab can be used in a number of different ways ormodes; as an advanced calculator in the calculatormode, in a high level programming language modeand as a subroutine called from a C-program. Moreinformation on the first two of these modes is givenbelow.Help and information on Matlab commands can befound in several ways,
from the command line by using the ’
helptopic
’ command (see below),
from the separate Help window found underthe Help menu or
from the Matlab helpdesk stored on disk oron a CD-ROM.Another useful facility is to use the ’
lookfor keyword
command, which searches the help files for the key-word. See Exercise 16.1 (page 17) for an exampleof its use.
2.2 Unix Systems
You should have a directory reserved for sav-ing files associated with Matlab. Create sucha directory (
 mkdir
) if you do not have one.Change into this directory (
cd
).
Start up a new
xterm
window (do
xterm &
inthe existing
xterm
window).
Launch Matlab in one of the
xterm
windowswith the command
 matlab
After a short pause, the logo will be shownfollowed by
>>
where
>>
is the Matlab prompt.Type
quit
at any time
to exit from Mat-lab
.
2.3 Command Line Help
Help is available from the command line prompt.Type
help help
for “help” (which gives a brief syn-opsis of the help system),
help
for a list of topics.The first few lines of this read
HELP topics: matlab/general - General purpose commands. matlab/ops - Operators and special char... matlab/lang - Programming language const... matlab/elmat - Elementary matrices and ma... matlab/elfun - Elementary math functions. matlab/specfun - Specialized math functions.
(truncated lines are shown with ...). Then to ob-tain help on “Elementary math functions”, for instance,type
>> help elfun
This gives rather a lot of information so, in order to seethe information one screenful at a time, first issue thecommand
more on
, i.e.,
>> more on>> help elfun
Hit any key to progress to the next page of information.
2

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->