Ebook Ebook PDF Matlab An Introduction With Applications 5Th Edition All Chapter PDF Docx Kindle
Ebook Ebook PDF Matlab An Introduction With Applications 5Th Edition All Chapter PDF Docx Kindle
Ebook Ebook PDF Matlab An Introduction With Applications 5Th Edition All Chapter PDF Docx Kindle
I hope that the book will be useful and will help the users of MATLAB to
enjoy the software.
Amos Gilat
Columbus, Ohio
November, 2013
gilat. l @osu.edu
Introduction 1
Index 401
Introduction
Topics Covered
MATLAB is a huge program, and therefore it is impossible to cover all of it in one
book. This book focuses primarily on the foundations of MATLAB. The
1
2 Introduction
assumption is that once these foundations are well understood, the student will be
able to learn advanced topics easily by using the information in the Help menu.
The order in which the topics are presented in this book was chosen
carefully, based on several years of experience in teaching MATLAB in an
introductory engineering course. The topics are presented in an order that allows
the student to follow the book chapter after chapter. Every topic is presented
completely in one place and then used in the following chapters.
The first chapter describes the basic structure and features of MATLAB and
how to use the program for simple arithmetic operations with scalars as with a
calculator. Script files are introduced at the end of the chapter. They allow the
student to write, save, and execute simple MATLAB programs. The next two
chapters are devoted to the topic of arrays. MATLAB's basic data element is an
array that does not require dimensioning. This concept, which makes MATLAB a
very powerful program, can be a little difficult to grasp for students who have only
limited knowledge of and experience with linear algebra and vector analysis. The
concept of arrays is introduced gradually and then explained in extensive detail.
Chapter 2 describes how to create arrays, and Chapter 3 covers mathematical
operations with arrays.
Following the basics, more advanced topics that are related to script files
and input and output of data are presented in Chapter 4. This is followed by
coverage of two-dimensional plotting in Chapter 5. Programming with MATLAB
is introduced in Chapter 6. This includes flow control with conditional statements
and loops. User-defmed functions, anonymous functions, and function functions
are covered next in Chapter 7. The coverage of function files (user-defmed
functions) is intentionally separated from the subject of script files. This has
proven to be easier to understand by students who are not familiar with similar
concepts from other computer programs.
The next three chapters cover more advanced topics. Chapter 8 describes
how MATLAB can be used for carrying out calculations with polynomials, and
how to use MATLAB for curve fitting and interpolation. Chapter 9 covers
applications of MATLAB in numerical analysis. It includes solving nonlinear
equations, finding minimum or a maximum of a function, numerical integration,
and solution of first-order ordinary differential equations. Chapter 10 describes
how to produce three-dimensional plots, an extension of the chapter on two
dimensional plots. Chapter 11 covers in great detail how to use MATLAB in
symbolic operations.
In every chapter the topics are introduced gradually in an order that makes the
concepts easy to understand. The use of MATLAB is demonstrated extensively
within the text and by examples. Some of the longer examples in Chapters 1-3 are
titled as tutorials. Every use of MATLAB is printed with a different font and with
a gray background. Additional explanations appear in boxed text with a white
background. The idea is that the reader will execute these demonstrations and
Introduction 3
Symbolic Calculations
The MATLAB program, like most other software, is continually being developed
and new versions are released frequently. This book covers MATLAB Version
8.2.0.701, Release 2013b. It should be emphasized, however, that the book covers
the basics of MATLAB, which do not change much from version to version. The
book covers the use of MATLAB on computers that use the Windows operating
system. Everything is essentially the same when MATLAB is used on other
machines. The user is referred to the documentation of MATLAB for details on
using MATLAB on other operating systems. It is assumed that the software is
installed on the computer, and the user has basic knowledge of operating the
computer.
It is probably impossible to write a textbook where all the subjects are presented
in an order that is suitable for everyone. The order of topics in this book is such
that the fundamentals ofMATLAB are covered first (arrays and array operations),
and, as mentioned before, every topic is covered completely in one location,
which makes the book easy to use as a reference. The order of the topics in this
fifth edition is the same as in the previous edition. Programming is introduced
before user-defmed functions. This allows using programming in user-defmed
functions. Also, applications ofMATLAB in numerical analysis follow Chapter 8
which covers polynomials, curve fitting, and interpolation.
Chapterl
Starting with
MATLAB
This chapter begins by describing the characteristics and purpose of the different
windows in MATLAB. Next, the Command Window is introduced in detail. The
chapter shows how to use MATLAB for arithmetic operations with scalars in
much to the way that a calculator is used. This includes the use of elementary
math functions with scalars. The chapter then shows how to define scalar vari
ables (the assigmnent operator) and how to use these variables in arithmetic calcu
lations. The last section in the chapter introduces script files. It shows how to
write, save, and execute simple MATLAB programs.
It is assumed that the software is installed on the computer, and that the user can
start the program. Once the program starts, the MATLAB desktop window opens
with the default layout, Figure 1-1. The layout has a Toolstrip at the top, the Cur
rent Folder Toolbar below it, and four windows underneath. At the top of the
Toolstrip there are three tabs: HOME, PLOTS, and APPS. Clicking on the tabs
changes the icons in the Toolstrip. Commonly, MATLAB is used with the HOME
tab selected. The associated icons are used for executing various commands, as
explained later in this chapter. The PLOTS tab can be used to create plots, as
explained in Chapter 5 (Section 5.12), and the APPS tab can be used for opening
additional applications and Toolboxes of MATLAB.
5
6 Chapter 1: Startin.: with MATLAB
(ommandWindow ® Worlupace
CommandHistory @
· ·ls-- 10/2/2013 3:01 PM --
are briefly described on the following pages. More detailed descriptions are
included in the chapters where they are used. The Command History Window,
Current Folder Window, and the Workspace Window are described in Sections
1.2, 1.8.4, and 4.1, respectively.
Command Window: The Command Window is MATLAB 's main window and
opens when MATLAB is started. It is convenient to have the Command Window
as the only visible window. This can be done either by closing all the other win
dows, or by selecting Command Window Only in the menu that opens when the
Layout icon on the Toolstrip is selected. To close a window, click on the pull
down menu at the top right-hand side of the window and then select Close. Work
ing in the Command Window is described in detail in Section 1.2.
Window Purpose
Window Purpose
Figure Window: The Figure Window opens automatically when graphics com
mands are executed, and contains graphs created by these commands. An example
of a Figure Window is shown in Figure 1-2. A more detailed description of this
window is given in Chapter 5.
IJ Figur� 1
file ,Edit Yiew Insert Iools. Q.esktop Window Help
30
20
1
0
-10
- 20
-30
-40
-so o'-----
-- -----'---------'---
" ------
-- -'---------'-----
-- -:'::-1o 1 -
2L
---,-
----
-:'::-14 ---6
----
1"
2 4
____
Editor Window: The Editor Window is used for writing and editing programs.
This window is opened by clicking on the New Script icon in the Toolstrip, or by
clicking on the New icon and then selecting Script from the menu that opens. An
example of an Editor Window is shown in Figure 1-3.More details on the Editor
Window are given in Section 1.8.2, where it is used for writing script files, and in
Chapter 7, where it is used to write function files.
Help Window: The Help Window contains help information. This window can
be opened from the Help icon in the Toolstrip of the Command Window or the
toolbar of any MATLAB window. The Help Window is interactive and can be
used to obtain information on any feature ofMATLAB. Figure 1-4 shows an open
Help Window.
When MATLAB is started for the first time, the screen looks like that shown
in Figure 1-1. For most beginners it is probably more convenient to close all the
8 Chapter 1: Startin.: with MATLAB
r- !3 Editor- Unt:itledJ*
Find Files
Ul [) &> � � Run Section
EDIT NAVIGATE Breakpoints Ru n Run and Run and =
Advance
Prin t . nne Advance
DIS=sqrt (b"2-4iira'"'c);
�(-b+di3) I (2"'"a)
x1�(-b-dis)/(2'a)
�' Help
... �
.,
> Mathematics
file:/1/C:/Proqram F11es/MATLAB/R2013b/help/matlab/relea<e-note<.html
windows except the Command Window. The closed windows can be reopened by
selecting them from the layout icon in the Toolstrip. The windows shown in Fig
ure 1-1 can be displayed by clicking on the layout icon and selecting Default in
the menu that opens. The various windows in Figure 1-1 are docked to the desk
top. A window can be undocked (become a separate, independent window) by
dragging it out. An independent window can be redocked by clicking on the pull
down menu at the top right-hand side of the window and then selecting Dock.
The Command Window is MATLAB's main window and can be used for execut
ing commands, opening other windows, running programs written by the user, and
managing the software. An example of the Command Window, with several sim
ple commands that will be explained later in this chapter, is shown in Figure 1-5 .
• Once a command is typed and the Enter key is pressed, the command is executed.
However, only the last command is executed. Everything executed previously
(that might be still displayed) is unchanged.
• Several commands can be typed in the same line. This is done by typing a comma
between the commands. When the Enter key is pressed, the commands are exe
cuted in order from left to right.
•
A previously typed command can be recalled to the command prompt with the up
arrow key (t ). When the command is displayed at the command prompt, it can
be modified if needed and then executed. The down-arrow key ( .t) can be used to
move down the list of previously typed commands.
•
If a command is too long to fit in one line, it can be continued to the next line by
typing three periods ... (called an ellipsis) and pressing the Enter key. The con
tinuation of the command is then typed in the new line. The command can con
tinue line after line up to a total of 4,096 characters.
The semicolon ( ; ):
When a command is typed in the Command Window and the Enter key is
pressed, the command is executed. Any output that the command generates is dis
played in the Command Window. If a semicolon ( ; ) is typed at the end of a com
mand, the output of the command is not displayed. Typing a semicolon is useful
when the result is obvious or known, or when the output is very large.
If several commands are typed in the same line, the output from any of the
commands will not be displayed if a semicolon instead of a comma is typed
between the commands.
Typing%:
When the symbol% (percent) is typed at the beginning of a line, the line is desig
nated as a comment. This means that when the Enter key is pressed the line is not
executed. The% character followed by text (comment) can also be typed after a
command (in the same line). This has no effect on the execution of the command.
Usually there is no need for comments in the Command Window. Comments,
however, are frequently used in a program to add descriptions or to explain the
program (see Chapters 4 and 6).
The clc command:
The clc command (type clc and press Enter) clears the Command Window.
After typing in the Command Window for a while, the display may become very
long. Once the clc command is executed, a clear window is displayed. The com
mand does not change anything that was done before. For example, if some vari
ables were defined previously (see Section 1.6), they still exist and can be used.
The up-arrow key can also be used to recall commands that were typed before.
then right-clicking the mouse and selecting Delete Selection. The whole history
can be deleted by right-clicking the mouse and selecting choose Clear Command
History in the menu that opens.
Addition + 5+3
Subtraction 5-3
Multiplication * 5*3
It should be pointed out here that all the symbols except the left division are
the same as in most calculators. For scalars, the left division is the inverse of the
right division. The left division, however, is mostly used for operations with
arrays, which are discussed in Chapter 3.
Second Exponentiation.
The simplest way to use MATLAB is as a calculator. This is done in the Com
mand Window by typing a mathematical expression and pressing the Enter key.
MATLAB calculates the expression and responds by displaying ans = followed
by the numerical result of the expression in the next line. This is demonstrated in
Tutorial 1-1.
» 7+8/2 ......
---------l[ Type and press Enter.
ans =
11
[ 8/2 is executed first. )
» (7+8)/2 ...
... [
--------l Type and press Enter. J
ans =
7+8 is executed first. )
7.5000
>> 4+5/3+2
ans = 5/3 is executed first. )
7.6667
» 5 ... 3/2
ans =
[ 5A3 is executed first, /2 is executed next.
62.5000
>> 27 ... (1/3)+32 ... 0.2
1/3 is executed frrst, 27A(1/3) and 32A0.2 are
ans =
0.7071
>>
The last expression is the first four
terms of the Taylor series for sin(1t/4).
The user can control the format in which MATLAB displays output on the screen.
In Tutorial 1-1, the output format is fixed-point with four decimal digits (called
short), which is the default format for numerical values. The format can be
1.4 Display Formats 13
changed with the format command. Once the format command is entered, all
the output that follows is displayed in the specified format. Several of the avail
able formats are listed and described in Table 1-2.
MATLAB has several other formats for displaying numbers. Details of these
formats can be obtained by typing help format in the Command Window. The
format in which numbers are displayed does not affect how MATLAB computes
and saves numbers.
41.4286
0.001 :5: number :5: 1000
Otherwise display format
short e.
41.428571428571431
0.001 :5: number :5: 100
Otherwise display format
long e.
4.1429e+001
format long e Scientific notation with 15 » 290/7
decimal digits. ans =
4.142857142857143e+001
format short g Best of 5-digit fixed or » 290/7
floating point. ans =
41.429
format long g Best of 15-digit fixed or » 290/7
floating point. ans =
41.4285714285714
format bank Two decimal digits. » 290/7
ans =
41.43
format compact Eliminates empty lines to allow more lines with
information displayed on the screen.
Hän tunsi tulijan. Hän oli löytänyt hänet itsensä tuon valjun
hiljaisuuden keskeltä, joka häntä ympäröi.
Sitten piti rouva Lissin laulaa. Sen oli hän luvannut. Mutta oli aina
tarpeen koko joukko valmistuksia, kun rouva Liss ryhtyi laulamaan.
Kuullos,
Jos uskallusta,
Jos uskallusta Sull' lie!
3.
Hän löysi pienen polun, joka pihasta johti hakaan. Yli kivien ja
kantojen, joihin hän loukkasi itseään puolipimeässä, kulki hänen
tiensä kohden nummea.
Hän tiesi, että tässä hän oli oikealla paikallaan, — paikalla, johon
voi piiloutua.
Hän värähti. Oliko hänen kylmä? Olihan ilma lämmin ja lenseä, oli
tyyntä, — tuo hiljainen tuulenhenkäys vain kävi yli nummen.
Hän pysähtyi.
Itsekö hän todella tässä seisoi? Niinpä kyllä, mutta hän pelkäsi
pimeätä ja oli suunniltaan ja mieletön pelästyksestä.
Hän katsahti ylös, hämillään siitä että tulija tällä kertaa todellakin
oli ihminen. Joku oli pysähtynyt hänen eteensä.
Hän olisi halunnut huutaa: Älä jätä minua! Ota minut mukaasi!
4.
Neiti Hemb häntä nyt vastusti. Tämä oli sitä mieltä, että puutteita
oli olemassa ja että oli sääli niitä ihmisiä, jotka kärsivät hätää.
Rouva Liss oli vakuutettu että kaikki maailmassa oli parhain päin,
ja mitä hätään ja kurjuuteen tulee, niin siitä kyllä joku huolehti, siitä
hän oli varma!
*****
Tänään oli Omar Pasha vallan kauhea! Hän kuuli kaikki mitä
sanottiin ja singahutteli pieniä huomautuksia joka suuntaan. Ei
kukaan ollut niiltä turvassa. Naiset tunsivat jonkinmoista pelkoa
häntä kohtaan, mutta kun hän oli poissa, oli kaipaus sentään
suurempi kuin pelko hänen ollessaan läsnä.
Lehtori tulistui.
Tällaisesta hän juuri piti, kun sai täten rauhassa kuunnella toisten
puhetta. Häntä huvitti nähdessään että toiset naisista näyttivät
ärtyneiltä. Prinsessa Leila lepäsi hänen polvillansa ja katsoi
ympärilleen viattomin, ihmettelevin katsein, kuin aavistaen myrskyä.