You are on page 1of 449

Contents

vi
Contents
vii
Contents
viii
Contents
xi
Contents
xii
Preface to the
third edition
Preface
xx
Part I
Essentials
1
Introduction
The objectives of this chapter are to enable you to use some simple MATLAB
commands fromthe CommandWindowand to examine various MATLAB desktop
and editing features.
++
Essential MATLAB for Engineers and Scientists
1.1 Using MATLAB
4
1 Introduction
Figure 1.1 The MATLAB desktop

5
1 Introduction

< >
< >
7
Essential MATLAB for Engineers and Scientists

< >
< >
< >

/
< >
< >
< >
< >
< >
< >
8
1 Introduction
< >
< >

< >
< >
< >
< >
9
Essential MATLAB for Engineers and Scientists
< >
< >
< >
< >
< >
10
1 Introduction

Figure 1.2 A gure window


+ =
= .
11
Essential MATLAB for Engineers and Scientists
< >
< >
< >
= =
< >
< >
< >
< >
< >
< >
12
1 Introduction

+ /
< >
< >
< >
< >
< >
13
Essential MATLAB for Engineers and Scientists

Figure 1.3 The Mexican hat


< >
< >
< >
< >
< >
< >
14
Essential MATLAB for Engineers and Scientists
+ +
+
18
1 Introduction
1.3.2 Saving a program: script les
19
Essential MATLAB for Engineers and Scientists
Current directory
Recommended way to run a script from the Current
Directory browser
20
1 Introduction
1.3.3 How a program works
21
Essential MATLAB for Engineers and Scientists
S u m m a r y
22
1 Introduction
E X E R C I S E
23
2
MATLAB fundamentals
The objective of this chapter is to introduce some of the fundamentals of MATLAB
programming, including:
variables, operators and expressions;
arrays (including vectors and matrices);
basic input and output;
repetition ( );
decisions ( ).
2.1 Variables and the workspace
2.1.1 Variables
2 MATLAB fundamentals
2.1.2 Case sensitivity
2.1.3 The workspace
25
Essential MATLAB for Engineers and Scientists
26
2 MATLAB fundamentals
2.1.4 Adding commonly used constants to the workspace
2.2 Arrays: vectors and matrices
27
Essential MATLAB for Engineers and Scientists
2.2.1 Initializing vectors: explicit lists

28
2 MATLAB fundamentals
2.2.2 Initializing vectors: the colon operator
29
Essential MATLAB for Engineers and Scientists

2.2.3
/
2.2.4 Transposing vectors
30
Essential MATLAB for Engineers and Scientists
2.2.7 Capturing output
32
2 MATLAB fundamentals
2.3 Vertical motion under gravity
= /
33
Essential MATLAB for Engineers and Scientists

Figure 2.1 Distancetime graph of stone thrown vertically upward


34
Essential MATLAB for Engineers and Scientists
.



E X E R C I S E S
. .


2.4.2 Data types
36
2 MATLAB fundamentals
Table 2.3 Arithmetic operators that operate element by
element on arrays.
Operator Description
Multiplication
Right division
\ Left division
Power
2.4.6 The transpose operator
2.4.7 Arithmetic operations on arrays
39
Essential MATLAB for Engineers and Scientists
=

.
40
2 MATLAB fundamentals
2.4.10 Statements, commands and functions
2.4.11 Vectorization of formulae
+
43
Essential MATLAB for Engineers and Scientists
+
/ / / /


= / +

46
Essential MATLAB for Engineers and Scientists
+ +
48
2 MATLAB fundamentals
2.5.2
.
. <
49
2 MATLAB fundamentals

2.6 Repeating with


2.6.1 Square roots with Newtons method
51
Essential MATLAB for Engineers and Scientists
=
/
2 MATLAB fundamentals
2.6.2 Factorials!
!
! = . . . .
2.6.3 Limit of a sequence
= / ! = . . .
!
=
!

=

/ .

53
Essential MATLAB for Engineers and Scientists
=
2.6.4 The basic construct
+ + . . .
+ + . . .
> <
54
2 MATLAB fundamentals



+ =

+ = .
55
Essential MATLAB for Engineers and Scientists
2.6.5 in a single line
2.6.6 More general
2.6.7 Avoid loops by vectorizing!

=
56
2 MATLAB fundamentals

=
.
57
Essential MATLAB for Engineers and Scientists
+ +
58
2 MATLAB fundamentals
!
2.6.8 A common mistake: less loops!
E X E R C I S E S
+ + + + .
+ +

+

+

+ =

.
59
2 MATLAB fundamentals
Table 2.4 Relational operators
Relational operator Meaning
less than
less than or equal
equal
not equal
greater than
greater than or equal
<

=
=
E X E R C I S E S
61
Essential MATLAB for Engineers and Scientists
Figure 2.2 A quadratic function with equal roots
66
2 MATLAB fundamentals
2.7.7 Nested s
=
67
2 MATLAB fundamentals
2.8 Complex numbers

+
69
Essential MATLAB for Engineers and Scientists
=

.

70
Essential MATLAB for Engineers and Scientists
\
72
Essential MATLAB for Engineers and Scientists
2.10.2 The statement

74
2 MATLAB fundamentals
E X E R C I S E S
2.10.3 Shelling out to the operating system
75
2 MATLAB fundamentals
S u m m a r y
77
Essential MATLAB for Engineers and Scientists
\
Essential MATLAB for Engineers and Scientists
E X E R C I S E S
+
+
+
+
+
+

/
+
/ ! + / !
80
2 MATLAB fundamentals
=
+


= = =
= / + .




=

81
2 MATLAB fundamentals
=
= =
=
+

= =
83
3
Program design and
algorithm development
The objectives of this chapter are to introduce you to the concept of program
design and to the concept of a structure plan (pseudocode) as a means of
designing the logic of a program.
Essential MATLAB for Engineers and Scientists
++
88
3 Program design and algorithm development
+
3.1.1 Projectile problem example
89
Essential MATLAB for Engineers and Scientists

< / =
=/
= .
>
=
= =
= .
=
= .
=
= .
= / .
=
=
= .
90
3 Program design and algorithm development
<
> < /

+
=


.

=
91
Essential MATLAB for Engineers and Scientists
92
Essential MATLAB for Engineers and Scientists

Figure 3.2 Projectile angle vs. speed


94
3 Program design and algorithm development
95
3 Program design and algorithm development
97
Essential MATLAB for Engineers and Scientists
3.2 Other examples of structure plans

98
Essential MATLAB for Engineers and Scientists
Figure 3.4 Graph of a quadratic equation with real unequal roots indicated by
3.3 Structured programming with functions
100
3 Program design and algorithm development
S u m m a r y
E X E R C I S E S
101
Essential MATLAB for Engineers and Scientists
= =
>

>

= =
+ + = .
.
.
. .
+ =
=
102
3 Program design and algorithm development
= =
+ =
+ = .
103
4
MATLAB functions &
*data import-export
utilities
The objectives of this chapter are:
To enable you to become familiar with some of the more common MATLAB
functions.
To introduce you briey to ways of importing and exporting data in and out
of the MATLAB workspace using:
The and commands.
The Import Wizard.
The low-level le input/output (I/O) functions.
4 MATLAB functions & data import-export utilities
4.1 Some common functions

.
/ /
105
4 MATLAB functions & data import-export utilities

Figure 4.2 A comparison of the results from the acos, asin and atan functions.
109
Essential MATLAB for Engineers and Scientists
Importing binary data
4.2.5 The Import Wizard
Importing ASCII data
Importing binary data
112
4 MATLAB functions & data import-export utilities
4.2.6 Low-level le I/O functions
Writing binary data
113
Essential MATLAB for Engineers and Scientists
114
4 MATLAB functions & data import-export utilities
Reading binary data
\
115
Essential MATLAB for Engineers and Scientists
Changing binary data
\
116
4 MATLAB functions & data import-export utilities
117
Essential MATLAB for Engineers and Scientists
4.2.7 Other import/export functions
S u m m a r y
E X E R C I S E S

= + .
+ +
+

118
5
Logical vectors
The objectives of this chapter are to enable you to:
Understand logical operators more fully.
And to introduce you to:
Logical vectors and how to use them effectively in a number of
applications.
Logical functions.
5 Logical vectors
Figure 5.1 A discontinuous graph using logical vectors
5.1.2 Avoiding division by zero
/
123
Essential MATLAB for Engineers and Scientists

Figure 5.2 sin(x)/x


=
124
Essential MATLAB for Engineers and Scientists
5.1.4 Counting random numbers
126
Essential MATLAB for Engineers and Scientists
5.2.2 Danger
< <
5.2.3 Logical operators and vectors
130
5 Logical vectors
E X E R C I S E
5.3 Subscripting with logical vectors
131
Essential MATLAB for Engineers and Scientists
132
5 Logical vectors
5.4 Logical functions
133
Essential MATLAB for Engineers and Scientists
+
5.4.1 Using and
134
5 Logical vectors
5.5 Logical vectors instead of ladders
+
+
+ .
135
Essential MATLAB for Engineers and Scientists
S u m m a r y
E X E R C I S E S
138
5 Logical vectors
+
+
+
139
Essential MATLAB for Engineers and Scientists
140
6
Matrices of numbers &
arrays of strings
The objectives of this chapter are to:
Introduce you to ways of creating and manipulating matrices.
Introduce you to matrix operations.
Introduce you to character strings and facilities for
handling them.
Essential MATLAB for Engineers and Scientists
6.1 Matrices
6.1.1 A concrete example
142
6 Matrices of numbers & arrays of strings
+ + + .
6.1.2 Creating matrices
143
Essential MATLAB for Engineers and Scientists
6.1.3 Subscripts
6.1.4 Transpose
6.1.5 The colon operator
144
6 Matrices of numbers & arrays of strings
147
6 Matrices of numbers & arrays of strings
6.1.8 Elementary matrices
149
6 Matrices of numbers & arrays of strings

6.1.10 Using MATLAB functions with matrices


151
Essential MATLAB for Engineers and Scientists
6.1.11 Manipulating matrices
152
6 Matrices of numbers & arrays of strings
6.1.12 Array (element-by-element) operations on matrices
6.1.13 Matrices and
153
Essential MATLAB for Engineers and Scientists
6.1.14 Visualization of matrices
6.1.15 Vectorizing nested s: loan repayment tables
=
+ /
+ /
.
\
154
6 Matrices of numbers & arrays of strings
155
Essential MATLAB for Engineers and Scientists
6.1.16 Multidimensional arrays
156
6 Matrices of numbers & arrays of strings
6.2 Matrix operations
6.2.1 Matrix multiplication
=
157
Essential MATLAB for Engineers and Scientists
+ +

=
.


=

.
158
Essential MATLAB for Engineers and Scientists
6.3 Other matrix functions
6.4 *Strings
6.4.1 Assignment
6.4.2 Input
160
Essential MATLAB for Engineers and Scientists
6.4.5 ASCII codes, and
162
6 Matrices of numbers & arrays of strings
6.4.6 of strings
\
\
\
6.4.7 Comparing strings
163
Essential MATLAB for Engineers and Scientists
6.4.8 Other string functions
6.5 *Two-dimensional strings
164
6 Matrices of numbers & arrays of strings
6.6 * and text macros
165
Essential MATLAB for Engineers and Scientists
6.6.1 Error trapping with and
\
166
6 Matrices of numbers & arrays of strings
6.6.2 with
S u m m a r y
167
Essential MATLAB for Engineers and Scientists
E X E R C I S E S

168
7
Introduction to
graphics
The objective of this chapter is to introduce you to
MATLABs high-level 2-D and 3-D plotting facilities.
7.1 Basic 2-D graphs
Essential MATLAB for Engineers and Scientists
Figure 7.1 Examples of
E X E R C I S E S

172
7 Introduction to graphics
7.1.1 Labels
7.1.2 Multiple plots on the same axes
173
7 Introduction to graphics
7.1.4 Axis limits
175
Essential MATLAB for Engineers and Scientists
7.1.5 Multiple plots in a gure:

176
7 Introduction to graphics

Figure 7.2 Four subplots: rotations of a 3-D surface


177
7 Introduction to graphics
Figure 7.3 A logarithmic plot
. . . . . . . . .
=
E X E R C I S E

7.1.9 Polar plots

=
=


179
Essential MATLAB for Engineers and Scientists
Figure 7.4 Polar plot of against sin(2)
7.1.10 Plotting rapidly changing mathematical functions:
180
Essential MATLAB for Engineers and Scientists
7.2.1

Figure 7.6 Examples of


182
7 Introduction to graphics

x
y
z
Figure 7.7 The surface =
E X E R C I S E S
=
.
.
185
Essential MATLAB for Engineers and Scientists
Figure 7.8Heat distribution over a steel plate
. .
7.6.4Contourplots
186
Essential MATLAB for Engineers and Scientists

y x
Figure 7.10 (a) ; (b) cropping a surface
7.2.6 Visualizing vector elds
= +
=

= .

188
7 Introduction to graphics

Figure 7.11 Gradients and level surfaces


7.2.7 Visualization of matrices
189
Essential MATLAB for Engineers and Scientists

7.2.8 Rotation of 3-D graphs


Figure 7.12 Visualization of a matrix
190
7 Introduction to graphics
.

E X E R C I S E
191
Essential MATLAB for Engineers and Scientists
7.2.9 Other cool graphics functions
192
7 Introduction to graphics

193
7 Introduction to graphics

Essential MATLAB for Engineers and Scientists

198
7 Introduction to graphics
E X E R C I S E S
=
+
. .
=
201
Essential MATLAB for Engineers and Scientists
=

> >

Figure 7.14 USA population: model and census data ( )
Figure 7.15 Spirals
202
Essential MATLAB for Engineers and Scientists
. .

=
!
! !
=


.
8.1.2 Update processes

+
+
=
= . =
206
8 Loops
207
8 Loops
8.2.4 Prime numbers
211
Essential MATLAB for Engineers and Scientists
=

= =
= <

=
8.2.5 Projectile trajectory
212
8 Loops
213
Essential MATLAB for Engineers and Scientists
Figure 8.1 Projectile trajectory
214
8 Loops
8.2.6 and
8.2.7 Menus
215
Essential MATLAB for Engineers and Scientists
Figure 8.2 A menu window
S u m m a r y
216
8 Loops
E X E R C I S E S

= / + / / + /
=
= + +

=

+

+


217
Essential MATLAB for Engineers and Scientists

= + + .

= =


/
= /
= /

/
= + /
= /
=

+
/
218
8 Loops
=

< <
< < .
=

=
+

.
=
.
=
=


Figure 8.3 Fourier series: Gibbs phenomenon
219
Essential MATLAB for Engineers and Scientists
9 Errors and pitfalls
\
.

+ + =
= +

/
=

/ .
227
Essential MATLAB for Engineers and Scientists
= = = . = =
/
/ / =

9.5 Trapping and generating errors
S u m m a r y
E X E R C I S E S
+
228
9 Errors and pitfalls

=
=

+ =
+ =
= /
= / .

. + . = .
. + . = . .
= =
= =
229
10
Function M-les
The objective of this chapter is to enable you to:
Represent your own functions with inline objects and function M-les.
10.1 Some examples
10.1.1 Inline objects: harmonic oscillators
10 Function M-les
=

10.2 Basic rules


233
Essential MATLAB for Engineers and Scientists
234
Essential MATLAB for Engineers and Scientists
236
10 Function M-les
237
Essential MATLAB for Engineers and Scientists
238
10 Function M-les
10.2.1 Subfunctions
10.2.2 Private functions
10.2.3 P-code les
239
10 Function M-les
= +

241
Essential MATLAB for Engineers and Scientists
10.4 Command/function duality
242
Essential MATLAB for Engineers and Scientists
10.6.1 Debugging a script
244
10 Function M-les
245
Essential MATLAB for Engineers and Scientists
10.6.2 Debugging a function
10.7 Recursion
! = !
246
Essential MATLAB for Engineers and Scientists
S u m m a r y
248
10 Function M-les
E X E R C I S E S
+ /
= =

= + +
!
+
!
+

249
Essential MATLAB for Engineers and Scientists
11
Vectors as arrays &
*advanced data
structures
The objectives of this chapter are:
11.1 Update processes
Essential MATLAB for Engineers and Scientists

+
+
=
11.1.1 Unit time steps
=
252
Essential MATLAB for Engineers and Scientists
254
Essential MATLAB for Engineers and Scientists
+
= . = .
11.1.3 Using a function
256
11 Vectors as arrays & advanced data structures
= = .
= .
257
Essential MATLAB for Engineers and Scientists
Figure 11.2 Random walk frequencies
11.2.2 Histograms
260
11 Vectors as arrays & advanced data structures
11.3 *Sorting
11.3.1 Bubble Sort
261
Essential MATLAB for Engineers and Scientists
Table 11.1 Memory during a Bubble Sort
1st pass 2nd pass 3rd pass 4th pass
: 27/13 13/9 9/5 5/3
: 13/27/9 9/13/5 5/9/3 3/5
: 9/27/5 5/13/3 3/9 9
: 5/27/3 3/13 13 13
: 3/27 27 27 27
4 tests 3 tests 2 tests 1 test

>
+
+
>
+

+ + + + = /
/

262
11 Vectors as arrays & advanced data structures
11 Vectors as arrays & advanced data structures
265
11 Vectors as arrays & advanced data structures
11.5 *Cell arrays
11.5.1 Assigning data to cell arrays
267
Essential MATLAB for Engineers and Scientists
11.5.2 Accessing data in cell arrays
268
Essential MATLAB for Engineers and Scientists
Figure 11.3 Result of
11.5.4 Displaying and visualizing cell arrays
11.6 *Classes and objects
270
11 Vectors as arrays & advanced data structures
S u m m a r y
271
12
*More graphics
The objectives of this chapter are to introduce you to:
Handle Graphics;
editing plots;
animation;
saving and exporting graphs;
color, lighting and the camera.
12.1 Handle Graphics
12 More graphics
Figure 12.1 Parentchild relationships of Handle Graphics objects (from top to bottom)
12.1.1 Getting handles
273
Essential MATLAB for Engineers and Scientists
12.1.2 Graphics object properties and how to change them
274
12 More graphics
275
12 More graphics

Figure 12.2 Result of manipulating a gure using the handles of axes children
12.1.4 Graphics object creation functions
12.1.5 Parenting
277
12 More graphics
12.2 Editing plots
12.2.1 Plot edit mode
279
Essential MATLAB for Engineers and Scientists
12.2.2 Property Editor
280
12 More graphics
12.3 Animation
281
12 More graphics
=
=

.
283
12 More graphics
12.4 Color etc.
12.4.1 Colormaps
285
12 More graphics
12.4.2 Color of surface plots

= = =
= = =
287
Essential MATLAB for Engineers and Scientists
12.4.3 Truecolor
12.5 Lighting and camera
288
12 More graphics
12.6 Saving, printing and exporting graphs
12.6.1 Saving and opening gure les
289
Essential MATLAB for Engineers and Scientists
12.6.2 Printing a graph
12.6.3 Exporting a graph
290
12 More graphics
S u m m a r y
291
13
*Graphical User
Interfaces (GUIs)
The objectives of this chapter are to introduce you to the basic concepts involved
in writing your own graphical user interfaces, including:
Figure les.
Application M-les.
Callback functions.
13.1 Basic structure of a GUI
13 Graphical User Interfaces (GUIs)
13.2 A rst example: getting the time
293
Essential MATLAB for Engineers and Scientists
Figure 13.1 Click the button to see the time
Figure 13.2 GUIDE Layout Editor
294
Essential MATLAB for Engineers and Scientists
296
13 Graphical User Interfaces (GUIs)
13.2.1 Exercise
13.3 Newton again
Figure 13.3 Square roots with Newtons method.
297
Essential MATLAB for Engineers and Scientists
298
13 Graphical User Interfaces (GUIs)
299
Essential MATLAB for Engineers and Scientists
300
13 Graphical User Interfaces (GUIs)
13.4 Axes on a GUI
Figure 13.4 Axes on a GUI.
301
Essential MATLAB for Engineers and Scientists
13.5 Adding color to a button
302
14
Dynamical systems
The objective of this chapter is to discuss the importance of learning to use tools
like MATLAB. MATLAB and companion toolboxes provide engineers, scientists,
mathematicians, and students of these elds with an environment for technical
computing applications. It is much more than a programming language like C,
C++ or Fortran. Technical computing includes mathematical computation, anal-
ysis, visualization, and algorithm development. The MathWork website describes
The Power of Technical Computing with MATLAB as follows:
Whatever the objective of your workan algorithm, an analysis, a graph,
a report, or a software simulationtechnical computing with MATLAB
lets you work more effectively and efciently. The exible MATLAB envi-
ronment lets you perform advanced analyses, visualize data, and develop
algorithms by applying the wealth of functionality available. With its more
than 1000 mathematical, statistical, scientic and engineering functions,
MATLAB gives you immediate access to high-performance numerical com-
puting. This functionality is extended with interactive graphical capabilities
for creating plots, images, surfaces, and volumetric representations.
The advanced toolbox algorithms enhance MATLABs functionality in
domains such as signal and image processing, data analysis and statis-
tics, mathematical modeling, and control design. Toolboxes are col-
lections of algorithms, written by experts in their elds, that provide
application-specic numerical, analysis, and graphical capabilities. By
relying on the work of these experts, you can compare and apply a number
of techniques without writing code. As with MATLAB algorithms, you can
customize and optimize toolbox functions for your project requirements.
Essential MATLAB for Engineers and Scientists
308
Essential MATLAB for Engineers and Scientists

Figure 14.1 Deection of a cantilever beam. The vertical deection of a uniformly loaded
cantilever beam
= /
310
Essential MATLAB for Engineers and Scientists
+ = .
=

.
312
14 Dynamical systems
Figure 14.2 Example of a circuit problem. Exponential approach to steady current condition
of a simple circuit with an instantaneously applied constant voltage
313
Essential MATLAB for Engineers and Scientists
14.3 Free fall
=
=
= = = = =
=
= = = =




=




.
= =

= =

= ( / ) .
= = =
314
Essential MATLAB for Engineers and Scientists
316
14 Dynamical systems
= .
317
14 Dynamical systems
319
Essential MATLAB for Engineers and Scientists
Figure 14.5 Comparison of free-fall distance. Speed: Exact is the line, circles are for the
nite-difference approximate solution
320
14 Dynamical systems
=
= +

+ +

+
+ +
+ +
+
+ +
/

=
+ +
.
+ +

+ +
=
321
Essential MATLAB for Engineers and Scientists
322
14 Dynamical systems
\
14.4 Projectile with friction
= /
= /
/ =

+
/ =

+ .
= =

323
Essential MATLAB for Engineers and Scientists
324
14 Dynamical systems
\
= .
325
Essential MATLAB for Engineers and Scientists
S u m m a r y
326
14 Dynamical systems
E X E R C I S E S
= .
= .
327
15
Simulation
The objective of this chapter is to introduce you to:
Simulation of real-life events.
15.1 Random number generation
<
15 Simulation
15.1.1 Seeding

15.2 Spinning coins


329
Essential MATLAB for Engineers and Scientists
15.3 Rolling dice
330
15 Simulation

S u m m a r y
E X E R C I S E S

337
16
*More matrices
The objectives of this chapter are to demonstrate the use of matrices in a number
of application areas, including:
Population dynamics.
Markov processes.
Linear equations.
And to introduce:
MATLABs sparse matrix facilities.
16.1 Leslie matrices: population growth
+
Essential MATLAB for Engineers and Scientists
=
= =
= /
= .
+
+
+
+ = +
+ =
+ = .

+
=

+ =

/
/

342
Essential MATLAB for Engineers and Scientists

Figure 16.1 Total rabbit population over 15 months


344
16 More matrices
16.2 Markov processes
16.2.1 A random walk
345
Essential MATLAB for Engineers and Scientists
+
+ = / + / .
+ = .
346
16 More matrices
347
Essential MATLAB for Engineers and Scientists
16.3 Linear equations
+ =
+ + =
= .
=

= .
348
16 More matrices
=

16.3.1 MATLABssolution
= = =

349
16 More matrices

=


=

.
353
Essential MATLAB for Engineers and Scientists
16.4 Sparse matrices
.: .) [ >: {[[ :{_a_][.[a//)H)//[[` [[{_,a//[{ ])]//,_[]//{.)]//_//{.)[` [/[{//a/[{ [[ a,_./.. [{ >)_./).[ .[.): [).):)[)@.[
[ {){.:
.):[@ :{ :).:[@
{]):[{ { {]):.))] :
.):_ >:[ : .: ..[ : :{: .[: .): _). .) { [{ [): _). ..
16 More matrices
E X E R C I S E S
+ =
+ + =
=
+ . = .
. + . = .
= =
357
17
*Introduction to
numerical methods
The objectives of this chapter are to introduce numerical methods for:
Solving equations.
Evaluating denite integrals.
Solving systems of ordinary differential equations.
Solving a parabolic partial differential equation.
17.1 Equations
=
17.1.1 Newtons method
Essential MATLAB for Engineers and Scientists
f x
k
f x
k
x
k
x
k
Figure 17.1 Newtons method
+

/
+
+
=

.
|

/ | =
+
= /

+ +
+ =
360
Essential MATLAB for Engineers and Scientists
. .
17.1.2 The Bisection method
=
= + .
<
= = = =
= + / .
= =
=| |/
362
17 Introduction to numerical methods
x
M
x
R
f x
x
L
Figure 17.3 The Bisection method
=| |/ .
| |/ <
>
| |/
>
=
363
Essential MATLAB for Engineers and Scientists
=
+ =
17.1.3
+
17.1.4
+
17.2 Integration
364
17 Introduction to numerical methods
17.4 First-order differential equations
17.4.1 Eulers method
/ = .
/
+
= .
+ = + .
369
Essential MATLAB for Engineers and Scientists
= =
=
= /
=
+
= +
+
= +
=
17.4.2 Example: bacteria growth
= .
/ = =
= .
+
= +
=
370
17 Introduction to numerical methods
= .
17.4.3 Alternative subscript notation
=
371
17 Introduction to numerical methods

Figure 17.5 Bacteria growth: (a) Eulers method; (b) the exact solution
17.4.4 A predictor-corrector method
/ =
373
Essential MATLAB for Engineers and Scientists
17.6.2 Systems of differential equations: chaos
/ =
/ = +
/ = / .
376
Essential MATLAB for Engineers and Scientists

y
t
t
Figure 17.6 Chaos?
.
378
Essential MATLAB for Engineers and Scientists
Figure 17.7 Lotka-Volterra model: (a) predator; (b) prey
/ =
/ =
= . = . = . = = =
380
17 Introduction to numerical methods
+ = + .
+ = . + .
+ = . + .
+ = . + .
+ = . + . .

.
.
.
.
.

.
=
= .
=

. . .

.
= .
= /
383
Essential MATLAB for Engineers and Scientists
\
384
17 Introduction to numerical methods
y
x
x
Figure 17.8 A cubic polynomial t
17.8 Other numerical methods
385
Essential MATLAB for Engineers and Scientists
S u m m a r y
E X E R C I S E S
386
17 Introduction to numerical methods

Figure 17.9 A trajectory of Van der Pols equation


=
= =
389
A p p en d ix A Syntax quick reference
A.4 and
391
Essential MATLAB for Engineers and Scientists
A.5 and
392
A p p en d ix A Syntax quick reference
A.6 Input/output
\
\
\
\
\
\
A.7 /
A.8 Vectors and matrices
393
Appendix B
Operators
Table B.1 Operator precedence (see Help on )
Precedence Operators
1.
2. (pure transpose)
3. (unary plus) (unary minus) (NOT)
4. \ \
5. (addition) (subtraction)
6.
7.
8. (AND)
9. (OR)
Appendix C
Command and functionquick
reference
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
Essential MATLAB for Engineers and Scientists
C.1.4 Controlling the Command Window
C.1.5 Starting and quitting MATLAB
C.2 Logical functions
C.3 Language constructs and debugging
C.3.1 MATLAB as a programming language
398
Essential MATLAB for Engineers and Scientists
C.4.3 Time and date
C.4.4 Matrix manipulation

C.4.5 Specialized matrices


C.5 Mathematical functions
400
A p p en d ix C Command and functionquick reference
C.6 Matrix functions
401
Essential MATLAB for Engineers and Scientists
C.13.2 3-D
C.13.3 General
404
Appendix D
ASCII character codes
Code Char Code Char Code Char Code Char Code Char

A p p en d ix E Solutions to selected exercises


= =
= =
= / = /
Chapter 4
411
Essential MATLAB for Engineers and Scientists
Chapter 5
412
A p p en d ix E Solutions to selected exercises
Chapter 7
Chapter 8
413
Essential MATLAB for Engineers and Scientists
414
A p p en d ix E Solutions to selected exercises
Chapter 9
Chapter 10
415
Essential MATLAB for Engineers and Scientists
Chapter 15
416
A p p en d ix E Solutions to selected exercises
Chapter 16
417
Essential MATLAB for Engineers and Scientists
Chapter 17
. .
. . .
.
/ =
/ = .
= .
= .
=
418
Index
422
Index
423
Index
Index

427
Index
428

You might also like