Numerical Methods 4th Edition George Lindfield John Penny

yahyalofte29 8 views 80 slides May 14, 2025
Slide 1
Slide 1 of 80
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80

About This Presentation

Numerical Methods 4th Edition George Lindfield John Penny
Numerical Methods 4th Edition George Lindfield John Penny
Numerical Methods 4th Edition George Lindfield John Penny


Slide Content

Numerical Methods 4th Edition George Lindfield
John Penny download
https://ebookbell.com/product/numerical-methods-4th-edition-
george-lindfield-john-penny-49535014
Explore and download more ebooks at ebookbell.com

Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Numerical Methods For Atmospheric And Oceanic Sciences 1st A
Chandrasekar
https://ebookbell.com/product/numerical-methods-for-atmospheric-and-
oceanic-sciences-1st-a-chandrasekar-45443620
Numerical Methods For Atmospheric And Oceanic Sciences 1st Edition A
Chandrasekar
https://ebookbell.com/product/numerical-methods-for-atmospheric-and-
oceanic-sciences-1st-edition-a-chandrasekar-46254960
Numerical Methods For Mixed Finite Element Problems Applications To
Incompressible Materials And Contact Problems Jean Deteix
https://ebookbell.com/product/numerical-methods-for-mixed-finite-
element-problems-applications-to-incompressible-materials-and-contact-
problems-jean-deteix-46255668
Numerical Methods In Environmental Data Analysis Moses Eterigho
Emetere
https://ebookbell.com/product/numerical-methods-in-environmental-data-
analysis-moses-eterigho-emetere-46454868

Numerical Methods For Scientific Computing Kyle Novak
https://ebookbell.com/product/numerical-methods-for-scientific-
computing-kyle-novak-46510692
Numerical Methods For Solving Discrete Event Systems With Applications
To Queueing Systems Winfried Grassmann
https://ebookbell.com/product/numerical-methods-for-solving-discrete-
event-systems-with-applications-to-queueing-systems-winfried-
grassmann-47165896
Numerical Methods Using Kotlin For Data Science Analysis And
Engineering Haksun Li
https://ebookbell.com/product/numerical-methods-using-kotlin-for-data-
science-analysis-and-engineering-haksun-li-47474922
Numerical Methods For Twophase Incompressible Flows Arnold Reusken
https://ebookbell.com/product/numerical-methods-for-twophase-
incompressible-flows-arnold-reusken-47988682
Numerical Methods For Engineers And Scientists Amos Gilat Vish
Subramaniam
https://ebookbell.com/product/numerical-methods-for-engineers-and-
scientists-amos-gilat-vish-subramaniam-48489698

Numerical Methods And Implementation In Geotechnical Engineering Part
1 Ym Cheng
https://ebookbell.com/product/numerical-methods-and-implementation-in-
geotechnical-engineering-part-1-ym-cheng-48746238

NumericalMethods
UsingMATLAB
®

NumericalMethods
UsingMATLAB
®
Fourth Edition
George Lindfield
Aston University, School of Engineering and Applied Science,
Birmingham, England, United Kingdom
John Penny
Aston University, School of Engineering and Applied Science,
Birmingham, England, United Kingdom

Academic Press is an imprint of Elsevier
125 London Wall, London EC2Y 5AS, United Kingdom
525 B Street, Suite 1650, San Diego, CA 92101, United States
50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States
The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom
Copyright © 2019 Elsevier Inc. All rights reserved.
M
ATLAB
®
is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks does not warrant the accuracy of the
text or exercises in this book. This book’s use or discussion of M
ATLAB
®
software or related products does not constitute endorsement
or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the M
ATLAB
®
software.
No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including
photocopying, recording, or any information storage and retrieval system, without permission in writing from the publisher. Details on
how to seek permission, further information about the Publisher’s permissions policies and our arrangements with organizations such as
the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our website:www.elsevier.com/permissions.
This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may be noted
herein).
Notices
Knowledge and best practice in this field are constantly changing. As new research and experience broaden our understanding, changes
in research methods, professional practices, or medical treatment may become necessary.
Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any information,
methods, compounds, or experiments described herein. In using such information or methods they should be mindful of their own safety
and the safety of others, including parties for whom they have a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any injury and/or
damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods,
products, instructions, or ideas contained in the material herein.
Library of Congress Cataloging-in-Publication Data
A catalog record for this book is available from the Library of Congress
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library
ISBN: 978-0-12-812256-3
For information on all Academic Press publications
visit our website athttps://www.elsevier.com/books-and-journals
Publisher:Katey Birtcher
Acquisition Editor:Steve Merken
Editorial Project Manager:Peter Jardim / Michael Lutz
Production Project Manager:Sruthi Satheesh
Designer:Matthew Limbert
Typeset by VTeX

This book is for my wife Zena. With tolerance and patience,
she has supported and encouraged me for many years
and for our grown up children Katy and Helen.
George Lindfield
This book is for my wife Wendy, for her patience, support and
encouragement, and for our grown up children, Debra, Mark and Joanne.
Also to our cat Jeremy who provided me with company
whilst I worked on this book.
John Penny

List of Figures
Fig. 1.1 Superimposed graphs obtained usingplot(x,y)andholdstatements. 30
Fig. 1.2 Plot ofy=sin(x
3
)using 51 equispaced plotting points. 31
Fig. 1.3 Plot ofy=sin(x
3
)using the functionfplotto choose plotting points adaptively. 31
Fig. 1.4 Function plotted over the range from−4to4.Ithasamaximumvalueof4 ×10
6
.3 2
Fig. 1.5 The same function as plotted in Fig.1.4but with a limit on the range of they-axis. 32
Fig. 1.6 An example of the use of the
subplotfunction. 33
Fig. 1.7
polarandcompassplots showing the roots ofx
5
−1=0. 34
Fig. 1.8 Polar scatter plots. Left diagram with default size circle markers. Right diagram with larger
filled black circles. 35
Fig. 1.9 Polar scatter histogram. 35
Fig. 1.10 Three-dimensional surface using default view. 37
Fig. 1.11 Three-dimensional contour plot. 37
Fig. 1.12 Filled contour plot. 37
Fig. 1.13 Implicit quadrafolium and folium of Descartes. 38
Fig. 1.14 Plots illustrating aspects of handle graphics. 41
Fig. 1.15 Plot of functions shown in Fig.1.14illustrating further handle graphs features. 42
Fig. 1.16 Plot of cos( 2x). The axes of the right-hand plot are enhanced using handle graphics.43
Fig. 1.17 Plot of(ω
2+x)
2
αcos(ω 1x).44
Fig. 2.1 Electrical network. 74
Fig. 2.2 Three intersecting planes representing three equations in three variables. (A) Three plane
surfaces intersecting in a point. (B) Three plane surfaces intersecting in a line. (C) Three plane
surfaces, two of which do not intersect. (D) Three plane surfaces intersecting in three lines. 77
Fig. 2.3 Planes representing an under-determined system of equations. (A) Two plane surfaces
intersecting in a line. (B) Two plane surfaces which do not intersect. 80
Fig. 2.4 Planes representing an over-determined system of equations. (A) Four plane surfaces
intersecting in a point. (B) Four plane surfaces intersecting in a line. (C) Four plane surfaces not
intersecting at a single point. Point of intersection of (S1, S2, S3) and (S1, S2, S4) are visible.
(D) Four plane surfaces representing inconsistent equations. 81
Fig. 2.5 Plot of an inconsistent equation system (2.30). 110
Fig. 2.6 Plot of inconsistent equation system (2.30) showing the region of intersection of the equations,
where + indicates “best” solution. 112
Fig. 2.7 Effect of minimum degree ordering on LU decomposition. The
spyfunction shows the matrix,
the ordered matrix, and LU decomposition with and without preordering. 125
Fig. 2.8 Mass-spring system with three degrees of freedom. 128
Fig. 2.9 Connections of different strengths between five pages of the internet. 150
Fig. 3.1 Solution ofx=exp(−x/c). Results from the function
fzeroare indicated by o and those from
the Armstrong and Kulesza formula by +. 158
Fig. 3.2 Plot of the functionf(x)=(x−1)
3
(x+2)
2
(x−3). 159
Fig. 3.3 Plot off(x)=exp(−x/10)sin(10x). 159
xiii

xiv List of Figures
Fig. 3.4 Iterates in the solution of(x−1)(x−2)(x−3)=0 from close but different starting points. 163
Fig. 3.5 Geometric interpretation of Newton’s method. 165
Fig. 3.6 Plot ofx
3
−10x
2
+29x−20=0 with the iterates of Newton’s method shown by o. 167
Fig. 3.7 Plot showing the complex roots of cos(x) −x=0. 168
Fig. 3.8 Plot of the iterates for five complex initial approximations for the solution of cos(x) −x=0
using Newton’s method. Each iterate is shown by◦. 168
Fig. 3.9 The cursor is shown close to the position of the root. 172
Fig. 3.10 Plot of graphf(x)=sin(1/x). This plot is spurious in the range±0.2. 172
Fig. 3.11 Plot of system (3.30). Intersections show roots. 182
Fig. 4.1 A log–log plot showing the error in a simple derivative approximation. 192
Fig. 4.2 Simpson’s rule, using a quadratic approximation over two intervals. 197
Fig. 4.3 Plots of functions defined by (4.41), (4.42), and (4.43). 221
Fig. 4.4 Function sin(1/x)in the rangex=2×10
−4
to 2.05×10
−4
. Nineteen cycles of the function
are displayed. 224
Fig. 4.5 Graph ofz=y
2
sinx. 227
Fig. 5.1 Exact o and approximate + solution fordy/dt=−0.1(y−10). 240
Fig. 5.2 Geometric interpretation of Euler’s method. 241
Fig. 5.3 Points from the Euler solution ofdy/dt=y−20 given thaty=100 whent=0. Approximate
solutions forh=0.2, 0.4, and 0.6 are plotted using o, +, and ∗respectively. The exact solution
is given by the solid line. 242
Fig. 5.4 Absolute errors in the solution ofdy/dt=ywherey=1whent =0, using Euler’s method
withh=0.1. 244
Fig. 5.5 Relative errors in the solution ofdy/dt=ywherey=1whent =0, using Euler’s method with
h=0.1. 244
Fig. 5.6 Solution ofdy/dt=yusing Euler (∗) and trapezoidal method, o. Steph=0.1andy
0=1at
t=0. 246
Fig. 5.7 Solution ofdy/dt=−y.The∗ represents Butcher’s method, + Merson’s method, and o the
classical method. 251
Fig. 5.8 Absolute error in solution ofdy/dt=−2yusing the Adams–Bashforth–Moulton method. The
solid lineplots the errors with a step size of 0.5. Thedot-dashed lineplots the errors with step
size 0.7. 253
Fig. 5.9 Relative error in the solution ofdy/dt=ywherey=1whent=0, using Hamming’s method
with a step size of 0.5. 255
Fig. 5.10 Solution of Zeeman’s model withp=1 and accuracy 0.005. The solid line representssand the
dashed line representsx. 261
Fig. 5.11 Solution of Zeeman’s model withp=20 and accuracy 0.005. Thesolid linerepresentssand
thedashed linerepresentsx. 261
Fig. 5.12 Sections of the cusp catastrophe curve in Zeeman’s model forp=0:10:40. 262
Fig. 5.13 Variation in the population of lynxes (dashed line ) and hares (solid line) against time, beginning
with 5000 hares and 100 lynxes. Accuracy 0.005. 263
Fig. 5.14 Graph showing the three coordinate responses of a mass-spring-damper system, shown by full
lines, when excited by a half sine pulse, shown by a dotted line. 270
Fig. 5.15 Plot showing the difference between the Newmark and 4th-order Runge–Kutta method
solutions for the three coordinates. 270

List of Figuresxv
Fig. 5.16 Solution of Lorenz equations forr=126.52,s=10, andb=8/3 using an accuracy of
0.000005 and terminating att=8. 272
Fig. 5.17 Solution of Lorenz equations where each variable is plotted against time. Conditions are the
same as those used to generate Fig.5.16. Note the unpredictable nature of the solutions. 272
Fig. 5.18 Solution of Lorenz equations forr=28,s=10, andb=8/3. Initial conditionsx=[555]
shown by the full line, andx=[5.0091 4.9997 5.0060] shown by the dashed line. Note the
sudden divergence of the two solutions from each other and unpredictable nature of the
solutions. 273
Fig. 5.19 Solution of Lorenz equations forr=28,s=10, andb=8/3. The full line shows the solution
using the default accuracy of the M
ATLABRunge–Kutta 4/5 function. The dashed line shows a
higher accuracy solution. Note the sudden divergence of the two solutions from each other and
unpredictable nature of the solutions. 273
Fig. 5.20 Case 1: The full line is the output from Duffing oscillator.ω=100 rad/s (15.92 Hz). Zero initial
conditions. The dashed line is the input force, arbitrarily scaled in amplitude. 275
Fig. 5.21 Output from Duffing oscillator.ω=120 rad/s. Full line gives output with zero initial conditions.
Dashed line give output with an initial displacement of 1 mm and an initial velocity of 1 m/s. 275
Fig. 5.22 Output from Duffing oscillator.ω=120 rad/s. Solution with zero initial velocity and initial
displacements of 1, 1.001, and 1.002 mm. (Shown by full, dashed and dot-dashed lines
respectively.) 276
Fig. 5.23 Output from Duffing oscillator. Phase plane plot.ω=120 rad/s. 276
Fig. 5.24 Poincaré map showing output from Duffing oscillator.ω=120 rad/s. 277
Fig. 5.25 Output from Duffing oscillator showing where points from two solutions lie on a Poincaré map.
+ and o indicate points generated from two different initial conditions withω=120 rad/s. 277
Fig. 5.26 Plot of sigmoid functionV=(1+tanhu)/2. 278
Fig. 5.27 Neural network finds the binary equivalent of 5 using 3 neurons and an accuracy of 0.005. The
three curves show the convergence to the binary digits 1, 0, and 1. 280
Fig. 5.28 Relative error in the solution ofdy/dt=yusing Hermite’s method. Initial conditiony=1
whent=0 and a step of 0.5. 284
Fig. 5.29 Model of a second-order differential equation, (5.62). 289
Fig. 5.30 Model of a second-order differential equation with Coulomb damping. 290
Fig. 5.31 A second-order system modeled by a transfer function. 290
Fig. 5.32 Model of Van der Pol’s equation. 291
Fig. 5.33 Model of a pair of simultaneous ordinary differential equations. 292
Fig. 5.34 Two simultaneous ordinary differential equations modeled in state space form.293
Fig. 5.35 Model to determine the root of a cubic equation. 294
Fig. 5.36 The Simulink model of Fig.5.35replaced by a single mask. 295
Fig. 6.1 Second-order differential equations with one or two independent variables and their solutions. 302
Fig. 6.2 Solutions ofx
2
(d
2
y/dx
2
)−6y=0 with initial conditionsy=1anddy/dx=swhenx=1,
for trial values ofs. 303
Fig. 6.3 Equispaced nodal points. 305
Fig. 6.4 Grid mesh in rectangular coordinates. 306
Fig. 6.5 Node numbering used in the solution of (6.15). 307
Fig. 6.6 Finite difference solution of(1+x
2
)(d
2
z/dx
2
)+xdz/dx−z=x
2
.The◦ indicates the finite
difference estimate; the continuous line is the exact solution. 310

xvi List of Figures
Fig. 6.7 Node numbering used in the solution of (6.17). 311
Fig. 6.8 The finite difference estimates for the first and second eigenfunctions of
x(d
2
z/dx
2
)+dz/dx+λz/x=0, denoted by a∗and a◦respectively: solid lines show the
exact eigenfunctionsz
0(x)andz 1(x). 312
Fig. 6.9 Plot shows how the distribution of temperature through a wall varies with time.316
Fig. 6.10 Variation in the temperature in the center of a wall. The steadily decaying solution denote by the
solid line was generated using the implicit method of solution; the temperatures computed by
the explicit method of solution are denoted by◦. Note how the explicit method of solution gives
temperatures that are oscillating and diverging with time. 316
Fig. 6.11 Solution of (6.29) subject to specific boundary and initial conditions. 319
Fig. 6.12 Temperature distribution around a plane section. Nodes 1 and 2 are shown. 320
Fig. 6.13 Finite difference estimate for the temperature distribution for the problem defined in Fig.6.12. 324
Fig. 6.14 Deflection of a square membrane subject to a distributed load. 324
Fig. 6.15 Finite difference approximation of the second mode of vibration of a uniform rectangular
membrane. 325
Fig. 7.1 Increasing the degree of the polynomial to fit the given data. (A) 1st degree; (B) 2nd degree;
(C) 3rd degree; (D) 4th degree. 331
Fig. 7.2 Use of splines to define cross-sections of a ship’s hull. 334
Fig. 7.3 Spline fit to the data of Table7.1denoted by o. 336
Fig. 7.4 Thesolid curveshows the functiony=2{1+tanh(2x)}−x/10. Thedashed lineshows an
eighth-degree polynomial fit; thedotted lineshows a spline fit. 336
Fig. 7.5 Fitting a cubic polynomial to data. Data points are denoted by o. 350
Fig. 7.6 Fitting third- and fifth-degree polynomials (that is, a full and a dashed line, respectively) to a
sequence of data. Data points are denoted by o. 353
Fig. 7.7 Polynomials of degree 4, 8, and 12 attempting to fit a sequence of data indicated by o in the
graph. 354
Fig. 7.8 Data sampled from the functiony=sin[1/(x+0.2)]+0.2x. Data points denoted by o. 356
Fig. 7.9 Fittingy=a
1e
a2x
+a3e
a4x
to data values indicated by◦. 358
Fig. 7.10 Fitting transformed data, denoted by “o” to a quadratic function. 360
Fig. 7.11 Fitting (7.15) to the given data denoted by o. 360
Fig. 7.12 The graph shows the original data, denoted by o, and the fits obtained fromy=be
ax
shown by
the full line andy=ax
b
shown by the dotted line. 362
Fig. 7.13 Changes in the height of a projectile over the time of fight. Graph shows the path of the
projectile without noise as the dashed line, the observed values including noise as asterisks and
the path generated by the Kalman filter as the continuous line. 371
Fig. 7.14 Considerably expanded graph of the height of projectile over time of flight showing
observations subject to noise by asterisks, the dashed line of the flight of the projectile subject
only to laws of dynamics and the output of the Kalman filter after processing the noisy data. 371
Fig. 7.15 Relationship between selected variables. Dashed line is generated using only the first principal
component. 377
Fig. 7.16 Relationship between selected variables. Dashed line is generated using only the first and
second principal component. 377
Fig. 8.1 Numbering scheme for data points. 385

List of Figuresxvii
Fig. 8.2 Graph shows the relationship between a signal frequency and its component in the DFT. Thus,
for example, a signal frequency of twice Nyquist frequency, 2f
max, will give a component of
zero frequency in the DFT. 386
Fig. 8.3 Stages in the FFT algorithm. 390
Fig. 8.4 Plots of the real and imaginary part of the DFT. 392
Fig. 8.5 Frequency spectra. 393
Fig. 8.6 The top graph shows the data in the time domain and the bottom graph shows the corresponding
frequency spectrum. Note frequency components at 20, 50, and 70 Hz. 394
Fig. 8.7 The top graph shows the data in the time domain and the bottom graph shows the corresponding
frequency spectrum. Note that due to aliasing, frequency components are at 20, approximately
32.4 and 50 Hz. 395
Fig. 8.8 Spectrum of a sequence of data. 398
Fig. 8.9 Plot of datayagainst time, in seconds. The dashed line is the envelope derived from the
absolute value of the analytic data. 404
Fig. 8.10 A three-dimensional plot of the real and imaginary parts of the analytic data against time, in
seconds, showing an exponentially decaying spiral. 404
Fig. 8.11 Plot of frequency, in Hz, derived from the Hilbert transform, against time, in seconds. The
dashed line is the exact frequency. 404
Fig. 8.12 Fourier transform of the data, showing a spectrum between 0.5 Hz and 1.5 Hz, but the transform
gives no information about the variation of frequency with time. 404
Fig. 8.13 Original data is shown in the first plot in the left column. The remaining plots are of the first 5
intrinsic mode functions derived from it. 406
Fig. 8.14 Plot of the original data over the interval fromt=14.5 s to 16.5 s and data points reconstructed
from the first and second intrinsic mode functions indicated by◦. Note the very close agreement. 406
Fig. 8.15 Plot showing the variation with time of the frequency components. The full lines are data from
the intrinsic mode functions. The dashed lines are the actual frequency components.406
Fig. 8.16 Plot showing the variation with time of the amplitude of the frequency components. The full
lines are data from the intrinsic mode functions The dashed lines are the actual amplitudes of
the frequency components. 406
Fig. 8.17 Fourier transform of the data of Example8.5. Note that this plot gives no information about the
variation of frequency with time. 407
Fig. 8.18 Walsh functions in the ranget=0 to 1, in ascending sequency order from WAL(0,t ), with no
zero crossings to WAL(7,t) with seven zero crossings. 408
Fig. 8.19 Upper figure shows plot of time series. Lower figure shows power sequency spectrum of the
time series. 413
Fig. 8.20 Plots show the coefficients of CAL and SAL sequency spectrum for the time series shown in
Fig.8.19. 413
Fig. 8.21 Diagram showing the partitioning of the time–frequency plane in the DWT. 417
Fig. 8.22 The Haar wavelets in ascending order fromψ(0,t)toψ(7,t)over the range 0<t<1. 417
Fig. 8.23 Flow diagram for the fast Haar transform. Data carried by a dashed line entering a node is
negated and added to the data carried by the full line entering a node. 418
Fig. 8.24 Decomposition ofx(t)into a constant term and 6 levels of Haar wavelets. 420
Fig. 8.25 Reconstruction ofx(t)from its Haar wavelet components. Adding the constant term (Level−1)
and all the Haar wavelets from Level 0 to Level 5 together provides and exact reconstruction
x(t). 420

xviiiList of Figures
Fig. 8.26 Contour plot of DWT of signal defined by (8.66), a composition of square waves. Responses
can be clearly seen at levels 5, 3, and 8. 422
Fig. 8.27 Contour plot of DWT of signal defined by (8.67), a composition of sine waves. Responses can
be observed at levels 5, 3, and 8. 423
Fig. 8.28 Contour plot of DWT of signal comprising bursts of exponentially decaying components,
(8.68). Response at levels 5 (att=3.2), 8 (att=6.4), 7 (att=11.2), 9 (att=17.6), and 3 (at
t=19.2) can be observed. 424
Fig. 8.29 Plots of the wavelets db2, db4, db8, and db16. 424
Fig. 8.30 Plots of the real and imaginary parts of the Morlet wavelet. The mother wavelet in the middle of
the plot witha=1andb=0, that is, the wavelet is neither dilated nor shifted. The wavelet at
the right of the plot is the wavelet shifted byb=7 but it is not dilated. The wavelet at the left of
the plot is both shifted byb=−7 and dilated bya=1/4. 426
Fig. 8.31 Ricker wavelet. 427
Fig. 8.32 Contour plot of the CWT of the signal defined by (8.72). Note that the frequency (Hz) =2
L
whereLis the level. The burst of energy can be seen at levels−2, 0, 2, 4, and 5, thus
corresponding to frequencies of 0.25, 1, 4, 16, and 32 Hz, respectively. 428
Fig. 8.33 Contour plot of the CWT for Eq. (8.73). Note that the frequency (Hz)=2
L
whereLis the level.
It is seen that one component of the signal clearly increases smoothly over the sampling time. 428
Fig. 9.1 Graphical representation of an optimization problem. Thedashed linerepresents the objective
function and thesolid linesrepresent the constraints. 436
Fig. 9.2 Graph of a function with a minimum in the range[x
axb]. 441
Fig. 9.3 A plot of the Bessel function of the second kind showing three minima. 443
Fig. 9.4 Three-dimensional plot of the Styblinski and Tang function. 448
Fig. 9.5 Contour plot of the Styblinski and Tang function, showing the location of four local minima.
The conjugate gradient algorithm has found the one in the lower left corner. The search path
taken by the algorithm is also shown. 448
Fig. 9.6 Graph showing the Styblinski–Tang function value for the final 40 iterations of the simulated
annealing algorithm. 461
Fig. 9.7 Contour plot of the Styblinski–Tang function. The final stages in the simulated annealing
process are shown. Note how these values are concentrated in the lower left corner, close to the
global minimum. 461
Fig. 9.8 Genetic algorithm. Each member of the population is represented by o. Successive generations
of the population concentrate toward the value 4 approximately. 464
Fig. 9.9 Contour plot of the Alpine 2 function showing the rapid convergence to the global maximum
using Differential Evolution. The bottom right contour plot is greatly expanded.471
Fig. 9.10 Graph showing the minimization of the negative of the Alpine 2 function in 4 variables. The
plots show the maximum, mean, and minimum values of the population for 200 generations of
the DE algorithm. The continuous line denotes the mean values and the dashed lines denote the
maximum and minimum values. Convergence is to the exact solution, shown by the horizontal
line. 472
Fig. 9.11 Graph showing the objective function and constraints for Example9.1. The four solutions are
also indicated. 476
Fig. 9.12 Graph of log
e
(x). 477

List of Figuresxix
Fig. 10.1 Plot of the Fresnel sine integral in the rangex=1tox=3. 500
Fig. 10.2 Symbolic solution and numerical solution indicated by +. 513
Fig. 10.3 The Fourier transform of a cosine function. 518
Fig. 10.4 The Fourier transforms of a “top-hat” function. 518

About the Authors
George Lindfieldis a former lecturer in the Department of Computer Science at Aston University and
is now retired. He taught courses in computer science and in optimization at bachelor- and master’s-
level. He has coauthored books on numerical methods and published many papers in various fields
including optimization. He is a member of the Institute of Mathematics, a Chartered Mathematician,
and a Fellow of the Royal Astronomical Society.
John Pennyis an Emeritus Professor in the School of Engineering and Applied Science at Aston
University, Birmingham. England. He is a former head of the Mechanical Engineering Department. He
taught bachelor- and master’s-level students in structural and rotor dynamics and related topics such as
numerical analysis, instrumentation, and digital signal processing. His research interests were in topics
in dynamics such as damage detection in static and rotating structures. He has published over 40 peer
reviewed papers. He is a Fellow of the Institute of Mathematics and its Applications and is a coauthor
of four text books.
xxi

Preface
Our primary aim in this text is unchanged from previous editions; it is to introduce the reader to a wide
range of numerical algorithms, explain their fundamental principles and illustrate their application. The
algorithms are implemented in the software package M
ATLABwhich is constantly being enhanced and
provides a powerful tool to help with these studies.
Many important theoretical results are discussed but it is not intended to provide a detailed and
rigorous theoretical development in every area. Rather, we wish to show how numerical procedures
can be applied to solve problems from many fields of application, and that the numerical procedures
give the expected theoretical performance when used to solve specific problems.
When used with care M
ATLABprovides a natural and succinct way of describing numerical algo-
rithms and a powerful means of experimenting with them. However, no tool, irrespective of its power,
should be used carelessly or uncritically.
This text allows the reader to study numerical methods by encouraging systematic experimentation
with some of the many fascinating problems of numerical analysis. Although M
ATLABprovides many
useful functions this text also introduces the reader to numerous useful and important algorithms and
develops M
ATLABfunctions to implement them. The reader is encouraged to use these functions to
produce results in numerical and graphical form. M
ATLABprovides powerful and varied graphics facil-
ities to give a clearer understanding of the nature of the results produced by the numerical procedures.
Particular examples are given throughout the text to illustrate how numerical methods are used to
study problems which include applications in the biosciences, chaos, neural networks, engineering,
and science.
It should be noted that the introduction to M
ATLABis relatively brief and is meant as an aid to the
reader. It can in no way be expected to replace the standard M
ATLABmanual or text books devoted to
M
ATLABsoftware. We provide a broad introduction to the topics, develop algorithms in the form of
M
ATLABfunctions and encourage the reader to experiment with these functions which have been kept
as simple as possible for reasons of clarity. These functions can be improved and we urge readers to
develop the ones that are of particular interest to them.
In addition to a general introduction to M
ATLAB, the text covers the solution of linear equations and
eigenvalue problems; methods for solving non-linear equations; numerical integration and differenti-
ation; the solution of initial value and boundary value problems; curve fitting including splines, least
squares, and Fourier analysis, topics in optimization such as interior point methods, non-linear pro-
gramming, and heuristic algorithms and, finally, we show how symbolic computing can be integrated
with numeric algorithms. Specifically in this 4th edition, descriptions and examples of some functions
recently added to M
ATLABsuch as implicit functions and the Live Editor are given in Chapter1.
Chapter4now includes a section on adaptive integration. Chapter5now includes a brief introduction
to Simulink; a toolbox which provides a visual interface to help the user simulating the process of
solving differential equations. The old Chapter 7 has been split into two chapters and we have added
the Kalman filter and principal component analysis, and the Hilbert, Walsh, and wavelet transforms.
The old Chapter 8 has had the emphasis on the genetic algorithm reduced and replaced by the more
modern and efficient differential evolution algorithm.
xxiii

xxivPreface
The text contains many worked examples, practice problems (some of which are new to this edition)
and solutions and we hope we have provided an interesting range of problems.
For readers of this book, additional materials, including all .m file scripts and functions listed in
the text, are available on the book’s companion site:https://www.elsevier.com/books-and-journals/
book-companion/9780128122563. For instructors using this book as a text for their courses, a solutions
manual is available by registering at the textbook site:www.textbooks.elsevier.com.
The text is suitable for undergraduate and postgraduate students and for those working in industry
and education. We hope readers will share our enthusiasm for this area of study. For those who do
not currently have access to M
ATLAB, this text still provides a general introduction to a wide range of
numerical algorithms and many useful and interesting examples and problems.
We would like to thank the many readers from all over the world for their helpful comments which
have enhanced this edition and we would be pleased to hear from readers who note errors or have
suggestions for improvements.
George Lindfield
John Penny
Aston University, Birmingham
March 2018

Acknowledgment
We thank Peter Jardim for his encouragement and support, Joe Hayton, the Publishing Director and the
production team members.
xxv

1
CHAPTER
AN INTRODUCTION TO MATLAB
®
Abstract
MATLAB
®
is a software package produced by The MathWorks, Inc. (http://www.mathworks.com) and
is available on systems ranging from personal computers to super-computers and including parallel
computing. In this chapter we aim to provide a useful introduction to M
ATLAB, giving sufficient back-
ground for the numerical methods we consider. The reader is referred to the M
ATLABmanual for a full
description of the package.
1.1THE SOFTWARE PACKAGE M ATLAB
MATLABis probably the world’s most successful commercial numerical analysis software and the
name M
ATLABis derived from the phrase “matrix laboratory”. It has evolved from some software writ-
ten by Cleve Moler in the late 1970s to allow his students to access matrix routines in the LINPACK
and EISPACK packages without the need to write FORTRAN programs. This first version of M
ATLAB
had only 80 functions, primitive graphics and “matrix” was the only data type. Its use spread to other
universities and, after it was reprogrammed in C, M
ATLABwas launched as a commercial product
in 1984. M
ATLABprovides an interactive development tool for scientific and engineering problems
and more generally for those areas where significant numeric computations have to be performed. The
package can be used to evaluate single statements directly or a list of statements called a script can
be prepared. Once named and saved, a script can be executed as an entity. The package was origi-
nally based on software produced by the LINPACK and EISPACK projects but in 2000, M
ATLABwas
rewritten to use the newer BLAS and LAPACK libraries for fast matrix operations and linear algebra,
respectively. M
ATLABprovides the user with:
1.Easy manipulation of matrix structures.
2.A vast number of powerful built-in routines which are constantly growing and developing.
3.Powerful two- and three-dimensional graphing facilities.
4.A scripting system which allows users to develop and modify the software for their own needs.
5.Collections of functions, called toolboxes, which may be added to the facilities of the core
M
ATLAB. These are designed for specific applications: for example neural networks, optimization,
digital signal processing, and higher-order spectral analysis.
It is not difficult to use M
ATLAB, although to use it with maximum efficiency for complex tasks
requires experience. Generally M
ATLABworks with rectangular or square arrays of data, the elements
of which may be real or complex. A scalar quantity is thus an array containing a single element.
This is an elegant and powerful notion but it can present the user with an initial conceptual difficulty.
A user schooled in many traditional computer languages is familiar with a pseudo-statement of the
form A=B+C and can immediately interpret it as an instruction that A is assigned the sum of the
Numerical Methods.https://doi.org/10.1016/B978-0-12-812256-3.00010-5
Copyright © 2019 Elsevier Inc. All rights reserved.
1

2 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
values stored in B and C. In MATLABthe variables B and C may represent arrays so thateach element
of the array A will become the sum of the values of corresponding elements of B and C; that is the
addition will follow the laws of matrix algebra.
There are several languages or software packages that have some similarities to M
ATLAB. These
packages include:
Mathematica and Maple.These packages are known for their ability to carry out complicated sym-
bolic mathematical manipulation but they are also able to undertake high precision numerical
computation. In contrast M
ATLABis known for its powerful numerical computational and ma-
trix manipulation facilities. However, M
ATLABalso provides an optional symbolic toolbox. This
is discussed in Chapter10.
Other Matlab-style languages.Languages such as Scilab,
1
Octave,
2
and Freemat
3
are somewhat
similar to M
ATLABin that they implement a wide range of numerical methods, and, in some
cases, use similar syntax to M
ATLAB.
It should noted that the languages do not necessarily have a range of toolboxes like M
ATLAB.
Julia.Julia
4
is a new high-level, high-performance dynamic programming language. The develop-
ers of Julia wanted, amongst other attributes, the speed of C, the general programming easy
of Python, and the powerful linear algebra functions and familiar mathematical notation of
M
ATLAB.
General purpose languages.General purpose languages such as Python and C. These languages
don’t have any significant numerical analysis capability in themselves but can load libraries of
routines. For example Python+Numpy, Python+Scipy, C+GSL.
The current M
ATLABrelease, version 9.4 (R2018a), is available on a wide variety of platforms.
Generally MathWorks releases an upgraded version of M
ATLABevery six months.
When M
ATLABis invoked it opens a command window. Graphics, editing, and help windows
may also be opened if required. Users can design their M
ATLABworking environment as they see fit.
M
ATLABscripts and function are generally platform independent and they can be readily ported from
one system to another. To install and start M
ATLAB, readers should consult the manual appropriate to
their particular working environment.
The scripts and functions given in this book have been tested under M
ATLABrelease, version
9.3.0.713579 (R2017b). However, most of them will work directly using earlier versions of M
ATLAB
but some may require modification.
The remainder of this chapter is devoted to introducing some of the statements and syntax of
M
ATLAB. The intention is to give the reader a sound but brief introduction to the power of MATLAB.
Some details of structure and syntax are omitted and must be obtained from the M
ATLABmanual. A de-
tailed description of M
ATLABis given by Higham and Higham (2017). Other sources of information
are the MathWorks website and Wikipedia. Wikipedia should be used with some care.
Before we begin a detailed discussion of the features of M
ATLAB, the meaning some terminology
needs clarification. Consider the terms M
ATLABstatements, commands, functions, and keywords. If
1
http://www.scilab.org.
2
http://www.gnu.org/software/octave.
3
http://freemat.sourceforge.net.
4
https://julialang.org/.

1.2MATRICES IN M ATLAB 3
we take a very simple MATLABexpression, likey = sqrt(x)then, if this is used in the command
window for immediate execution, it is a command for M
ATLABto determine the square root of the
variable
xand assign it toy. If it is used in a script, and is not for immediate execution, then it is
usually called a statement. The expression
sqrtis a MATLABfunction, but it can also be called a
keyword. The vast majority of M
ATLABkeywordsarefunctions, but a few are not: for example all,
long, andpi. The last of these is a reserved keyword to denote the mathematical constantπ. Thus, the
use of the four word discussed are often interchangeable. 1.2MATRICES IN M ATLAB
A two-dimensional array is effectively a table of data, not restricted to numeric data. If arrays are
stacked in the third dimension, then they are three-dimensional arrays. Matrices are two-dimensional
arrays that contain only numeric data or mathematical expressions where the variables of the expression
have already been assigned numeric values. Thus, 23.2 andx
2
are allowed,peteris allowed if it is a
numeric constant but not if it is a person’s name. Thus a two dimension array of numeric data can
legitimately be called an array or a matrix. Matrices can be operated on, using the laws of matrix
algebra. Thus ifAis a matrix, then 3A andA
−1
have a meaning, whereas, ifAis an alpha-numeric array
these statements have no meaning. M
ATLABsupports matrix algebra, but also allows array operations.
For example, an array of data might be a financial statement, and therefore, it might be necessary to
sum the 3rd through 5th rows and place the result in the 6th row. This is a legitimate array operation
that M
ATLABsupports.
The matrix is fundamental to M
ATLABand we have provided a broad and simple introduction to
matrices in AppendixA.InM
ATLABthe names used for matrices must start with a letter and may be
followed by any combination of letters or digits. The letters may be upper or lower case. Note that
throughout this text a distinctive font is used to denote M
ATLABstatements and output, for example
disp.
In M
ATLABthe arithmetic operations of addition, subtraction, multiplication, and division can be
performed in the usual way on scalar quantities, but they can also be used directly with matrices or
arrays of data. To use these arithmetic operators on matrices, the matrices must first be created. There
are several ways of doing this in M
ATLABand the simplest method, which is suitable for small ma-
trices, is as follows. We assign an array of values to
Aby opening thecommandwindow and then
typing
>> A = [1 3 5;1 0 1;5 0 9]
after the prompt>>. Notice that the elements of the matrix are placed in square brackets, each row
element separated by at least one space or comma. A semicolon (
;) indicates the end of a row and the
beginning of another. When the return key is pressed the matrix will be displayed thus:
A=
135
101
509

4 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
All statements are executed by pressing the return or enter key. Thus, for example, by typing
B = [1 3 51;2 6 12;10 7 28] after the>>prompt, and pressing the return key, we assign values
to
B. To add the matrices in thecommandwindow and assign the result to Cwe typeC = A+Band
similarly if we type
C = A-Bthe matrices are subtracted. In both cases the results are displayed row by
row in thecommandwindow. Note that terminating a M
ATLABstatement with a semicolon suppresses
any output.
For simple problems we can use thecommandwindow. By simple we mean M
ATLABstatements
of limited complexity – even M
ATLABstatements of limited complexity can provide some powerful
numerical computation. However, if we require the execution of an ordered sequence of M
ATLAB
statements (commands) then it is sensible for these statements to be typed in the MATLABeditor
window to create a script which must be saved under a suitable name for future use as required. There
will be no execution or output until the name of this script is typed into thecommandwindow and the
script executed by pressing return.
A matrix which has only one row or column is called a vector. A row vector consists of one row
of elements and a column vector consists of one column of elements. Conventionally in mathematics,
engineering, and science an emboldened upper case letter is usually used to represent a matrix, for
exampleA. An emboldened lower case letter usually represents acolumnvector, that isx. The transpose
operator converts a row to a column and vice versa so that we can represent a row vector as a column
vector transposed. Using the superscriptTin mathematics to indicate a transpose, we can write a row
vector asx
T
.InMATLABit is often convenient to ignore the convention that the initial form of a vector
is a column; the user can define the initial form of a vector as a row or a column.
The implementation of vector and matrix multiplication in M
ATLABis straightforward. Beginning
with vector multiplication, we assume that row vectors having the same number of elements have been
assigned to
dandp. To multiply them together we writex=d*p’ . Note that the symbol’transposes
the row
pinto a column so that the multiplication is valid. The result,x, is a scalar. Many practitioners
use
.’to indicate a transpose. The reason for this is discussed in Section1.4.
Assuming the two matrices
AandBhave been assigned, for matrix multiplication the user simply
types
C=A*B . This computesApost-multiplied byB, assigns the result toCand displays it, providing
the multiplication is valid. Otherwise M
ATLABgives an appropriate error indication. The conditions
for matrix multiplication to be valid are given in AppendixA. Notice that the symbol
*must be used
for multiplication because in M
ATLABmultiplication is not implied.
AveryusefulM
ATLABfunction iswhos(and the similar function,who).
These functions tell us the current content of the work space. For example, provided
A,B, andC
described above have not been cleared from the memory, then
>> whos
Name Size Bytes Class
A 3x3 72 double array
B 3x3 72 double array
C 3x3 72 double array
This tells us thatA,B, andCare all 3×3 matrices. They are stored as double precision arrays. A double
precision number requires 8 bytes to store it, so each array of 9 elements requires 72 bytes; a grand

1.3MANIPULATING THE ELEMENTS OF A MATRIX 5
total is 27 elements using 216 bytes. Consider now the following operations:
>> clear A
>>B=[];
>> C = zeros(4,4);
>> whos
Name Size Bytes Class
B 0x0 0 double array
C 4x4 128 double array
Here we see that we have cleared (i.e., deleted)Afrom the memory, assigned an empty matrix toBand
a4×4 array of zeros to
C.
Note that the size of matrices can also be determined using the
sizeandlengthfunctions thus:
>> A = zeros(4,8);
>> B = ones(7,3);
>> [p q] = size(A)
p=
4
q=
8
>> length(A)
ans =
8
>> L = length(B)
L=
7
It can be seen thatsizegives the size of the matrix whereaslengthgives the number of elements in
the largest dimension.
1.3MANIPULATING THE ELEMENTS OF A MATRIX
In MATLAB, matrix elements can be manipulated individually or in blocks. For example,
>> X(1,3) = C(4,5)+V(9,1)
>> A(1) = B(1)+D(1)
>> C(i,j+1) = D(i,j+1)+E(i,j)

6 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
are valid statements relating elements of matrices. Rows and columns can be manipulated as complete
entities. Thus
A(:,3),B(5,:)refer respectively to the third column ofAand fifth row ofB.IfBhas
10 rows and 10 columns, i.e. it is a 10×10 matrix, then
B(:,4:9)refers to columns 4 through 9 of
the matrix. The
:by itself indicates all the rows, and hence all elements of columns 4 through 9. Note
that in M
ATLAB, by default, thelowest matrix index starts at1. This can be a source of difficulty when
implementing some algorithms.
The following examples illustrate some of the ways subscripts can be used in M
ATLAB.Firstwe
assign a matrix
>>A=[2345 6;-4 -5 -6 -7 -8;3 5 7 9 1; ...
4 6 8 10 12;-2 -3 -4 -5 -6]
A=
23456
-4 -5 -6 -7 -8
35791
4 6 8 10 12
-2 -3 -4 -5 -6
Note the use of...(an ellipsis) to indicate that the MATLABstatement continues on the next line.
Executing the following statements
>>v=[135];
>> b = A(v,2)
gives
b=
3
5
-3
Thusbis composed of the elements of the first, third, and fifth rows in the second column ofA.Exe-
cuting
>> C = A(v,:)
gives
C=
23456
35791
-2 -3 -4 -5 -6
ThusCis composed of the first, third, and fifth rows ofA. Executing
>> D = zeros(3);
>> D(:,1) = A(v,2)

1.3MANIPULATING THE ELEMENTS OF A MATRIX 7
gives
D=
300
500
-300
HereDis a 3×3 matrix of zeros with column 1 replaced by the first, third, and fifth elements of
column 2 of
A.
Executing
>> E = A(1:2,4:5)
gives
E=
56
-7 -8
Note that if we index an existing square or rectangular array with a single index, then the elements
of the array are identified as follows. Index 1 gives the top left element of the array, and the index
is incremented down the columns in sequence, from left to right. For example, with reference to the
preceding array
C
C1 = C;
C1(1:4:15) = 10
C1 =
1034510
310791
-2 -3 10 -5 -6
Note that in this example the index is incremented by 4.
When manipulating very large matrices it is easy to become unsure of the size of the matrix. Thus, if
we want to find the value of the element in the penultimate row and last column of
Adefined previously
we could write
>> size(A)
ans =
55
>> A(4,5)
ans =
12

8 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
butitiseasiertouseendthus:
>> A(end-1,end)
ans =
12
Thereshapefunction may be used to manipulate a matrix. As the name implies, the function reshapes
a given matrix into a new matrix of any specified size provided it has an identical number of elements.
For example a 3×4 matrix can be reshaped into a 6×2matrixbuta3×3 matrix cannot be reshaped
into a 5×2 matrix. It is important to note that this function takes each column of the original matrix in
turn until the new required column size is achieved and then repeats the process for the next column.
For example, consider the matrix
P.
>> P = C(:,1:4)
P=
2345
3579
-2 -3 -4 -5
>> reshape(P,6,2)
ans =
24
37
-2 -4
35
59
-3 -5
>> s = reshape(P,1,12);
>> s(1:10)
ans =
23-235-347-45
1.4TRANSPOSING MATRICES
A simple operation that may be performed on a matrix is transposition which interchanges rows and
columns. Transposition of a vector is briefly discussed in Section1.2.InM
ATLABtransposition is
denoted by the symbol
’. For example, consider the matrixA, where
>>A=[123;456;789]

1.5SPECIAL MATRICES 9
A=
123
456
789
To assign the transpose ofAtoBwe write
>> B = A’
B=
147
258
369
Hadweused.’to obtain the transpose we would have obtained the same result. However, ifAis
complex then the M
ATLABoperator’gives the complex conjugate transpose. For example
>> A = [1+2i 3+5i;4+2i 3+4i]
A=
1.0000 + 2.0000i 3.0000 + 5.0000i
4.0000 + 2.0000i 3.0000 + 4.0000i
>> B = A’
B=
1.0000 - 2.0000i 4.0000 - 2.0000i
3.0000 - 5.0000i 3.0000 - 4.0000i
To provide the transpose without conjugation we execute
>> C = A.’
C=
1.0000 + 2.0000i 4.0000 + 2.0000i
3.0000 + 5.0000i 3.0000 + 4.0000i
1.5SPECIAL MATRICES
Certain matrices occur frequently in matrix manipulations and MATLABensures that these are gen-
erated easily. Some of the most common are
ones(m,n),zeros(m,n),rand(m,n),randn(m,n), and
randi(p,m,n). These MATLABfunctions generatem×nmatrices composed of ones, zeros, uni-
formly distributed random numbers, normally distributed random numbers and uniformly distributed
random integers, respectively. In the case of
randi(p,m,n),pis the maximum integer. If only a sin-
gle scalar parameter is given, then these statements generate a square matrix of the size given by the

10 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
parameter. The MATLABfunctioneye(n)generates then×nunit matrix. The function eye(m,n)
generates a matrix ofmrows andncolumns with a diagonal of ones; thus:
>> A = eye(3,4), B = eye(4,3)
A=
1000
0100
0010
B=
100
010
001
000
If we wish to generate a random matrixCof the same size as an already existing matrixA, then the
statement
C = rand(size(A))can be used. SimilarlyD = zeros(size(A))andE = ones(size(A))
generates a matrixDof zeros and a matrixEof ones, both of which are the same size as matrixA.
Some special matrices with more complex features are introduced in Chapter2.
1.6GENERATING MATRICES AND VECTORS WITH SPECIFIED ELEMENT
VALUES
Here we confine ourselves to some relatively simple examples thus:
x = -8:1:8(orx = -8:8)setsxto a vector having elements−8,−7, ...,7,8.
y = -2:.2:2setsyto a vector having elements−2,−1.8, −1.6, ...,1.8,2.
z = [1:3 4:2:8 10:0.5:11] setszto a vector having the elements
[1 2 3 4 6 8 10 10.5 11]
The M
ATLABfunctionlinspacealso generates a vector. However, in this function the user defines the
beginning and end values of the vector and the number of elements in the vector. For example
>> w = linspace(-2,2,5)
w=
-2 -1 0 1 2
This is simple and could just as well have been created byw = -2:1:2or evenw = -2:2. However,
consider
>> w = linspace(0.2598,0.3024,5)
w=
0.2598 0.2704 0.2811 0.2918 0.3024

1.6GENERATING MATRICES AND VECTORS 11
Generating this sequence of values by other means would be more difficult. If we require logarithmic
spacing then we can use
>> w = logspace(1,2,5)
w=
10.0000 17.7828 31.6228 56.2341 100.0000
Note that the values produced are between 10
1
and 10
2
, not 1 and 2. Again, generating these values
by any other means would require some thought! The user of
logspaceshould be warned that if the
second parameter is
pithe values run toπ, not 10
π
. Consider the following
>> w = logspace(1,pi,5)
w=
10.0000 7.4866 5.6050 4.1963 3.1416
More complicated matrices can be generated by combining other matrices. For example, consider the
two statements
>> C = [2.3 4.9; 0.9 3.1];
>> D = [C ones(size(C)); eye(size(C)) zeros(size(C))]
These two statements generate a new matrixDthe size of which is double the row and column size of
the original
C; thus
D=
2.3000 4.9000 1.0000 1.0000
0.9000 3.1000 1.0000 1.0000
1.0000 0 0 0
0 1.0000 0 0
The MATLABfunctionrepmatreplicates a given matrix a required number of times. For example,
assuming the matrix
Cis defined in the preceding statement, then
>> E = repmat(C,2,3)
replicatesCas a block to give a matrix with twice as many rows and three times as many columns.
Thus we have a matrix
Eof 4 rows and 6 columns:
E=
2.3000 4.9000 2.3000 4.9000 2.3000 4.9000
0.9000 3.1000 0.9000 3.1000 0.9000 3.1000
2.3000 4.9000 2.3000 4.9000 2.3000 4.9000
0.9000 3.1000 0.9000 3.1000 0.9000 3.1000
The MATLABfunctiondiagallows us to generate a diagonal matrix from a specified vector of diagonal
elements. Thus

12 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
>> H = diag([2 3 4])
generates
H=
200
030
004
There is a second used of the functiondiagwhich is to obtain the elements on the leading diagonal of
a given matrix. Consider
>> P = rand(3,4)
P=
0.3825 0.9379 0.2935 0.8548
0.4658 0.8146 0.2502 0.3160
0.1030 0.0296 0.5830 0.6325
then
>> diag(P)
ans =
0.3825
0.8146
0.5830
A more complicated form of diagonal matrix is the block diagonal matrix. This type of matrix can be
generated using the M
ATLABfunctionblkdiag. We set matricesA1andA2as follows:
>> A1 = [1 2 5;3 4 6;3 4 5];
>> A2 = [1.2 3.5,8;0.6 0.9,56];
Then,
>> blkdiag(A1,A2,78)
ans =
1.0000 2.0000 5.0000 0000
3.0000 4.0000 6.0000 0000
3.0000 4.0000 5.0000 0000
0 0 0 1.2000 3.5000 8.0000 0
0 0 0 0.6000 0.9000 56.0000 0
000000 78.0000
The preceding functions can be very useful in allowing the user to create matrices with complicated
structures, without detailed programming.

1.7MATRIX ALGEBRA IN M ATLAB 13
1.7MATRIX ALGEBRA IN M ATLAB
The matrix is fundamental to MATLABand we have provided a broad and simple introduction to
matrices in AppendixA.
M
ATLABallows matrix equations to be simply expressed and evaluated. For example, to illustrate
matrix addition, subtraction, multiplication, and scalar multiplication, consider the evaluation of the
matrix equation
Z=AA
T
+sP−Q
wheres=0.5 and
A=

2345
2468

P=

13
2−9

Q=

−73
51

Assigning
A,P,Q, ands, and evaluating this equation in MATLABwe have
>> A = [2 3 4 5;2 4 6 8];
>> P = [1 3;2 -9];
>> Q = [-7 3;5 1];
>> s = 0.5;
>> Z = A*A’+s*P-Q
Z=
61.5000 78.5000
76.0000 114.5000
This result can be readily checked by hand!
M
ATLABallows a single scalar value to be added to or subtracted from every element of a matrix.
This is called explicit expansion. To illustrate this we first generate a fourth-order Riemann matrix
using the M
ATLABfunctiongallery. This function gives the user access to a range of special matrices
with useful properties. See Chapter2for further discussion. In the following piece of M
ATLABcode
we use it to generate a 4×4 Riemann matrix, and then subtract 0.5 from every element of the matrix.
>> R = gallery(’riemann’,4)
R=
1-1 1-1
-1 2-1-1
-1 -1 3 -1
-1 -1 -1 4
>> A = R-0.5
A=
0.5000 -1.5000 0.5000 -1.5000
-1.5000 1.5000 -1.5000 -1.5000
-1.5000 -1.5000 2.5000 -1.5000
-1.5000 -1.5000 -1.5000 3.5000

14 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
In the 2016b release of MATLABthis feature has been extended to allow a row or column vector to be
added to a matrix. For example
>>B=2 *ones(4)-[1 2 3 4]
B=
1 0 -1 -2
1 0 -1 -2
1 0 -1 -2
1 0 -1 -2
>>C=2 *ones(4)+[2 4 6 8]’
C=
4444
6666
8888
10 10 10 10
Note that2*ones(4)produces a 4×4 matrix where each element is 2. In computing Bthe results
show that 1 is subtracted from each element of the first column, the 2 from each element in the second
column, the 3 from each element of the third column and so on. Similarly. in computing
Cthe results
show that 2 is added to each element of the first row, the 4 to each element in the second row, the 6 to
each element of the third row and so on.
1.8MATRIX FUNCTIONS
Some arithmetic operations are simple to evaluate for single scalar values but involve a great deal of
computation for matrices. For large matrices such operations may take a significant amount of time.
An example of this is where a matrix is raised to a power. We can write this in M
ATLABasA^pwhere
pis a scalar value andAis a square matrix. This produces the power of the matrix for any value ofp.For
the case where the power equals 0.5 it is better to use
sqrtm(A)which gives the principal square root
of the matrix
A, (see AppendixA, SectionA.13). Similarly, for the case where the power equals−1
it is better to use
inv(A). Another special operation directly available in MATLABisexpm(A)which
gives the exponential of the matrix
A.TheMATLABfunctionlogm(A)provides the principal logarithm
to the baseeof
A.IfB=logm(A)then the principal logarithmBis the unique logarithm for which every
eigenvalue has an imaginary part lying strictly between−πandπ.
For example
>> A = [61 45;60 76]
A=
61 45
60 76

1.9USING THE M ATLABOPERATOR FOR MATRIX DIVISION 15
>> B = sqrtm(A)
B=
7.0000 3.0000
4.0000 8.0000
>> B^2
ans =
61.0000 45.0000
60.0000 76.0000
1.9USING THE M ATLABOPERATOR FOR MATRIX DIVISION
As an example of the power of MATLABwe consider the solution of a system of linear equations. It
is easy to solve the problemax=bwhereaandbare simple scalar constants andxis the unknown.
Givenaandbthenx=b/a. However, consider the corresponding matrix equation
Ax=b (1.1)
whereAis a square matrix andxandbare column vectors. We wish to findx. Computationally this is
a much more difficult problem and in M
ATLABit is solved by executing the statement
x = Aρ
This statement uses the important MATLABdivision operator\and solves the linear equation sys-
tem (1.1).
Solving linear equation systems is an important problem and the computational efficiency and other
aspects of this type of problem are discussed in considerable detail in Chapter2.
1.10ELEMENT-BY-ELEMENT OPERATIONS
Element-by-element operations differ from the standard matrix operations but they can be very useful.
They are achieved by using a period or dot (
.) to precede the operator. IfXandYare matrices (or
vectors), then
X.^ Yraises eachelementof Xto the power of the corresponding element ofY. Similarly
X.*YandY.\Xmultiply or divide each element ofXby the corresponding element inYrespectively. The
form
X./Ygives the same result asY.\X. For these operations to be executed the matrices and vectors
used must be the same size. Note that a period isnotused in the operations
+and-because ordinary
matrix addition and subtractionareelement-by-element operations. Examples of element-by-element
operations are given as follows:

16 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
>> A = [1 2;3 4]
A=
12
34
>> B = [5 6;7 8]
B=
56
78
First we use normal matrix multiplication thus:
>> A*B
ans =
19 22
43 50
However, using the dot operator (.)wehave
>> A.*B
ans =
512
21 32
which is element-by-element multiplication. Now consider the statement
>> A.^B
ans =
164
2187 65536
In the above, each element ofAis raised to the corresponding power inB.
Element-by-element operations have many applications. An important use is in plotting graphs (see
Section1.14). For example
>> x = -1:0.1:1;
>>y=x. *cos(x);
>> y1 = x.^3.*(x.^2+3*x+sin(x));
Notice here that using the vectorxof many values, allows a vector of corresponding values foryand
y1to be computed simultaneously from single statements. Element-by-element operations are in effect
operations on scalar quantities performed simultaneously.

1.11SCALAR OPERATIONS AND FUNCTIONS 17
1.11SCALAR OPERATIONS AND FUNCTIONS
In MATLABwe can define and manipulate scalar quantities, as in most other computer languages, but
no distinction is made in the naming of matrices and scalars. Thus
Acould represent a scalar or matrix
quantity. The process of assignment makes the distinction. For example
>> x = 2;
>> y = x^2+3*x-7
y=
3
>> x = [1 2;3 4]
x=
12
34
>> y = x.^2+3*x-7
y=
-3 3
11 21
Note that in the preceding examples, when vectors are used the dot must be placed before the operator.
This is not required for scalar operations, but does not cause errors if used.
In the case where we multiply a square matrix by itself, for example, in the form
x^2we get the
full matrix multiplication as shown below, rather than element-by-element multiplication as given by
x.^2.
>> y = x^2+3*x-7
y=
39
17 27
A very large number of mathematical functions are directly built into MATLAB. They act on scalar
quantities, arrays or vectors on an element-by-element basis. They may be called by using the function
name together with the parameters that define the function. These functions may return one or more
values. A small selection of M
ATLABfunctions is given in the following table which lists the function
name, the function use and an example function call. Note that all function names must be in lower
case letters.
All M
ATLABfunctions are not listed in Table1.1,butM ATLABprovides a complete range of
trigonometric and inverse trigonometric functions, hyperbolic and inverse hyperbolic functions and

18 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
Table 1.1Selected MATLABmathematical functions
FunctionFunction gives Example
sqrt(x) square root ofx y = sqrt(x+2.5);
abs(x) ifxis real, is the positive value ofx
ifxis complex, is the scalar measure ofxd = abs(x)*y;
real(x) real part ofxwhenxis complex d = real(x)*y;
imag(x) imaginary part ofxwhenxis complexd = imag(x)*y;
conj(x) the complex conjugate ofx x = conj(y);
sin(x) sine ofxin radians t = x+sin(x);
asin(x) inverse sine ofxreturned in radianst = x+sin(x);
sind(x) sine ofxin degrees t = x+sind(x);
log(x) logtobaseeofx z = log(1+x);
log10(x) logtobase10ofx z = log10(1-2*x);
cosh(x) hyperbolic cosine ofx u = cosh(pi*x);
exp(x) exponential ofx, i.e.,e
x
p=.7*exp(x);
gamma(x) gamma function ofx f = gamma(y);
bessel(n,x)nth-order Bessel function ofx f = bessel(2,y);
logarithmic functions. The following examples illustrate the use of some of the functions listed be-
fore:
>> x = [-4 3];
>> abs(x)
ans =
43
>> x = 3+4i;
>> abs(x)
ans =
5
>> imag(x)
ans =
4
>> y = sin(pi/4)
y=
0.7071
and

1.11SCALAR OPERATIONS AND FUNCTIONS 19
>> x = linspace(0,pi,5)
x=
0 0.7854 1.5708 2.3562 3.1416
>> sin(x)
ans =
0 0.7071 1.0000 0.7071 0.0000
and
>> x = [0 pi/2;pi 3*pi/2]
x=
0 1.5708
3.1416 4.7124
>> y = sin(x)
y=
0 1.0000
0.0000 -1.0000
Some functions perform special calculations for important and general mathematical processes. These
functions often require more than one input parameter and may provide several outputs. For example,
bessel(n,x)gives thenth-order Bessel function ofx. The statement y = fzero(’fun’,x0)deter-
mines the root of the function
funnear tox0wherefunis a function defined by the user that provides
the equation for which we are finding the root. For examples of the use of
fzero, see Section3.1.The
statement
[Y,I] = sort(X)is an example of a function that can return two output values.Yis the
sorted matrix and
Iis a matrix containing the indices of the sort.
In addition to a large number of mathematical functions, M
ATLABprovides several utility functions
that may be used for examining the operation of scripts. These are:
pausecauses the execution of the script to pause until the user presses a key. Note that the cursor is
turned into the symbol P, warning the script is in pause mode. This is often used when the script
is operating with
echo on.
echo ondisplays each line of script in thecommandwindow before execution. This is useful for
demonstrations. To turn it off, use the statement
echo off.
wholists the variables in the current workspace.
whoslists all the variables in the current workspace, together with information about their size and
class, and so on.
M
ATLABalso provides functions related to time:

20 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
clockreturns the current date and time in the form: <year month day hour min sec>.
etime(t2,t1)calculates elapsed time betweent1andt2. Note thatt1andt2are output from the
clock function. When timing the duration of an event
tic ... tocshould be used.
tic ... toctimes an event. For example, finding the time taken to execute a segment of script. The
statement
ticstarts the timing andtocgives the elapsed time since the lasttic.
cputimereturns the total time in seconds since MATLABwas launched.
timeittimes the operation of a function. Suppose we carry out a 8192 point Fourier
transform using the M
ATLABfunctionfft(described in Chapter8) then we run
fft_time = timeit(@()fft(8192)) .
The script
e4s101.muses the timing functions described previously to estimate the time taken to solve
a 1000×1000 system of linear equations:
% e4s101.m Solves a 5000 x 5000 linear equation system
A = rand(5000); b = rand(5000,1);
T_before = clock;
tic
t0 = cputime;
y = A;
tend = toc;
t1 = cputime-t0;
t2 = timeit(@() A);
disp(’ tic-toc cputime timeit’)
fprintf(’%10.2f %10.2f %10.2f ’, tend,t1,t2)
Running scripte4s101.mon a particular computer gave the following results:
tic-toc cputime timeit
2.52 5.09 2.60
The output shows that the three alternative methods of timing give essentially the same value. When
measuring computing times the displayed times vary from run to run and the shorter the run time, the
greater the percentage variation.
1.12STRING VARIABLES
We have found that MATLABmakes no distinction in naming matrices and scalar quantities. This is
also true of string variables or strings. For example,
A=[12;34] ,A = 17.23,orA = ’help’are
each valid statements and assign an array, a scalar or a text string respectively to
A.
Characters and strings of characters can be assigned to variables directly in M
ATLABby placing the
string in quotes and then assigning it to a variable name. Strings can then be manipulated by specific
M
ATLABstring functions which we list in this section. Some examples showing the manipulation of
strings using standard M
ATLABassignment are given below.

1.12STRING VARIABLES 21
>> s1 = ’Matlab ’, s2 = ’is ’, s3 = ’useful’
s1 =
Matlab
s2 =
is
s3 =
useful
Strings in MATLABare represented as vectors of the equivalent ASCII code numbers; it is only the
way that we assign and access them that makes them strings. For example, the string
’is ’is actually
saved as the vector[105 115 32]. Hence, we can see that the ASCII codes for the letters
i,s, and
a space are 105, 115, and 32 respectively. This vector structure has important implications when we
manipulate strings. For example, we can concatenate strings, because of their vector nature, by using
the square brackets as follows
>> sc = [s1 s2 s3]
sc =
Matlab is useful
Note the spaces are recognized. To identify any item in the string array we can write:
>> sc(2)
ans =
a
To identify a subset of the elements of this string we can write:
>> sc(3:10)
ans =
tlab is
we can display a string vertically, by transposing the string vector thus:
>> sc(1:3)’
ans =
M
a
t
We can also reverse the order of a substring and assign it to another string as follows:

22 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
>>a = sc(6:-1:1)
a=
baltaM
We can define string arrays as well. For example, using the stringscas defined previously:
>> sd = ’Numerical method’
>> s = [sc; sd]
Matlab is useful
Numerical method
To obtain the 12th column of this string we use
>> s(:,12)
ans =
s
e
Note that the string lengths must be the same in order to form a rectangular array of ASCII code
numbers. In this case the array is 2×16. We now show how M
ATLABstring functions can be used to
manipulate strings. To replace one string by another we use
strrepas follows:
>> strrep(sc,’useful’,’super’)
ans =
Matlab is super
Notice that this statement causesusefulinscto be replaced bysuper.
We can determine if a particular character or string is present in another string by using
findstr.
For example
>> findstr(sd,’e’)
ans =
412
This tells us that the 4th and 12th characters in the string are ‘e’. We can also use this function to find
the location of a substring of this string as follows
>> findstr(sd, ’meth’)
ans =
11
The string’meth’begins at the 11th character in the string. If the substring or character is not in the
original string, we have the result illustrated by the example below:

1.12STRING VARIABLES 23
>> findstr(sd,’E’)
ans =
[]
We can convert a string to its ASCII code equivalent by either using the functiondoubleor by invoking
any arithmetic operation. Thus, operating on the existing string
sdwe have
>> p = double(sd(1:9))
p=
78 117 109 101 114 105 99 97 108
>> q = 1*sd(1:9)
q=
78 117 109 101 114 105 99 97 108
Note that in the case where we are multiplying the string by 1, MATLABtreats the string as a vector
of ASCII equivalent numbers and multiplies it by 1. Recalling that
sd(1:9) = ’Numerical ’ we can
deduce that the ASCII code for N is 78 and for u it is 117, etc.
We convert a vector of ASCII code to a string using the M
ATLABchar function. For example
>> char(q)
ans =
Numerical
To increase each ASCII code number by 3, and then to convert to the character equivalent we have
>> char(q+3)
ans =
Qxphulfdo
>> char((q+3)/2)
ans =
(<84:6327
>> double(ans)
ans =
40 60 56 52 58 54 51 50 55
char(q)
has converted the ASCII string back to characters. Here we have shown that it is possible to do
arithmetic on the ASCII code numbers and, if we wish, convert back to characters. If after manipulation
the ASCII code values are non-integer, they are rounded down.
It is important to appreciate that the string ‘123’ and the number 123 are not the same. Thus

24 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
>> a = 123
a=
123
>> s1 = ’123’
s1 =
123
Usingwhosshows the class of the variablesaands1as follows:
>> whos
Name Size Bytes Class
a 1x1 8 double array
s1 1x3 6 char array
A total of 4 elements using 14 bytes. Thus, a character requires 2 bytes, a double precision num-
ber requires 8 bytes. We can convert strings to their numeric equivalent using the functions
str2num,
str2doubleas follows:
>> x=str2num(’123.56’)
x=
123.5600
Appropriate strings can be converted to complex numbers but the user should take care, as we
illustrate below:
>> x = str2num(’1+2j’)
x=
1.0 + 2.0000i
but
>> x = str2num(’1+2 j’)
x=
3.0000 0 + 1.0000i
Note thatstr2doublecan be used to convert to complex numbers and is more tolerant of spaces.
>> x = str2double(’1+2 j’)
x=
1.0 + 2.0000i

1.13INPUT AND OUTPUT IN M ATLAB 25
There are many MATLABfunctions which are available to manipulate strings; see the appropriate
M
ATLABmanual. Here we illustrate the use of some functions.
bin2dec(’111001’)orbin2dec(’111 001’)returns 57.
dec2bin(57)returns the string ‘111001’.
int2str([3.9 6.2])returns the string ‘4 6’.
num2str([3.9 6.2])returns the string ‘3.9 6.2’.
str2num(’3.9 6.2’)returns 3.9000 6.2000.
strcat(’how ’,’why ’,’when’) returns the string ‘howwhywhen’.
strcmp(’whitehouse’,’whitepaint’) returns 0 because strings are not identical.
strncmp(’whitehouse’,’whitepaint’,5) returns 1 because first the 5 characters of strings are
identical.
datereturns the current date, in the form24-Aug-2011.
A useful and common application of the function
num2stris in thedispandtitlefunctions see
Sections1.13and1.14respectively.
1.13INPUT AND OUTPUT IN M ATLAB
To output the names and values of variables, the semicolon can be omitted from assignment statements.
However, this does not produce clear scripts or well-organized and tidy output. It is often better practice
to use the function
dispsince this leads to clearer scripts. Thedispfunction allows the display of text
and values on the screen. To output the contents of the matrix
Aon the screen we writedisp(A).Text
output must be placed in single quotes, for example,
>> disp(’This will display this test’)
This will display this test
Combinations of strings can be printed using square brackets[], and numerical values can be placed
in text strings if they are converted to strings using the
num2strfunction. For example,
>> x = 2.678;
>> disp([’Value of iterate is ’, num2str(x), ’ at this stage’])
will place on the screen
Value of iterate is 2.678 at this stage
The more flexiblefprintffunction allows formatted output to the screen or to a file. It takes the
form
fprintf(’filename’,’format_string’,list);
Herelistis a list of variable names separated by commas. The filename parameter is optional; if not
present, output is to the screen rather than to the filename. The format string formats the output. The
basic elements that may be used in the format string are

26 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
%P.Qefor exponential notation
%P.Qffixed point
%P.Qgbecomes%P.Qeor%P.Qfwhichever is shorter
gives a new line
Note that
PandQin the preceding are integers. The integer string characters, including a period (.),
must follow the
%symbol and precede the lettere,f,org. The integer before the period (P) sets the
field width; the integer after the period (
Q) sets the number of decimal places after the decimal point.
For example,
%8.4fand%10.3fgive field width 8 with four decimal places and 10 with three decimal
places, respectively. Note that one space is allocated to the decimal point. For example,
>> x = 1007.461; y = 2.1278; k = 17;
>> fprintf(’ x = %8.2f y = %8.6f k = %2.0f ’,x,y,k)
outputs
x = 1007.46 y = 2.127800 k = 17
whereas
>> p = sprintf(’ x = %8.2f y = %8.6f k = %2.0f ’,x,y,k)
gives
p=
x = 1007.46 y = 2.127800 k = 17
Note thatpis a string vector, and can be manipulated if required.
The degree to which the M
ATLABuser will want to improve the style of MATLABoutput will
depend on circumstances. Is the output generated for other persons to read, perhaps requiring a clearly
structured output, or is it just for the user alone and therefore requiring only a simple output? Will the
output be filed away for future use, or is it a quick result that is rapidly discarded? In this text we have
given examples of very simple output and sometimes quite elaborate output.
We now consider the input of text and data via the keyboard. An interactive way of obtaining input
is to use the function
input. One form of this function is
>> variable = input(’Enter data: ’);
Enter data: 67.3
Theinputfunction displays the text as a prompt and then waits for a numeric entry from the keyboard,
67.3in this example. This is assigned tovariablewhen the return key is pressed. Scalar values or
arrays can be entered in this way. The alternative form of the
inputfunction allows string input thus:
>> variable = input(’Enter text: ’,’s’);
Enter text: Male
This assigns the stringMaletovariable.
For large amounts of data, perhaps saved in a previous M
ATLABsession, the functionloadallows
the loading of files from disk using

1.13INPUT AND OUTPUT IN M ATLAB 27
load filename
The filename normally ends in.mator.dat. A file of sunspot data already exists in the MATLAB
package and can be loaded into memory using the command
>> load sunspot.dat
In the following example, we save the values ofx,y, andzin filetest001, clear the workspace and the
reload
x,y, andzinto the workspace, thus
>> x = 1:5; y = sin(x); z = cos(x);
>> whos
Name Size Bytes Class
x 1x5 40 double array
y 1x5 40 double array
z 1x5 40 double array
>> save test001
>> clear all, whos Nothing listed
>> load test001
>> whos
Name Size Bytes Class
x 1x5 40 double array
y 1x5 40 double array
z 1x5 40 double array
>> x = 1:5; y = sin(x); z = cos(x);
Here we only savex,yin filetest002and then we clear the workspace and reloadx,ythus:
>> save test002 x y
>> clear all, whos Nothing listed
>> load test002 x y, whos
Name Size Bytes Class
x 1x5 40 double array
y 1x5 40 double array
Note that the statementload test002has the same effect asload test002 x y. Finally we clear the
workspace and reload
xinto the workspace thus:
>> clear all, whos Nothing listed
>> load test002 x, whos
Name Size Bytes Class
x 1x5 40 double array
Files composed of Comma Separated Values (CSV) are commonly used to exchange large amounts
of tabular data between software applications. The data is stored in plain text and the fields are sepa-
rated by commas. The files are easily editable using common spread sheet applications (e.g. MS Excel).
If data has been generated elsewhere and saved as a CSV file it can be imported into M
ATLAB

28 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
usingcsvread.Weusecsvwriteto generate a CSV file from MATLAB. In the following MATLAB
statements we save the vectorp, we clear the workspace and then reloadp, but now call it the vectorg:
>> p = 1:6;
>> whos
Name Size Bytes Class
p 1x6 48 double array
>> csvwrite(’test003’,p)
>> clear
>> g = csvread(’test003’)
g=
12345
As a further example of theloadandsavecommands, consider the following example:
% e4s110
x=[10231];y=[-10411];
A = [x;x.^2; x.^3;x.^4;x.^5];
B = [x;2*x; 3*x; 4*x;5*x];
save test004 A B
clear all
whos
disp(’nothing listed’)
load test004
C=A*B;
disp(’Results of matrix multiplication’)
disp(C)
Running scripte4s110gives
>> e4s110
nothing listed
Results of matrix multiplication
24 0487224
54 0 108 162 54
138 0 276 414 138
378 0 756 1134 378
1074 0 2148 3222 1074
1.14M ATLABGRAPHICS
MATLABprovides a wide range of graphics facilities which may be called from within a script or
used simply in command mode for direct execution. We begin by considering the
plotfunction. This
function takes several forms. For example,

1.14M ATLABGRAPHICS 29
Table 1.2Symbols and characters used in plotting
LineSymbolPointSymbolColorCharacter
Solid - point . yellow y
Dashed - - plus + red r
Dotted : star * green g
Dashdot -. circle o blue b
xmark × black k
plot(x,y)plots the vectorxagainsty.Ifxandyare matrices the first column ofxis plotted against
the first column of
y. This is then repeated for each pair of columns ofxandy.
plot(x1,y1,’type1’,x2,y2,’type2’) plots the vectorx1againsty1using the line or point type given
by
type1, and the vectorx2againsty2using the line or point type given bytype2.
The
typeis selected by using the required symbol from Table1.2. This symbol may be preceded by a
character indicating a color.
Semilog and log–log graphs can be obtained by replacing
plotbysemilogx,semilogy,orloglog
functions and various other replacements forplotare available to give special plots. Titles, axis labels
and other features can be added to a given graph using the functions
xlabel,ylabel,title,grid, and
text. These functions have the following forms:
title(’title’)displays the title which is enclosed between quotes, at the top of the graph.
xlabel(’x_axis_name’)displays the name which is enclosed between quotes for thex-axis.
ylabel(’y_axis_name’)displays the name which is enclosed between quotes for they-axis.
gridsuperimposes a grid on the graph.
text(x,y,’text-at-x,y’) displays text at position (x,y) in the graphics window wherexandyare
measured in the units of the current plotting axes. There may be one point or many at which text is
placed depending on whether or not
xandyare vectors.
gtext(’text’)allows the placement of text using the mouse by positioning it where the text is required
and then pressing the mouse button.
ginputallows information to be taken from a graphics window. The function takes two main forms.
The simplest is
[x,y] = ginput
This inputs an unlimited number of points into the vectorsxandyby positioning the mouse cross-hairs
at the points required and then pressing the mouse button. To exit ginput the return key must be pressed.
If a specific number of points
nare required, then we write
[x,y] = ginput(n)
In addition, the function axis allows the user to set the limits of the axes for a particular plot. This
takes the form
axis(p)wherepis a four-element row vector specifying the lower and upper limits of
theaxesinthexandydirections. The axis statement must be placedafterthe plot statement to which
it refers. Similarly the functions
xlabel,ylabel,title,grid,text,gtext, andaxismustfollowthe
plot to which they refer.
Script
e4s102.mgives the plot which is output as Fig.1.1. The function holdis used to ensure that
the two graphs are superimposed.

30 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
FIGURE 1.1
Superimposed graphs obtained usingplot(x,y)andholdstatements.
% e4s102.m
x = -4:0.05:4;
y = exp(-0.5*x).*sin(5*x);
figure(1), plot(x,y)
xlabel(’x-axis’), ylabel(’y-axis’)
hold on
y = exp(-0.5*x).*cos(5*x);
plot(x,y), grid
gtext(’Two tails...’)
hold off
Scripte4s102.millustrates how few MATLABstatements are required to generate a graph.
The function
fplotallows the user to plot a previously defined function between given limits. The
important difference between
fplotandplotis thatfplotchooses the plotting points in the given
range adaptively depending on the rate of change of the function at that point. Thus, more points
are chosen when the function is changing more rapidly. This is illustrated by executing the M
ATLAB
scripte4s103.m:
% e4s103.m
y = @(x) sin(x.^3);
x = 2:.04:4;
figure(1)
plot(x,y(x),’o-’)
xlabel(’x’), ylabel(’y’)
figure(2)
fplot(y,[2 4])
xlabel(’x’), ylabel(’y’)
Notefigure(1)andfigure(2)direct the graphic output to separate windows. The interpretation of
the anonymous function
@(x) sin(x.^3)is explained in Section1.19.

1.14M ATLABGRAPHICS 31
FIGURE 1.2
Plot ofy=sin(x
3
)using 51 equispaced plotting
points.
FIGURE 1.3
Plot ofy=sin(x
3
)using the functionfplotto choose
plotting points adaptively.
Running scripte4s103.mproduces Fig.1.2and Fig.1.3. In the plot example, we have deliberately
chosen an inadequate number of plotting points and this is reflected in the quality of Fig.1.2.The
function
fplotproduces a smoother and more accurate curve. Note thatfplotonly allows a function
or functions to be plotted against an independent variable. Parametric plots cannot be created by
fplot.
The M
ATLABfunctionezplotis similar tofplotin the sense that we only have to specify the
function, but has the disadvantage that the step size is fixed. However,
ezplotdoes allow parametric
plots and three-dimensional plots. For example
>> ezplot(@(t) (cos(3 *t)), @(t) (sin(1.6*t)), [0 50])
is a parametric plot but the plot is rather coarse.
We have seen how
fplothelps in plotting difficult functions. Other functions which help to clarify
when the plot of a function is unclear or unpredictable are
ylimandxlim. The functionylimallows the
user to easily limit the range of they-axis in the plot and
xlimdoes the same for thex-axis. Their use
is illustrated by the following example. Fig.1.4(without the uses of
xlimandylim) is unsatisfactory
since it gives little understanding about how the function behaves except at the specific pointsx=−2.5,
x=1, andx=3.5.
>> x = -4:0.0011:4;
>> y =1./(((x+2.5).^2). *((x-3.5).^2))+1./((x-1).^2);
>> plot(x,y)
>> ylim([0,10])
Fig.1.5shows how the M ATLABstatementylim([0,10])restricts they-axis to maximum value
of 10. This gives a clear picture of the behavior of the graph. There are a number of special features
available in M
ATLABfor the presentation and manipulation of graphs and some of these are now be
discussed. The
subplotfunction takes the formsubplot(p,q,r)wherepandqsplit the figure window
into ap×qgrid of cells and places the plot in therth cell of the grid, numbered consecutively along

32 CHAPTER 1 AN INTRODUCTION TO M ATLAB
®
FIGURE 1.4
Function plotted over the range from−4to 4. It has a
maximum value of4×10
6
.
FIGURE 1.5
The same function as plotted in Fig.1.4but with a
limit on the range of they-axis.
the rows. This is illustrated by running scripte4s104.mwhich generates six different plots, one in each
of the six cells. These plots are given in Fig.1.6.
% e4s104.m
x = 0.1:.1:5;
subplot(2,3,1), plot(x,x)
title(’plot of x’), xlabel(’x’), ylabel(’y’)
subplot(2,3,2), plot(x,x.^2)
title(’plot of x^2’), xlabel(’x’), ylabel(’y’)
subplot(2,3,3), plot(x,x.^3)
title(’plot of x^3’), xlabel(’x’), ylabel(’y’)
subplot(2,3,4), plot(x,cos(x))
title(’plot of cos(x)’), xlabel(’x’), ylabel(’y’)
subplot(2,3,5), plot(x,cos(2 *x))
title(’plot of cos(2x)’), xlabel(’x’), ylabel(’y’)
subplot(2,3,6), plot(x,cos(3 *x))
title(’plot of cos(3x)’), xlabel(’x’), ylabel(’y’)
The current plot can be held on screen by using the functionholdand subsequent plots are drawn
over it. The function
hold onswitches the hold facility on whilehold offswitches it off. The figure
window can be cleared using the function
clf.
M
ATLABprovides many other plot functions and styles. To illustrate two of these, thepolarand
compassplots, we display the roots ofx
5
−1=0 which have been determined using the MATLAB
functionroots. This function is described in detail in Section3.11. Having determined the five roots
of this equation we plot them using both
polarandcompass. The functionpolarrequires the absolute
values and phase angles of the roots, whereas as the function
compassplots the real parts of the roots
against their imaginary parts.

1.14M ATLABGRAPHICS 33
FIGURE 1.6
An example of the use of thesubplotfunction.
>> p=roots([1 0 0 0 0 1])
p=
-1.0000
-0.3090 + 0.9511i
-0.3090 - 0.9511i
0.8090 + 0.5878i
0.8090 - 0.5878i
>> pm = abs(p.’)
pm =
1.0000 1.0000 1.0000 1.0000 1.0000
>> pa = angle(p.’)
pa =
3.1416 1.8850 -1.8850 0.6283 -0.6283
>> subplot(1,2,1), polar(pa,pm,’ok’)
>> subplot(1,2,2), compass(real(p),imag(p),’k’)
Fig.1.7shows these subplots.
An interesting development introduced in the 2016b release of M
ATLABare polar scatter and polar
histogram plots that allow data to be plotted in polar coordinates. For the polar scatter function the
points are plotted on a circle, each point being denoted by a circle, or some other selected symbol.

Random documents with unrelated
content Scribd suggests to you:

71
“Any plans for this morning, Flash?” he inquired
casually.
“None in particular. I thought I would go over to the
hospital. Would you like to come along?”
Doyle shook his head. He seemed relieved by Flash’s
answer.
“No, I’ll be tied up all morning. I want to check over my
sound equipment and get ready to roll when my new
assignment comes through. Tell Joe hello for me.”
Flash ate breakfast and reached the hospital in time for
the ten o’clock visiting hours. The door of Major
Hartgrove’s room stood ajar. But the bed was empty and
attendants were stripping off the linen.
A nurse was passing in the hall. Flash stopped her and
inquired where he would find the Major.
“You are too late,” she replied. “Major Hartgrove left the
hospital early this morning.”
Flash went on to Joe Wells’ room. He had made up his
mind not to tell his friend of George Doyle’s treachery.
However, when Joe again urged him to take the
newsreel job for at least a month, he gave the matter
rather serious consideration.
“The only reason I might do it would be to protect you,
Joe,” he replied. “If I held the post until you were up
and around again, no one could steal it from you.”
“Oh, that wouldn’t happen,” his friend responded
carelessly. “I have a good stand-in with the News-Vue
people.”

72
73
“Even so, you can’t tell what will happen these days,”
hinted Flash.
“Then will you take the job if I can land it for you?”
“I’ll not promise yet, Joe. Tell you what I’ll do. I’ll wire
Riley and see what he says. I can’t afford to jeopardize
my own place on the Ledger, you know.”
The matter was allowed to rest. Leaving the hospital
before the visiting hours were over, Flash dispatched the
telegram, and then returned to the hotel.
As he passed through the lobby he was surprised to see
George Doyle sitting in a near-by chair, his back turned.
He was talking earnestly with an alert-eyed, gray-haired
man of forty.
Instantly it struck Flash that Doyle had wished to have
him away from the hotel at the time of an anticipated
interview. Impulsively, he crossed the room, intending
to test out his theory by speaking to the technician.
Doyle did not see him approach. As Flash paused just
behind the upholstered chair, he arose and extended his
hand to the man who faced him.
“I’m glad you liked my work,” he said heartily. “And I’m
sorry about Evans. He’s given me to understand he
wouldn’t be interested in any proposition.”

74
CHAPTER IX
FLASH ACCEPTS AN OFFER
Flash stepped forward into George Doyle’s view. The
soundman saw him and lapsed into confused silence.
“Sorry. I couldn’t help hearing,” Flash apologized. “I
don’t mind saying I’m curious about this proposition
which wouldn’t interest me.”
“You’re not Flash Evans?” inquired the stranger before
Doyle could find his voice.
“Yes, sir, I am.”
“Flash, this is our district manager, Mr. Clewes,” Doyle
said unwillingly. “We were just speaking of your fine
work at Indianapolis.”
“Yes,” nodded Mr. Clewes, “as I mentioned in my
telegram, those pictures were the best we’ve had in
months! The sound effects were fairly good, too.”
Flash glanced at Doyle who shifted uncomfortably from
one foot to another.
“Thank you, sir,” he said politely to the district manager.
“I didn’t happen to see your wire.”
Mr. Clewes gazed questioningly at the sound technician.

75
“I repeated the contents to him,” Doyle said defensively.
Ignoring the technician, Mr. Clewes turned to Flash
again.
“Howard Brandiss, who heads our company, was much
impressed by your work. When he saw the crash films
run through he said to me: ‘Fly down to Columbia and
sign that photographer on the dotted line before some
other company gets him.’ But Doyle here tells me you
wouldn’t be interested in any proposition we might
offer.”
“Flash already is employed by the Brandale Ledger,”
Doyle broke in hurriedly. “He’s on his vacation now. I
understood him to say he wouldn’t consider working for
a newsreel concern.”
“I’m afraid your hearing was almost too acute,” Flash
said pleasantly. “Either that or I gave the wrong
impression.”
“Then you are interested?” Mr. Clewes asked quickly.
“Not in a permanent job. I might consider filling in a
month for Joe Wells. That is, if Mr. Riley has no
objection.”
“And who is Mr. Riley?”
“My editor on the Brandale Ledger.”
“I am sure we can arrange everything to his
satisfaction,” said Mr. Clewes. “And I respect you for
being loyal to your employer. If you are unwilling to
leave the Ledger, we should not try to convince you
otherwise. Nevertheless, after a month of newsreel

76
work, you may decide you prefer it to your newspaper
position.”
“That’s quite possible, sir.”
Dismissing Doyle with a curt nod, Mr. Clewes drew Flash
aside. For a half hour they talked together, discussing
salary and matters of general routine. The district
manager then insisted upon placing a long distance
telephone call to Riley of the Brandale Ledger.
He stepped from the booth, smiling broadly.
“Everything has been arranged. Mr. Riley says you may
work for us, providing we don’t try to steal you away
from him at the end of the month.”
“I aim to go back to Brandale when my vacation is over,”
Flash insisted. “My home is there.”
Mr. Clewes gazed about the lobby in search of Doyle.
The technician had slumped down in a chair in front of
the fireplace. He came over as the district manager
motioned to him.
“Doyle, meet your new partner. You two will continue to
work together.”
The technician’s face twisted into a strained smile.
“Glad Mr. Clewes was able to persuade you when I
couldn’t,” he said to Flash. “We’ll get along fine.”
The district manager glanced at his watch. “I have
fifteen minutes to catch my plane,” he declared
hurriedly.

77
“How about our next assignment?” asked Doyle.
“I was coming to that. No news of special importance is
breaking in this section of the country right now. Your
instructions are to start East again. Stop off at
Melveredge Field and try to get shots of the new
bombing plane which is being tested there.”
“Try is right,” grumbled Doyle. “That place is so
surrounded by barbed-wire red tape a newsreel man
couldn’t cut his way through in a month. How about
permits?”
“News-Vue will endeavor to make the necessary
arrangements. Even if you can’t obtain pictures of the
bomber, you should be able to get routine maneuvers.
Do the best you can. Further orders will be forwarded to
you at the Clarinda Hotel.”
Mr. Clewes shook hands with both Flash and Doyle, and
hastened to his taxi. In silence, the two newsreel men
went to their room. They began to pack.
“This is a poor assignment,” Doyle complained, jamming
shirts into his bag. “We’ll waste a lot of time at
Melveredge Field, fail to get the pictures, and then be
reprimanded for our pains.”
“Mr. Clewes must think we have a chance or he wouldn’t
send us.”
“Us,” said Doyle with biting sarcasm. “A lot of good
you’re going to do me!”
The words were spoken before he thought. Once said,
he could not retract them. But instantly he was
ashamed of the unwarranted outburst.

78
“Sorry,” he apologized curtly. “I shouldn’t have said that.
But you made me sore, trying to show me up in front of
Mr. Clewes.”
“In what way?”
“Letting on that I hadn’t shown you his telegram. And
then the way you breezed up and accepted a job after
you made me think you wouldn’t take one.”
“I don’t remember that we ever discussed it,” Flash
returned coldly. “But that’s neither here nor there. I’ve
taken the job. Whether we like it or not, we’ll be
working together. Why not try to get along without
friction?”
“Suits me. All I ask is that you do your work and don’t
expect to use me as a crutch.”
“We understand each other perfectly, Doyle. Now when
do we start?”
“Twenty minutes.”
“I’ll meet you at the parking lot. I want to telephone Joe
and tell him I’ve taken the job.”
Flash had another errand in mind, one which he did not
reveal to Doyle. Quickly he made his telephone call from
the lobby of the hotel.
“I’m glad you’ve changed your mind,” Joe told him
gratefully. “Can’t you come over to the hospital before
you leave town?”
“Afraid not. We’re starting in a few minutes.”

79
Joe Wells hesitated, and then said: “You’ll get along
fine, Flash, if you manage to stay on the good side of
Doyle. He can help you a lot. But I’ll give you a tip. If he
takes a dislike to a fellow, he knows all the ways of
making it plenty tough.”
“Everything will be fine, Joe. I’ll manage. And your job
will be waiting whenever you want it back.”
He hung up, smiling ruefully at his friend’s belated
warning. Already he had incurred George Doyle’s dislike.
But he was not afraid of what the technician might
attempt to do. He would be ready and waiting.

80
CHAPTER X
CHECKING FACTS
With fifteen minutes to spare, Flash made a quick trip to
the railroad station. His next errand was anything but to
his liking. Yet he was unwilling to leave Columbia
without verifying a certain fact.
He found the station agent in his little office behind the
ticket window.
“What may I do for you, sir?” the man questioned.
Introducing himself as a representative of the Brandale
Ledger, Flash added that he was checking upon the
death of a man reported killed in the streamliner crash.
“Sorry I can’t help you on that,” replied the agent. “It’s
against orders to give out information about the
accident. You’ll have to see some other person.”
Flash was persistent. He explained that any information
obtained would not be published in a newspaper.
“I’m trying to learn about a man named Albert Povy.”
“I guess I can tell you about him,” the agent conceded.
“He was among the victims.”
“The body was shipped from here?”

81
“It was.”
“To relatives?”
“Couldn’t tell you as to that. The body was claimed by a
man named Rascomb. Herbert Rascomb.”
Flash was startled by the name. He wondered if it could
be the same man George Doyle had been telling him
about. But that scarcely seemed possible.
“And where was the casket sent?” he asked after a
moment. “That is, what city?”
“To a place called Clear Lake.”
Flash thanked the agent for the information and left the
station. He was ten minutes late in reaching the parking
lot. Doyle was waiting in the sound truck, appearing
none too pleased at the delay.
They drove out of town with Doyle at the wheel. The
truck made good speed. For a time neither of them
spoke.
“Oh, by the way,” Doyle said at length, “what sort of
salary did Clewes give you?”
“Somewhat less than Joe was getting,” Flash answered
vaguely. “More than I’ll earn probably.”
“You’ll be getting a double salary while you’re on
vacation, won’t you?” Doyle could not hide his envy.
“Yes, but it won’t last long.”
Flash decided to ask a few questions himself. A little
later he introduced the subject of the sportsman,

82
Rascomb, asking Doyle the man’s first name.
“Herbert. Herb Rascomb.”
“And where is his lodge located? What town is it near?”
“Couldn’t tell you exactly,” responded Doyle. “I
understand it’s not far from where we’re heading—
Melveredge Field. But why this sudden interest in
Rascomb?”
“Merely curious, that’s all. What sort of reputation does
he have?”
“Reputation? Oh, he steps around in fast company, if
that’s what you mean. He has a lot of foreign friends.”
“Was he ever mixed up in trouble with the government
or anything of the sort?”
“Rascomb? Say, that fellow is in the blue book. The only
thing he’s interested in is having a good time. If he did
get into trouble he could buy himself out.”
Again Flash fell silent, for he saw that Doyle had grown
irritated by his questions. It struck him as an interesting
fact that Rascomb had been connected with Albert Povy,
a man of dubious reputation.
Actually there was no good reason why the pair should
not have been friends. With a large circle of
acquaintances, Rascomb could have met Povy in his
travels about the country and, learning that the man
was without relatives, might have claimed the body out
of kindness. In any case, it was none of his affair. He
never expected to see Rascomb again.

83
Throughout the day the sound truck rumbled steadily
eastward, making only brief stops for oil and gas. Twice
Flash offered to relieve Doyle at the wheel, and both
times was turned down.
Toward dusk they pulled into a busy little city of some
fifty thousand population. They had reached their
destination. Melveredge Field was located close by.
Doyle glanced at his watch.
“Ten after five,” he announced. “Too late to do anything
tonight. We’ll find the Clarinda Hotel and call it a day.”
Flash nodded. Doyle never bothered to consult his
wishes. He quickly had learned that the easiest way to
get along with the technician was to have no opinions of
his own. So far any differences they might have had
were trivial. But clashes were certain to come later.
Flash had been relieved to learn that News-Vue paid all
traveling expenses. The arrangement, however, had one
distinct drawback. He and Doyle were expected to share
the same room.
“We see too much of each other as it is,” thought Flash.
“Before the end of a month we won’t be on speaking
terms.”
They registered at the Clarinda Hotel and inquired for
mail. There was none. The anticipated orders from the
News-Vue Company had not yet arrived.
The newsreel men both were tired and dirty from their
long journey.
“Me for the tub,” Doyle announced.

84
Slamming the bathroom door behind him, he started the
water running, and remained soaking for nearly an hour.
Flash became irritated at the long delay.
“Say, have you gone to bed in there?” he called at last.
“You’re not the only dirty pebble on the beach!”
Doyle did not answer, nor would he hurry. He took
another half hour to dress. Finally be unlocked the door
and sauntered out.
“What’s all the shouting about, Flash?”
“You’ve been in there exactly an hour and a half!”
“Well, it’s all yours now,” Doyle shrugged. “Such
impatience! Dear! Dear!”
Flash glanced at the tub. It was rimmed with dirt. Every
bath towel had been used.
“Say, you lug—” he began.
An outside door slammed. The culprit had gone.
Ringing for more towels, Flash cleaned the tub and
hastened through his own bath.
“I’ll get even with him tomorrow,” he thought. “We’ll see
how he likes it when the joke is on him.”
It was after seven o’clock when Flash finally left the
hotel in search of a restaurant. He sauntered along,
pausing to read menus printed on the plate glass
windows. Suddenly he felt a hand touch his shoulder.
Flash whirled around. For a moment he did not
recognize the smiling young man who stood there. Then

85
he gave a pleased cry:
“Bailey Brooks! What are you doing out this way?”
“Oh, prowling around,” the parachute jumper replied.
“Had your dinner?”
“Not yet.”
“Then let’s go inside. I’m meeting a man, but he’s not
due to show up for fifteen minutes.”
Flash felt flattered that Bailey Brooks had remembered
him. He was even more pleased when the parachute
jumper praised him for the pictures he had taken at
Brandale.
“All the publicity helped,” Brooks declared warmly.
“Since the parachute test proved successful, several
concerns have been after me. I’ve not had a definite
offer yet, but it’s only a matter of time.”
The two young men entered the restaurant and selected
a table not far from the door. Flash hesitated, and then
said:
“Too bad about Povy.”
“Yeah.” The smile faded from Brooks’ face. “He was
interested in my invention. Offered me a good price for
it, too. But probably it’s just as well the deal didn’t go
through.”
“Why do you say that?”
“You know who Povy was, don’t you?”
“I’ve heard rumors.”

86
“He was mixed up with a spy ring years ago and
probably was doing espionage work at the time of his
death. That was the main reason I held off about selling
him the parachute. I liked Povy personally but I never
trusted him.”
“I wonder what government employed him?”
“I never learned. Povy was very cautious in his dealings.
He revealed nothing about himself. All he ever told me
was that he represented a firm which would pay well for
my invention, providing the tests were successful.”
A waitress came to take orders and Flash gave his.
Bailey Brooks said that he would wait for a man with
whom he had a dinner appointment.
“You say several other persons are after your invention
now?”
“Several is an exaggeration,” Brooks admitted with a
grin. “One private party and the United States Army.”
“So that’s why you’re here!”
Brooks nodded. “The ’chute is to be given exhaustive
tests out at Melveredge Field. If it comes through okay,
I’ll be sitting pretty.”
“When will the tests be made?”
“All week. There’s an endless amount of red tape.”
“I’m with the News-Vue people now,” Flash explained
abruptly. “Any chance to get some shots of the tests?”

87
“Not a glimmer. Melveredge Field is closed tighter than a
drum these days. I doubt if they’ll even allow you near
the place with a newsreel camera.”
Flash mentioned the chain of events which had led him
to spend his vacation working for the News-Vue
Company. The parachute jumper immediately recalled
Joe Wells and expressed regret over his accident.
“While I was in Columbia I inquired about Albert Povy,”
Flash presently remarked. “You know, I thought there
might have been some mistake about his death.”
“There wasn’t?”
“No. His body was shipped to a place called Clear Lake.”
“That town isn’t so far from here,” Brooks said
thoughtfully. “I’ve heard of it.”
“Povy’s body was claimed by a man named Herbert
Rascomb. A well known sportsman and—”
Bailey Brooks had been toying with a silver knife. It slid
from his hand, making a clatter as it struck the floor.
“Rascomb?” he asked in a strange voice. “Did you say
Rascomb?”
Flash could see that the information had startled the
parachute jumper. But before he could explain further or
ask a question, the door of the café swung open.
A dapper man in army uniform strode across the room
directly toward the pair at the table.
“Ah, here is my host now,” murmured Bailey Brooks.

88
Flash turned his head. The man who approached was
Captain Ernest Johns.

CHAPTER XI
HIGH WATER
Bailey Brooks arose to greet the newcomer. As he
turned to introduce Flash, Captain Johns forestalled him
by saying in a curt voice:
“We have met before, I believe!”
“At the Columbia Hospital,” recalled Flash.
The Captain seated himself on the opposite side of the
table, regarding the cameraman with a cold scrutiny
which was not easy to interpret. Assuming that he was
an intruder at a private business conference, Flash
offered an apology and started to leave.
“No, don’t go.” Captain Johns waved him back into his
chair. “Finish your dinner. Why did you fail to keep your
promise to Major Hartgrove?”
Flash now understood the reason behind the officer’s
coolness. Major Hartgrove had reported his failure to
give up the requested pictures.
“I made no promise,” he replied.
“It was understood that you would bring the pictures to
the hospital without delay.”

89
90
“The Major may have understood it that way,” replied
Flash evenly. “But I work for the News-Vue Company,
not the United States Army.”
Captain Johns’ lips twisted in a faint suggestion of a
smile. Yet his voice had an edge to it as he asked:
“You still have those pictures?”
“I have.”
“What is your reason for withholding them?”
“No reason,” Flash admitted cheerfully. “As a matter of
fact, I went back to the hospital yesterday after I had
them printed. The Major was gone.”
“You went back after you had looked at them yourself?”
“Quite right, sir. I wanted to see what I was giving
away. Just protecting my paper, you know.”
“Yes, I know,” responded Captain Johns dryly. “You may
be interested to learn that Major Hartgrove has been
removed to the army hospital at Melveredge Field.”
“Doing well I hope.”
“He will be dismissed tomorrow or the day following.
Now about those pictures. Where are they now?”
“In my room at the hotel.”
“May I see them?”
“I’ll be glad to show them to you, Captain,” replied
Flash, grinning. “But I don’t think you’ll find them of any
aid in running down the man who struck the Major.”

91
“Let me be the judge of that. Now as I recall, Major
Hartgrove said you were the first person to reach him
after the train wreck.”
“Hardly the first, sir. As I approached the car, I saw
someone slipping away into the dark. It may have been
the man who robbed him.”
“You are mistaken. Major Hartgrove was not robbed.”
“I understood otherwise.”
“An attempt was made to take Major Hartgrove’s wallet.
The man did not succeed.”
Flash accepted the explanation without comment. He
was rather inclined to believe that the Major had not
been robbed. However, it seemed unreasonable that the
army men would be making such strenuous efforts to
apprehend an ordinary thief. Obviously Major Hartgrove
had carried military papers or something of far greater
value than money.
Ignoring Bailey Brooks for the moment, Captain Johns
asked Flash a number of questions about his actions
following the train wreck. Cleverly but without success
he tried to make the cameraman contradict himself. At
last, he seemed satisfied the young man was telling the
truth, and turned his attention once more to the
parachute jumper.
After the meal had ended, Captain Johns volunteered to
go with Flash to his room. The three walked together to
the Clarinda Hotel.
George Doyle looked up in surprise as Flash pushed
open the bedroom door. He rose quickly to his feet.

92
“You remember Bailey Brooks,” said Flash. “And this is
Captain Ernest Johns.”
Doyle was impressed by the caller. He lost his customary
indifference and put himself out to be agreeable. But
the captain paid him scant attention.
“I have only a few minutes,” he said impatiently. “May I
see the pictures now, please?”
Flash found the envelope in his luggage. Doyle sat
watching him curiously as he sorted through the prints.
“I have only one which will interest you,” he said to the
captain. “It isn’t much good.”
The army man examined the picture carefully and
returned it to the stack.
“You are right,” he admitted regretfully. “For our
purposes it is valueless.” Methodically, he thumbed
through the other prints. “Now here is an excellent
one!”
“A snap I took at the races. Too bad the wreck picture
didn’t come out the same way. Conditions were against
me.”
Bailey Brooks had crossed the room. As Captain Johns
dropped the prints carelessly on the table, he picked
them up and glanced through the stack.
The army officer turned to leave but Doyle stepped
forward, neatly blocking his way.
“Say, Captain,” he began, “Flash and I are with News-
Vue, you know. What are the picture possibilities out at

Melveredge?”
“There are none, Mr. Doyle.”
“Oh, come now, I know it’s hard to get in there these
days, but it can be done with pull. How about giving us
a permit?”
“I regret I am not in a position to grant such a favor,”
the captain returned stiffly. “Good evening.”
Accompanied by Bailey Brooks, he went away. As soon
as the footsteps receded, Doyle turned angrily to Flash.
“You might have said something instead of standing
there like a clam! Here the Captain is a good friend of
yours. He could have passed us into Melveredge Field.”
“The Captain isn’t a friend of mine.”
“Then why did you bring him here?”
“You must have observed for yourself, Doyle. To look at
those pictures.”

93
The technician picked up the stack and glanced through
the prints.
“What’s all this about anyway?” he demanded. “Why
would the Captain be interested?”
Flash made an evasive answer which only irritated Doyle
further. Despite the technician’s displeasure, he had no
intention of taking him into his confidence.
“I’m tired,” he said shortly. “Let’s go to bed.”
It was dark in the hotel room when Flash awakened to
hear the telephone ringing. Struggling out of sleep, he
reached to roll up the window shade. A few carts were
creaking by on the street below. The sky was barely
light.
The telephone rang again.
“Answer it, will you?” growled Doyle.
“All right.”
Flash took the receiver from its hook. He was informed
by the hotel operator that long distance was calling. As
he relayed the message to Doyle, the latter leaped from
bed and seized the instrument.
“That must be Clewes!”
Doyle talked for several minutes and then hung up the
receiver.
“Get dressed!” he said curtly. “We’re clearing out of
here. And we haven’t much time.”

94
“What’s up?”
“We move again. Clewes says to let the Melveredge
pictures slide. Arrangements can’t be made with the
authorities.”
“A new assignment?”
“Yeah. Not a bad one either. We’re to cover an
International polo match at Excelsior City. We ought to
be there not later than twelve-thirty.”
Flash looked at his watch and whistled.
“It’s nearly six now. Excelsior City must be at least three
hundred miles from here.”
“Nearer three twenty. It means fast stepping.”
Quickly they dressed and crammed their clothing into
suitcases. There was no time for breakfast. A clock on
the street chimed six-thirty as they pulled out of the
drowsing city.
A fog hung low over the valley. Before the sound truck
had covered many miles a fine, steady rain began to
fall.
Strangely, Doyle offered no complaint about either the
weather or the early morning call to duty. Flash stole a
curious glance at him. The technician’s face was
animated and he whistled a cheerful tune.
“This assignment seems to please you, Doyle.”
“It could be a lot worse.”

Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com