100% found this document useful (10 votes)
61 views

MATLAB Programming for Engineers 6th Edition Stephen J. Chapman - eBook PDF instant download

The document is a promotional overview of the 6th Edition of 'MATLAB Programming for Engineers' by Stephen J. Chapman, which focuses on teaching MATLAB as a technical programming language for engineering applications. It highlights the book's structure, including introductory and advanced topics, and emphasizes MATLAB's ease of use, predefined functions, and graphical capabilities. Additionally, it outlines the pedagogical features designed to aid student comprehension, such as quizzes, exercises, and good programming practices.

Uploaded by

jusbamindt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (10 votes)
61 views

MATLAB Programming for Engineers 6th Edition Stephen J. Chapman - eBook PDF instant download

The document is a promotional overview of the 6th Edition of 'MATLAB Programming for Engineers' by Stephen J. Chapman, which focuses on teaching MATLAB as a technical programming language for engineering applications. It highlights the book's structure, including introductory and advanced topics, and emphasizes MATLAB's ease of use, predefined functions, and graphical capabilities. Additionally, it outlines the pedagogical features designed to aid student comprehension, such as quizzes, exercises, and good programming practices.

Uploaded by

jusbamindt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

MATLAB Programming for Engineers 6th Edition

Stephen J. Chapman - eBook PDF pdf download

https://ebooksecure.com/download/matlab-programming-for-
engineers-ebook-pdf/

Download more ebook from https://ebooksecure.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebooksecure.com
to discover even more!

(eBook PDF) MATLAB Programming for Engineers 6th


Edition

http://ebooksecure.com/product/ebook-pdf-matlab-programming-for-
engineers-6th-edition/

Fortran for Scientists and Engineers 4th Edition


Stephen J. Chapman - eBook PDF

https://ebooksecure.com/download/fortran-for-scientists-and-
engineers-ebook-pdf/

MATLAB for Engineers 6th Edition Holly Moore - eBook


PDF

https://ebooksecure.com/download/matlab-for-engineers-ebook-pdf/

(eBook PDF) MATLAB for Engineers Global Edition 5th


Edition

http://ebooksecure.com/product/ebook-pdf-matlab-for-engineers-
global-edition-5th-edition/
(eBook PDF) MATLAB for Engineers 5th Edition by Holly
Moore

http://ebooksecure.com/product/ebook-pdf-matlab-for-
engineers-5th-edition-by-holly-moore/

Essential MATLAB for Engineers and Scientists 7th


Edition - eBook PDF

https://ebooksecure.com/download/essential-matlab-for-engineers-
and-scientists-ebook-pdf-2/

(eBook PDF) Essentials of MATLAB Programming 3rd


Edition

http://ebooksecure.com/product/ebook-pdf-essentials-of-matlab-
programming-3rd-edition/

Essential MATLAB for engineers and scientists 7th


Edition Hahn B.D. - eBook PDF

https://ebooksecure.com/download/essential-matlab-for-engineers-
and-scientists-ebook-pdf/

(eBook PDF) Applied Numerical Methods with MATLAB for


Engineers and Scientists 4th Edition

http://ebooksecure.com/product/ebook-pdf-applied-numerical-
methods-with-matlab-for-engineers-and-scientists-4th-edition/
MATLAB®
Programming
for Engineers
MATLAB®
Programming
for Engineers
Sixth Edition

Stephen J. Chapman
BAE Systems Australia

Australia • Brazil • Mexico • Singapore • Spain • United Kingdom • United States


MATLAB Programming for Engineers, © 2020, 2016, 2008 Cengage Learning, Inc.
Sixth Edition
Stephen J. Chapman Unless otherwise noted, all content is © Cengage

Product Director, Global Engineering: ALL RIGHTS RESERVED. No part of this work covered by the
Timothy L. Anderson copyright herein may be reproduced or distributed in any form

Senior Product Assistant: Alexander or by any means, except as permitted by U.S. copyright law,

Sham without the prior written permission of the copyright owner.

Content Developer: MariCarmen


Constable
For product information and technology assistance, contact us at
Associate Marketing Manager: Tori Cengage Customer & Sales Support, 1-800-354-9706
Sitcawich or support.cengage.com.

Content Manager: Marianne Groth


For permission to use material from this text or product,
IP Analyst: Nancy Dillon
submit all
IP Project Manager: Jillian Shafer requests online at www.cengage.com/permissions.

Production Service: RPK Editorial


Services, Inc. Library of Congress Control Number: 2018965078

Compositor: MPS Limited

Senior Designer: Diana Graham Student Edition:


ISBN: 978-0-357-03039-4
Cover Image: iStockPhoto.com/
Henrik5000 Loose-leaf Edition:
Manufacturing Planner: Doug Wilke ISBN: 978-0-357-03051-6

Cengage
20 Channel Center Street
Boston, MA 02210
USA

Cengage is a leading provider of customized learning solutions


with employees residing in nearly 40 different countries and
sales in more than 125 countries around the world. Find your
local representative at www.cengage.com.

Cengage products are represented in Canada by Nelson


Education, Ltd.

To learn more about Cengage platforms and services, register


or access your online learning solution, or purchase materials
for your course, visit www.cengage.com.

MATLAB is a registered trademark of The MathWorks, Inc.,


1 Apple Hill Drive, Natick, MA 01760-2098

Printed in the United States of America


Print Number: 01   Print Year: 2018
This book is dedicated with love to my youngest daughter Devorah,
who just finished high school. The last one!
Preface

MATLAB (short for MATrix LABoratory) is a special-purpose computer program


optimized to perform engineering and scientific calculations. It started life as a pro-
gram designed to perform matrix mathematics, but over the years it has grown into
a flexible computing system capable of solving essentially any technical problem.
The MATLAB program implements the MATLAB language and provides an
extensive library of predefined functions to make technical programming tasks
easier and more efficient. This extremely wide variety of functions makes it much
easier to solve technical problems in MATLAB than in other languages such as
Fortran or C. This book introduces the MATLAB language as it is implemented in
version R2018a and shows how to use it to solve typical technical problems.
This book teaches MATLAB as a technical programming language, showing
students how to write clean, efficient, and documented programs. It makes no pre-
tense at being a complete description of all of MATLAB’s hundreds of functions.
Instead, it teaches the student how to use MATLAB as a computer language and
how to locate any desired function with MATLAB’s extensive on-line help facilities.
The first eight chapters of the text are designed to serve as the text for an
“Introduction to Programming/Problem Solving” course for freshman engineer-
ing students. This material should fit comfortably into a 9-week, 3-hour-per-week
course. The remaining chapters cover advanced topics such as I/O, object-oriented
programming, and graphical user interfaces (GUIs). These chapters may be covered
in a longer course or used as a reference by engineering students or practicing engi-
neers who use MATLAB as a part of their coursework or employment.

Changes in the Sixth Edition


The sixth edition of this book is specifically devoted to MATLAB R2018a. In
the four years since the last release, there have been many changes in MATLAB.
vii
viii | Preface

The most significant of these changes include the introduction of the App
Designer, which includes a whole new paradigm for creating MATLAB apps; a
new family of plotting functions; and strings. There have also been many smaller
improvements throughout the program. The book has been revised to reflect
these changes.
The major changes in this edition of the book include:
■■ An increase in the number of MATLAB applications featured in the chapters,
with more end-of-chapter exercises using them.
■■ More extensive coverage of plots in Chapter 3 and Chapter 8. The discussion

now includes most of the currently recommended plot types in MATLAB.


Older deprecated plot types have been dropped from coverage as the new ones
have been added.
■■ Coverage of the new string data type, along with changes in the support for

character arrays.
■■ Coverage of the time data types: dateTime, duration, and
calendarDuration.
■■ Coverage of table arrays.

■■ A completely rewritten Chapter 14 featuring the new App Designer and class-

based GUIs.
■■ An extra on-line Chapter 15 featuring the older GUIDE-based GUIs; this

chapter can be downloaded from the book’s website.

The Advantages of MATLAB for Technical Programming


MATLAB has many advantages compared to conventional computer languages for
technical problem solving. Among them are:
1. Ease of Use
MATLAB is an interpreted language, like many versions of Basic. Like
Basic, it is very easy to use. The program can be used as a scratch pad to
evaluate expressions typed at the command line, or it can be used to execute
large pre-written programs. Programs may be easily written and modified
with the built-in integrated development environment and debugged with the
MATLAB debugger. Because the language is so easy to use, it is ideal for
educational use and for the rapid prototyping of new programs.
Many program development tools are provided to make the program
easy to use. They include an integrated editor/debugger, on-line documenta-
tion and manuals, a workspace browser, and extensive demos.
2. Platform Independence
MATLAB is supported on many different computer systems, providing a
large measure of platform independence. At the time of this writing, the
language is supported on Windows 7/8/10, Linux, and the Mac. Programs
written on any platform will run on all of the other platforms, and data files
written on any platform may be read transparently on any other platform.
Preface | ix

As a result, programs written in MATLAB can migrate to new platforms


when the needs of the user change.
3. Predefined Functions
MATLAB comes complete with an extensive library of predefined functions
that provide tested and prepackaged solutions to many basic technical tasks.
For example, suppose that you are writing a program that must calculate the
statistics associated with an input data set. In most languages, you would
need to write your own subroutines or functions to implement calculations
such as the arithmetic mean, standard deviation, median, and so forth. These
and hundreds of other functions are built right into the MATLAB language,
making your job much easier.
In addition to the large library of functions built into the basic
MATLAB language, there are many special-purpose toolboxes available to
help solve complex problems in specific areas. For example, a user can buy
standard toolboxes to solve problems in Signal Processing, Control Sys-
tems, Communications, Image Processing, and Neural Networks, among
many others.
4. Device-Independent Plotting
Unlike other computer languages, MATLAB has many integral plotting and
imaging commands. The plots and images can be displayed on any graphi-
cal output device supported by the computer on which MATLAB is running.
This capability makes MATLAB an outstanding tool for visualizing techni-
cal data.
5. Graphical User Interface
MATLAB includes tools that allow a programmer to interactively construct a
GUI for his or her program. With this capability, the programmer can design
sophisticated data analysis programs that can be operated by relatively inex-
perienced users.

Features of This Book


Many features of this book are designed to emphasize the proper way to write reli-
able MATLAB programs. These features should serve a student well as he or she
is first learning MATLAB and should also be useful to the practitioner on the job.
These features include:
1. Emphasis on Top-Down Design Methodology
The book introduces a top-down design methodology in Chapter 4 and
then uses it consistently throughout the rest of the book. This methodology
encourages a student to think about the proper design of a program before
beginning to code. It emphasizes the importance of clearly defining the
problem to be solved and the required inputs and outputs before any other
work is begun. Once the problem is properly defined, the methodology
teaches the student to employ stepwise refinement to break the task down
x | Preface

into successively smaller sub-tasks, and to implement the sub-tasks as sepa-


rate subroutines or functions. Finally, it teaches the importance of testing
at all stages of the process, both unit testing of the component routines and
exhaustive testing of the final product.
The formal design process taught by the book may be summarized as
follows:
1. Clearly state the problem that you are trying to solve.
2. Define the inputs required by the program and the outputs to be pro-
duced by the program.
3. Describe the algorithm that you intend to implement in the program.
This step involves top-down design and stepwise decomposition,
using pseudocode or flow charts.
4. Turn the algorithm into MATLAB statements.
5. Test the MATLAB program. This step includes unit testing of specific
functions as well as exhaustive testing of the final program with many
different data sets.
2. Emphasis on Functions
The book emphasizes the use of functions to logically decompose tasks
into smaller subtasks. It teaches the advantages of functions for data hid-
ing. It also emphasizes the importance of unit testing functions before
they are combined into the final program. In addition, the book teaches
about the common mistakes made with functions and how to avoid them.
3. Emphasis on MATLAB Tools
The book teaches the proper use of MATLAB’s built-in tools to make
programming and debugging easier. The tools covered include the Editor/
Debugger, Workspace Browser, Help Browser, and GUI design tools.
4. Good Programming Practice Boxes
These boxes highlight good programming practices when they are intro-
duced for the convenience of the student. In addition, the good programming
practices introduced in a chapter are summarized at the end of the chapter.
An example Good Programming Practice Box is as follows:

Good Programming Practice


Always indent the body of an if construct by two or more spaces to improve the
readability of the code.

5. Programming Pitfalls Boxes


These boxes highlight common errors so that they can be avoided. An
example Programming Pitfalls Box is as follows:
Preface | xi

Programming Pitfalls
Make sure that your variable names are unique in the first 31 characters. Otherwise,
MATLAB will not be able to tell the difference between them.

6. Emphasis on Data Structures


Chapter 10 contains a detailed discussion of MATLAB data structures,
including sparse arrays, cell arrays, and structure arrays. The proper use
of these data structures is illustrated in the chapters on handle graphics
(Chapter 13) and graphical user interfaces (Chapter 14).
7. Emphasis on Object-Oriented MATLAB
Chapter 12 includes an introduction to object-oriented programming (OOP)
and describes the MATLAB implementation of OOP in detail. This informa-
tion is then applied in the discussion of App Designer GUIs.

Pedagogical Features
The first eight chapters of this book are specifically designed to be used in a fresh-
man “Introduction to Program/Problem Solving” course. It should be possible to
cover this material comfortably in a 9-week, 3-hour-per-week course. If there is
insufficient time to cover all of the material in a particular Engineering program,
Chapter 8 may be omitted, and the remaining material will still teach the fundamen-
tals of programming and using MATLAB to solve problems. This feature should
appeal to harassed engineering educators trying to cram ever more material into a
finite curriculum.
The remaining chapters cover advanced material that will be useful to the
engineer and engineering students as they progress in their careers. This material
includes advanced I/O, object-oriented programming, and the design of GUIs for
programs.
The book includes several features designed to aid student comprehension. A
total of 20 quizzes appear scattered throughout the chapters, with answers to all
questions included in Appendix B. These quizzes can serve as a useful self-test of
comprehension. In addition, there are approximately 230 end-of-chapter exercises.
Answers to all exercises are included in the Instructor’s Solutions Manual. Good
programming practices are highlighted in all chapters with special Good Program-
ming Practice boxes, and common errors are highlighted in Programming Pitfalls
boxes. End-of-chapter materials include Summaries of Good Programming Practice
and Summaries of MATLAB Commands and Functions.
The book is accompanied by an Instructor’s Solutions Manual, which contains
the solutions to all end-of-chapter exercises. The source code for all examples in
xii | Preface

the book is available from the book’s website at https://login.cengage.com, and the
source code for all solutions in the Instructor’s Manual is available separately to
instructors.

A Final Note to the User


No matter how hard I try to proofread a document like this book, it is inevitable that
some typographical errors will slip through and appear in print. If you should spot
any such errors, please drop me a note via the publisher, and I will do my best to
get these errors eliminated from subsequent printings and editions. Thank you very
much for your help in this matter.
I will maintain a complete list of errata and corrections at the book’s website,
which is available through https://login.cengage.com. Please check that site for any
updates and/or corrections.

Acknowledgments
I would like to thank all my friends at Cengage Learning for the support they have
given me in getting this book to market.
In addition, I would like to thank my wife Rosa, and our children Avi, David,
Rachel, Aaron, Sarah, Naomi, Shira, and Devorah for their help and encouragement.

Stephen J. Chapman
Melbourne, Australia
Digital Resources

New Digital Solution for Your Engineering Classroom


WebAssign is a powerful digital solution designed by educators to enrich the engi-
neering teaching and learning experience. With a robust computational engine at
its core, WebAssign provides extensive content, instant assessment, and superior
support.
WebAssign’s powerful question editor allows engineering instructors to cre-
ate their own questions or modify existing questions. Each question can use any
combination of text, mathematical equations and formulas, sound, pictures, video,
and interactive HTML elements. Numbers, words, phrases, graphics, and sound or
video files can be randomized so that each student receives a different version of
the same question.
In addition to common question types such as multiple choice, fill-in-
the-blank, essay, and numerical, you can also incorporate robust answer entry
palettes (­mathPad, chemPad, calcPad, physPad, pencilPad, Graphing Tool) to
input and grade symbolic expressions, equations, matrices, and chemical struc-
tures using powerful computer algebra systems. You can even use ­Camtasia to
embed “clicker” questions that are automatically scored and recorded in the
­GradeBook.

xiii
xiv | Digital Resources

WebAssign Offers Engineering Instructors the Following


■■ The ability to create and edit algorithmic and numerical exercises.
■■ The opportunity to generate randomized iterations of algorithmic and numeri-
cal exercises. When instructors assign numerical WebAssign homework exer-
cises (­engineering math exercises), the WebAssign program offers them the
ability to generate and assign their students differing versions of the same
engineering math exercise. The computational engine extends beyond and
provides the luxury of solving for correct solutions/answers.
■■ The ability to create and customize numerical questions, allowing students to

enter units, use a specific number of significant digits, use a specific number of
decimal places, respond with a computed answer, or answer within a different
tolerance value than the default.
Visit https://www.webassign.com/instructors/features/ to learn more. To create an account,
instructors can go directly to the signup page at http://www.webassign.net/signup.html.

MindTap Reader
Available via WebAssign and our digital subscription service, Cengage Unlimited,
MindTap Reader is Cengage’s next-generation eBook for engineering students.
The MindTap Reader provides more than just text learning for the student. It
offers a variety of tools to help our future engineers learn chapter concepts in a way
that ­resonates with their workflow and learning styles.
■■ Personalize their ­experience
Within the MindTap Reader, students can h­ ighlight key concepts, add notes, and
bookmark pages. These are collected in My Notes, ensuring they will have their own
study guide when it comes time to study for exams.
Digital Resources | xv

■■ Flexibility at their fingertips


With access to Merriam-Webster’s Dictionary and the book’s internal glossary,
students can personalize their study experience by creating and collating their own
custom flashcards. The ReadSpeaker feature reads text aloud to students, so they can
learn on the go—wherever they are.

■■ Review concepts at point of use


Within WebAssign, a “Read It” button at the bottom of each question links students
to corresponding sections of the textbook, enabling access to the MindTap Reader
at the precise moment of learning. A “Watch It” button causes a short video to play.
These videos allow students to better understand and review the problem they need
to complete, enabling support at the precise moment of learning.
xvi | Digital Resources

The MindTap Mobile App


Available on iOS and Android smartphones, the MindTap Mobile App provides
convenience. Students can access their entire textbook anyplace and anytime. They
can take notes, highlight important passages, and have their text read aloud whether
they are on-line or off.
To download the mobile app, visit https://www.cengage.com/mindtap
/mobileapp.

All-You-Can-Learn Access with Cengage Unlimited


Cengage Unlimited is the first-of-its-kind digital subscription that gives students
total and on-demand access to all the digital learning platforms, eBooks, on-line
homework, and study tools Cengage has to offer—in one place, for one price. With
Cengage ­Unlimited, students get access to their WebAssign courseware, as well as
content in other Cengage platforms and course areas from day one. That’s 70 disci-
plines and 675 courses worth of material, including engineering.
With Cengage Unlimited, students get unlimited access to a library of more than
22,000 products. To learn more, visit https://www.cengage.com/unlimited.
Contents

Chapter 1 Introduction to MATLAB 1


1.1 The Advantages of MATLAB 2
1.2 Disadvantages of MATLAB 3
1.3 The MATLAB Environment 4
1.3.1 The MATLAB Desktop 4
1.3.2 The Command Window 6
1.3.3 The Toolstrip 7
1.3.4 The Command History Window 8
1.3.5 The Document Window 8
1.3.6 Figure Windows 11
1.3.7 Docking and Undocking Windows 12
1.3.8 The MATLAB Workspace 12
1.3.9 The Workspace Browser 14
1.3.10 The Current Folder Browser 14
1.3.11 Getting Help 15
1.3.12 A Few Important Commands 18
1.3.13 The MATLAB Search Path 19
1.4 Using MATLAB as a Calculator 21
1.5 MATLAB Script Files 23
1.5.1 Setting Up a Problem to Solve 24
1.5.2 Creating a Simple MATLAB Script File 24
1.6 Summary 28
1.6.1 MATLAB Summary 28
1.7 ­­Exercises 29

Chapter 2 MATLAB Basics 33


2.1 Variables and Arrays 33
xvii
xviii | Contents

2.2 Creating and Initializing Variables in MATLAB 37


2.2.1 Initializing Variables in Assignment Statements 37
2.2.2 Initializing with Shortcut Expressions 40
2.2.3 Initializing with Built-In Functions 41
2.2.4 Initializing Variables with Keyboard Input 41
2.3 Multidimensional Arrays 43
2.3.1 Storing Multidimensional Arrays in Memory 45
2.3.2 Accessing Multidimensional Arrays with One
Dimension 46
2.4 Subarrays 46
2.4.1 The end Function 47
2.4.2 Using Subarrays on the Left-Hand Side of an Assignment
Statement 47
2.4.3 Assigning a Scalar to a Subarray 49
2.5 Special Values 49
2.6 Displaying Output Data 51
2.6.1 Changing the Default Format 52
2.6.2 The disp Function 53
2.6.3 Formatted Output with the fprintf Function 54
2.7 Data Files 55
2.8 Scalar and Array Operations 58
2.8.1 Scalar Operations 58
2.8.2 Array and Matrix Operations 58
2.9 Hierarchy of Operations 62
2.10 Built-in MATLAB Functions 65
2.10.1 Optional Results 65
2.10.2 Using MATLAB Functions with Array Inputs 65
2.10.3 Common MATLAB Functions 66
2.11 Introduction to Plotting 67
2.11.1 Using Simple xy Plots 68
2.11.2 Printing a Plot 69
2.11.3 Multiple Plots 70
2.11.4 Line Color, Line Style, Marker Style, and Legends 71
2.12 Examples 75
2.13 MATLAB Applications:Vector Mathematics 82
2.13.1 Vector Addition and Subtraction 84
2.13.2 Vector Multiplication 85
2.14 MATLAB Applications: Matrix Operations
and Simultaneous Equations 90
2.14.1 The Matrix Inverse 91
2.15 Debugging MATLAB Programs 92
2.16 Summary 94
2.16.1 Summary of Good Programming Practice 95
2.16.2 MATLAB Summary 96
2.17 Exercises 99
Contents | xix

Chapter 3 Two-Dimensional Plots 111


3.1 Additional Plotting Features for Two-Dimensional Plots 111
3.1.1 Logarithmic Scales 111
3.1.2 Controlling x- and y-axis Plotting Limits 116
3.1.3 Plotting Multiple Plots on the Same Axes 117
3.1.4 Creating Multiple Figures 117
3.1.5 Subplots 121
3.1.6 Controlling the Spacing between Points on a Plot 122
3.1.7 Enhanced Control of Plotted Lines 126
3.1.8 Enhanced Control of Text Strings 127
3.2 Polar Plots 130
3.3 Annotating and Saving Plots 132
3.4 Additional Types of Two-Dimensional Plots 135
3.5 Using the plot Function with Two-Dimensional Arrays 140
3.6 Plots with Two y Axes 142
3.7 Summary 149
3.7.1 Summary of Good Programming Practice 150
3.7.2 MATLAB Summary 151
3.8 Exercises 151

Chapter 4 Branching Statements and Program Design 157


4.1 Introduction to Top-Down Design Techniques 157
4.2 Use of Pseudocode 161
4.3 The logical Data Type 162
4.3.1 Relational and Logic Operators 162
4.3.2 Relational Operators 163
4.3.3 A Caution About the == and ~= Operators 164
4.3.4 Logic Operators 165
4.3.5 Logical Functions 169
4.4 Branches 171
4.4.1 The if Construct 171
4.4.2 Examples Using if Constructs 173
4.4.3 Notes Concerning the Use of if Constructs 179
4.4.4 The switch Construct 182
4.4.5 The try/catch Construct 183
4.5 More on Debugging MATLAB Programs 189
4.6 Code Sections 196
4.7 MATLAB Applications: Roots of Polynomials 198
4.8 Summary 201
4.8.1 Summary of Good Programming Practice 201
4.8.2 MATLAB Summary 202
4.9 Exercises 203
xx | Contents

Chapter 5 Loops and Vectorization 207


5.1 The while Loop 207
5.2 The for Loop 213
5.2.1 Details of Operation 220
5.2.2 Vectorization: A Faster Alternative to Loops 222
5.2.3 The MATLAB Just-In-Time (JIT) Compiler 223
5.2.4 The break and continue Statements 227
5.2.5 Nesting Loops 228
5.3 Logical Arrays and Vectorization 229
5.3.1 Creating the Equivalent of if/else Constructs
with Logical Arrays 230
5.4 The MATLAB Profiler 232
5.5 Additional Examples 235
5.6 The textread Function 250
5.7 MATLAB Applications: Statistical Functions 252
5.8 MATLAB Applications: Curve Fitting and Interpolation 255
5.8.1 General Least-Squares Fits 255
5.8.2 Cubic Spline Interpolation 262
5.8.3 Interactive Curve-Fitting Tools 267
5.9 Summary 271
5.9.1 Summary of Good Programming Practice 271
5.9.2 MATLAB Summary 272
5.10 Exercises 272

Chapter 6 Basic User-Defined Functions 283


6.1 Introduction to MATLAB Functions 284
6.2 Variable Passing in MATLAB:The Pass-by-Value Scheme 290
6.3 Optional Arguments 300
6.4 Sharing Data Using Global Memory 305
6.5 Preserving Data between Calls to a Function 313
6.6 Built-In MATLAB Functions: Sorting Functions 318
6.7 Built-In MATLAB Functions: Random Number Functions 320
6.8 Summary 320
6.8.1 Summary of Good Programming Practice 321
6.8.2 MATLAB Summary 321
6.9 Exercises 322

Chapter 7 Advanced Features of User-Defined Functions 331


7.1 Function Functions 331
7.2 Function Handles 336
Contents | xxi

7.3 Functions eval and feval 341


7.4 Local Functions, Private Functions, and Nested Functions 342
7.4.1 Local Functions 342
7.4.2 Private Functions 344
7.4.3 Nested Functions 345
7.4.4 Order of Function Evaluation 348
7.4.5 Function Handles and Nested Functions 348
7.4.6 The Significance of Function Handles 350
7.5 An Example Application: Solving Ordinary
Differential Equations 351
7.6 Anonymous Functions 358
7.7 Recursive Functions 359
7.8 Plotting Functions 360
7.9 Histograms 362
7.10 An Example Application: Numerical Integration 368
7.11 Summary 374
7.11.1 Summary of Good Programming Practice 374
7.11.2 MATLAB Summary 375
7.12 Exercises 375

Chapter 8 Complex Numbers and Additional Plots 385


8.1 Complex Data 385
8.1.1 Complex Variables 387
8.1.2 Using Complex Numbers with Relational Operators 387
8.1.3 Complex Functions 388
8.1.4 Plotting Complex Data 394
8.2 Multidimensional Arrays 397
8.3 Gallery of MATLAB Plots 399
8.4 Line Plots 410
8.4.1 The plot3 Function 410
8.4.2 Changing the Viewpoint of Three-dimensional Plots 414
8.4.3 The fplot3 Function 414
8.4.4 The fimplicit Function 415
8.5 Discrete Data Plots 417
8.5.1 The stem3 Function 419
8.5.2 The scatter Function 420
8.5.3 The scatter3 Function 424
8.6 Polar Plots 426
8.6.1 The compass Function 429
8.6.2 The ezpolar Function 429
8.7 Contour Plots 431
8.7.1 Function contour 431
8.7.2 Function contourf 433
xxii | Contents

8.7.3 Function contour3 435


8.7.4 Function fcontour 435
8.8 Surface and Mesh Plots 436
8.8.1 Creating Surface and Mesh Plots 437
8.8.2 Creating Three-Dimensional Objects using Surface
and Mesh Plots 442
8.8.3 Ribbon Plots 444
8.8.4 Function pcolor 445
8.8.5 Functions fsurf and fmesh 447
8.8.6 Function fimplicit3 448
8.9 Pie Charts, Bar Plots, and Histograms 450
8.9.1 The area Function 451
8.9.2 Bar Plots 452
8.9.3 Two-Dimensional Histograms 456
8.10 Color Order, Color Maps, and Color Bars 457
8.10.1 Plot Color Order 457
8.10.2 Color Maps 459
8.10.3 Color Bars 459
8.11 Summary 463
8.11.1 Summary of Good Programming Practice 463
8.11.2 MATLAB Summary 463
8.12 Exercises 464

Chapter 9 Additional Data Types 471


9.1 Character Arrays versus Strings 472
9.1.1 Character Arrays 472
9.1.2 Strings 473
9.2 Character Arrays and Character Functions 473
9.2.1 Character Array Conversion Functions 474
9.2.2 Creating Two-Dimensional Character Arrays 475
9.2.3 Concatenating Character Arrays 476
9.2.4 Comparing Character Arrays 476
9.2.5 Searching/Replacing Characters within a Character Array 480
9.2.6 Uppercase and Lowercase Conversion 481
9.2.7 Trimming Whitespace from Strings 482
9.2.8 Numerical-to-Character Array Conversions 482
9.2.9 String-to-Numerical Conversions 484
9.3 The string Data Type 490
9.3.1 Creating Strings 491
9.3.2 Converting Data into Strings 491
9.3.3 Converting Strings to Other Data Types 493
9.3.4 Concatenating Strings 494
9.3.5 Comparing Strings 494
9.3.6 Searching for Substrings within a String 495
Contents | xxiii

9.3.7 Extracting Substrings from a String 496


9.3.8­ Inserting Strings into a String 497
9.3.9 Replacing Characters within a String 497
9.3.10 Erasing Characters in a String 498
9.3.11 Uppercase and Lowercase Conversion 499
9.3.12 Trimming Whitespace from Strings 499
9.4 Summary of Character Array and String Functions 499
9.5 The single Data Type 503
9.6 Integer Data Types 504
9.7 Limitations of the single and Integer Data Types 505
9.8 The datetime and duration Data Types 507
9.8.1 The datetime Data Type 507
9.8.2 The duration Data Type 508
9.8.3 calendarDuration Arrays 508
9.8.4 Time Calculations 509
9.8.5 Using Time Data in MATLAB 511
9.9 Summary 513
9.9.1 Summary of Good Programming Practice 513
9.9.2 MATLAB Summary 513
9.10 Exercises 514

Chapter 10 Sparse Arrays, Cell Arrays, Structures,


and Tables 517
10.1 Sparse Arrays 517
10.1.1 The sparse Attribute 519
10.2 Cell Arrays 525
10.2.1 Creating Cell Arrays 527
10.2.2 Using Braces {} as Cell Constructors 528
10.2.3 Viewing the Contents of Cell Arrays 528
10.2.4 Extending Cell Arrays 529
10.2.5 Deleting Cells in Arrays 531
10.2.6 Using Data in Cell Arrays 532
10.2.7 Cell Arrays of Strings 532
10.2.8 The Significance of Cell Arrays 534
10.2.9 Summary of cell Functions 538
10.3 Structure Arrays 539
10.3.1 Creating Structure Arrays 539
10.3.2 Adding Fields to Structures 542
10.3.3 Removing Fields from Structures 542
10.3.4 Using Data in Structure Arrays 543
10.3.5 The getfield and setfield Functions 544
10.3.6 Dynamic Field Names 545
10.3.7 Using the size Function with Structure Arrays 546
xxiv | Contents

10.3.8 Nesting Structure Arrays 547


10.3.9 Summary of structure Functions 548
10.4 Table Arrays 548
10.4.1 Creating Table Arrays 548
10.4.2 Accessing Data in a Table 551
10.4.3 Table Metadata (Properties) 552
10.4.4 Examining the Contents and Properties of a Table 553
10.4.5 Table Summary 554
10.5 Summary 560
10.5.1 Summary of Good Programming Practice 560
10.5.2 MATLAB Summary 561
10.6 Exercises 561

Chapter 11 Input-Output Functions 565


11.1 The textread Function 565
11.2 More about the load and save Commands 567
11.3 An Introduction to MATLAB File Processing 570
11.4 File Opening and Closing 571
11.4.1 The fopen Function 571
11.4.2 The fclose Function 574
11.5 Binary I/O Functions 575
11.5.1 The fwrite Function 575
11.5.2 The fread Function 575
11.6 Formatted I/O Functions 580
11.6.1 The fprintf Function 580
11.6.2 Understanding Format Conversion Specifiers 581
11.6.3 How Format Strings Are Used 583
11.6.4 The sprintf Function 585
11.6.5 The fscanf Function 587
11.6.6 The fgetl Function 588
11.6.7 The fgets Function 589
11.7 Comparing Formatted and Binary I/O Functions 589
11.8 File Positioning and Status Functions 594
11.8.1 The exist Function 595
11.8.2 The ferror Function 597
11.8.3 The feof Function 598
11.8.4 The ftell Function 598
11.8.5 The frewind Function 598
11.8.6 The fseek Function 598
11.9 The textscan Function 604
11.10 Function uiimport 606
11.11 Summary 609
11.11.1 Summary of Good Programming Practice 610
11.11.2 MATLAB Summary 610
11.12 Exercises 611
Contents | xxv

Chapter 12 User-Defined Classes and


Object-Oriented Programming 615
12.1 An Introduction to Object-Oriented Programming 615
12.1.1 Objects 616
12.1.2 Messages 617
12.1.3 Classes 617
12.1.4 Static Methods 618
12.1.5 Class Hierarchy and Inheritance 620
12.1.6 Object-Oriented Programming 620
12.2 The Structure of a MATLAB Class 621
12.2.1 Creating a Class 622
12.2.2 Adding Methods to a Class 624
12.2.3 Listing Class Types, Properties, and Methods 628
12.2.4 Attributes 629
12.3 Value Classes versus Handle Classes 633
12.3.1 Value Classes 634
12.3.2 Handle Classes 635
12.4 Destructors: The delete Method 638
12.5 Access Methods and Access Controls 640
12.5.1 Access Methods 640
12.5.2 Access Controls 642
12.5.3 Example: Creating a Timer Class 642
12.5.4 Notes on the MyTimer Class 647
12.6 Static Methods 648
12.7 Defining Class Methods in Separate Files 649
12.8 Overriding Operators 650
12.9 Events and Listeners 655
12.9.1 Property Events and Listeners 658
12.10 Exceptions 659
12.10.1 Creating Exceptions in Your Own Programs 660
12.10.2 Catching and Fixing Exceptions 661
12.11 Superclasses and Subclasses 662
12.11.1 Defining Superclasses and Subclasses 663
12.11.2 Example Using Superclasses and Subclasses 668
12.12 Summary 678
12.12.1 Summary of Good Programming Practice 679
12.12.2 MATLAB Summary 679
12.13 Exercises 680

Chapter 13 Handle Graphics and Animation 685


13.1 Handle Graphics 685
13.2 The MATLAB Graphics System 686
13.3 Object Handles 688
xxvi | Contents

13.4 Examining and Changing Object Properties 689


13.4.1 Changing Object Properties at Creation Time 689
13.4.2 Changing Object Properties after Creation Time 689
13.4.3 Examining and Changing Properties
Using Object Notation 690
13.4.4 Examining and Changing Properties Using
get/set Functions 692
13.4.5 Examining and Changing Properties Using
the Property Editor 694
13.5 Using set to List Possible Property Values 698
13.6 User-Defined Data 700
13.7 Finding Objects 701
13.8 Selecting Objects with the Mouse 703
13.9 Position and Units 706
13.9.1 Positions of figure Objects 706
13.9.2 Positions of axes and polaraxes Objects 707
13.9.3 Positions of text Objects 707
13.10 Printer Positions 710
13.11 Default and Factory Properties 711
13.12 Restoring Default Properties 713
13.13 Graphics Object Properties 713
13.14 Animations and Movies 714
13.14.1 Erasing and Redrawing 714
13.14.2 Creating a Movie 719
13.15 Summary 721
13.15.1 Summary of Good Programming Practice 721
13.15.2 MATLAB Summary 721
13.16 Exercises 722

Chapter 14 MATLAB Apps and Graphical User Interfaces 725


14.1 How a Graphical User Interface Works 726
14.2 Creating and Displaying a Graphical User Interface 732
14.2.1 The Structure of a Callback Function (Method) 738
14.2.2 Adding Application Data to a Figure 739
14.3 Object Properties 739
14.3.1 Key Properties of Numerical Components 741
14.3.2 Key Properties of Text Components 743
14.4 Additional Containers: Panels,Tab Groups,
and Button Groups 749
14.4.1 Panels 749
14.4.2 Tab Groups 752
14.4.3 Button Groups 752
14.5 Dialog Boxes 754
14.5.1 Alert Dialog Boxes 755
Contents | xxvii

14.5.2 Confirmation Dialog Boxes 755


14.5.3 Input Dialog Boxes 757
14.5.4 The uigetfile, uisetfile, and uigetdir Dialog
Boxes 757
14.5.5 The uisetcolor and uisetfont Dialog Boxes 759
14.6 Menus 760
14.6.1 Creating Your Own Menus 763
14.6.2 Accelerator Keys and Keyboard Mnemonics 763
14.7 Summary 774
14.7.1 Summary of Good Programming Practice 775
14.7.2 MATLAB Summary 775
14.8 Exercises 777

A UTF-8 Character Set 779

B Answers to Quizzes 781

Index 807

Chapter 15 Guide-Based Graphical User Interfaces (On-line Only)


15.1 How a Graphical User Interface Works
15.2 Creating and Displaying a Graphical User Interface
15.2.1 A Look Under the Hood
15.2.2 The Structure of a Callback Subfunction
15.2.3 Adding Application Data to a Figure
15.2.4 A Few Useful Functions
15.3 Object Properties
15.4 Graphical User Interface Components
15.4.1 Static Text Fields
15.4.2 Edit Boxes
15.4.3 Pushbuttons
15.4.4 Toggle Buttons
15.4.5 Checkboxes and Radio Buttons
15.4.6 Popup Menus
15.4.7 List Boxes
15.4.8 Sliders
15.4.9 Tables
15.5 Additional Containers: Panels and Button Groups
15.5.1 Panels
15.5.2 Button Groups
15.6 Dialog Boxes
15.6.1 Error and Warning Dialog Boxes
15.6.2 Input Dialog Boxes
xxviii | Contents

15.6.3 The uigetfile, uisetfile, and uigetdir Dialog Boxes


15.6.4 The uisetcolor and uisetfont Dialog Boxes
15.7 Menus
15.7.1 Suppressing the Default Menu
15.7.2 Creating Your Own Menus
15.7.3 Accelerator Keys and Keyboard Mnemonics
15.7.4 Creating Context Menus
15.8 Tips for Creating Efficient GUIs
15.8.1 Tool Tips
15.8.2 Toolbars
15.8.3 Additional Enhancements
15.9 Summary
15.9.1 Summary of Good Programming Practice
15.9.2 MATLAB Summary
15.10 Exercises
Chapter 1
Introduction to MATLAB

MATLAB (short for MATrix LABoratory) is a special-purpose computer program


optimized to perform engineering and scientific calculations. It started life as a pro-
gram designed to perform matrix mathematics, but over the years it has grown into
a flexible computing system capable of solving essentially any technical problem.
The MATLAB program implements the MATLAB programming language and
provides a very extensive library of predefined functions to make technical pro-
gramming tasks easier and more efficient. This book introduces the MATLAB lan-
guage as it is implemented in MATLAB Version 2018A and shows how to use it to
solve typical technical problems.
MATLAB is a huge program with an incredibly rich variety of functions. Even the
basic version of MATLAB without any toolkits is much richer than other technical
programming languages. There are more than 1000 functions in the basic MATLAB
product alone, and the toolkits extend this capability with many more functions in
various specialties. Furthermore, these functions often solve very complex problems
(solving differential equations, inverting matrices, and so forth) in a single step, saving
large amounts of time. Doing the same thing in another computer language usually
involves writing complex programs yourself or buying a third-party software pack-
age (such as IMSL, the Intel® Math Kernel Library, or the NAG software libraries)
that contains the functions.
The built-in MATLAB functions are almost always better than anything that
an individual engineer could write on his or her own because many people have
worked on them, and they have been tested against many different data sets. These
functions are also robust, producing sensible results for wide ranges of input data
and gracefully handling error conditions.
This book makes no attempt to introduce users to all of MATLAB’s functions.
Instead, it teaches users the basics of how to write, debug, and optimize good MATLAB
programs, and it introduces a subset of the most important functions used to
solve common scientific and engineering problems. Just as importantly, it teaches

1
Discovering Diverse Content Through
Random Scribd Documents
"We'll fight her," declared von Giespert vehemently, for he realized
that the game was a desperate one. "Serve out the arms, Herr
Strauss. Himmel! What would I give now for a submerged torpedo-
tube? Would that she piled herself upon the reef. She nearly did it
last time."

"Harborough is more cautious this time," observed Strauss. "He's


coming in under power."

"He is, curse him," growled the other.

The two Germans watched in silence as the Titania, with her


exhaust chortling noisily, passed through the narrow gap and
starboarded helm, steering for the opposite part of the lagoon to
that where the Zug lay at anchor. That was another puzzler to the
already bewildered von Giespert.

Presently the yacht reversed engines and lost way broadside on to


and at about a mile from her rival. Then, to the consternation of the
crew of the Zug, a large gun, of a calibre certainly not less than 4.7
inches, was ominously visible betwixt fore- and main-masts.
Simultaneously, and without any preparatory signal, a hoist of the
letters VOX—"I am going to semaphore to you"—fluttered from the
Titania's main truck.

Slowly, reluctantly, the answering pennant was displayed from the


Zug.

"I thought you informed me that yonder yacht was unarmed,"


exclaimed von Giespert, turning furiously upon his henchman,
Strauss.

"She was when we left Southampton, Herr Kapitan," replied


Strauss. "That I can swear to, because we had her under
observation all the time. Of course, she might have——"
"They're semaphoring," interrupted von Giespert. He himself could
not follow the quick movements of the red and yellow hand-flags,
but most of the Zug's crew could. More than that, they could read
the peremptory message although it was sent in English.

"Hand over my airman, Claverhouse, instantly," it read, "or I will


blow your bridge and charthouse to blazes."

Von Giespert chose the first alternative.

Three quarters of an hour later the Titania, with Alec Claverhouse


once more on board, was bowling along at a steady nine knots for
Nua Leha.

Then it was that Harborough, with a playful movement of one


hand, toppled the formidable 4.7 inch gun through the hatch into
the fore-hold. The mounting followed with a distinctly "tinny" sound.
The feat was an easy one, since the "gun" consisted of a twelve-foot
length of stove-pipe, and the mounting a piece of sheet iron and an
empty oil-drum.

"So friend von Giespert is breathing out threatenings and slaughter,


eh?" he laughed. "From what I know of him, his bark is worse than
his bite, but we'll have to watch him pretty carefully in the future."

CHAPTER XXVII
A Submarine Duel

It was not until the morning of the fifth day after the storm that
operations upon the wreck of the Fusi Yama were resumed.
Since it was found upon a second examination that the hull of the
motor-boat was somewhat strained and required intricate repairs
before it could be rendered seaworthy, the motor was taken out and
installed on a strong platform supported by the gig and the whaler.
It meant devoting two boats to a duty formerly performed by one,
but the motor was necessary, since it worked the dynamo that in
turn provided light for the divers to work by.

Villiers and Swaine gained the wreck by following the guide-rope


from the beach. They found the rope buried deeply in the sand at
places, while another result of the gale was the almost entire
removal of the bed of mud on which the ship lay, its place being
taken by a deposit of sand and lumps of coral that had been
detached from the reef under the terrific force of the breakers.

More than once it required the united efforts of both men to lift the
rope clear of the sand that covered it, while in one spot an
accumulation of seaweed took a quarter of an hour's hard work
before the tenacious tendrils could be cut and the rope exposed.

Upon gaining the deck Villiers could see that the damage done by
the hurricane was considerable. Most of the deck-houses and the
promenade deck, which had stood the effect of four years'
submergence without much sign of deterioration, had been swept
away, while a vast quantity of sand had found its way below. This
was sufficient evidence to prove that the hurricane had been the
worst ever experienced at Nua Leha since the time when the Fusi
Yama had been scuttled.

Outside the strong-room things were not so bad. There were tons
of sand, but most of it had shifted owing to the list of the wreck, and
lay five or six feet high against the interior side of the ship.

Adjusting the powerful lamp, so that its rays showed directly into
the strong-room, Swaine beckoned to his companion to enter.
If Villiers expected to walk into a treasure-chamber glittering with
gold, he was mistaken. The place was piled with wooden boxes,
some of which had been wrenched open, displaying their rather dull
but heavy contents, but on the shelves, and secured from the
motion of the ship by steel grids, were canvas sacks. A few of these,
rotted by the action of the salt water or else hurriedly ripped open
when the Huns made a hasty examination of their booty, had shed a
shower of gold coins upon the boxes and on the floor. There were
British and Australian sovereigns, Japanese five-yen pieces, Chinese
gold taels, and five-dollar pieces, representing almost every
American republic on the Pacific coast, and mixed haphazardly.

With little delay the work of clearing the strong-room commenced.


New canvas sacks, weighted with pieces of iron, were lowered from
the boats above. Into these were poured the contents of the rotten
sacks, then at a prearranged signal the men on the raft hoisted the
precious specie to the surface.

It was a slow, laborious but at the same time pleasureable task.


Movements that could be quickly executed in air were greatly
retarded by the pressure of water, and by the time that the divers'
air-supply was showing signs of exhaustion only a quarter of the
coin had been salved.

For the next week the operations continued uninterruptedly. Villiers


and Swaine each making two descents a day.

Compared with the task of recovering the bullion, the preliminary


work of clearing the specie was simple. The bullion, packed tightly in
iron-bound boxes, had to be extricated bar by bar, for as originally
packed each case was too heavy, even under water, to be
manhandled.

There were delays, too, in transporting the recovered treasure to


the Titania, owing to the lack of sufficient boats, so that, according
to Villiers' estimate, three weeks would elapse before the precious
metal would be stowed in the yacht's hold.

Dick Beverley was enjoying himself immensely. He worked quite as


hard as anybody, and his one regret was that he had not been
allowed to don a diving-dress and make a descent. This Harborough
bluntly refused to allow.

"This is a salvage company, not a nursery for amateur divers," he


remarked, although his refusal was based upon his compact with
Bobby Beverley not to expose Dick to any unnecessary risk.

By common consent a substantial share of the treasure was to be


given to Pete. The man had earned it fairly. As a cook he was
painstaking and conscientious, and when not engaged in his duties
in the galley he was always ready and willing to bear a hand at other
work.

"What are you going to do with your little lot when we pay off,
Pete?" asked Villiers.

Pete's features were almost hidden by a mouth that stretched


practically from ear to ear as he gave a prodigious grin.

"Do, sah? Be coloured gen'lman at Barbadoes, Massa Villiers. Buy


top-hole swagger hotel an' get dollars from Yankee visitors. P'r'aps I
buy a sail-boat and take people round de islands. If any of you
gen'lmen come to Barbadoes, be sure to look up Massa Pete
Johnson. He put you up free, gratis, and for nothin'."

"Then you're not sorry that Captain Abe booted you out of the Lucy
M. Partington?" asked Bobby.

"No, sah." Pete evidently did not wish to reopen an unpleasant


incident, for he turned somewhat abruptly to O'Loghlin. "Say,
Massa," he asked anxiously, "you understan' motors. Will I be able to
run a swagger car? One that licks creation for goin' tarnation quick?"
"If you handle the steering-wheel of a car as well as you do a
frying-pan, you'll be a rattling good driver, Pete," replied O'Loghlin,
pushing aside his empty plate with a satisfied sigh.

The salvage operation continued without a hitch in glorious


weather and under ideal conditions. The divers' dread of sharks
seemed to have been a needless one, for the noise of the motors
and the activity of all hands had no doubt scared the tigers of the
deep.

One day Villiers was at work below, when he noticed a gaudily-


coloured fish dart out from behind a box, and graze his hand. The
fish was but a small one, less than six inches in length, but its dorsal
fins resembled trailing tendrils and its tail ended in two tapering
points.

Hardly paying any attention to the creature, for fishes were


continually swimming around the divers, Villiers began prising open
the metal-bound box. Before he had completed his task his arm was
throbbing frightfully, and his hand seemed to lose the power of
gripping things.

He "stuck it" for another ten minutes, then signed to Swaine that
he was finishing work. Before he reached dry ground he felt on the
point of collapse, and when he did gain the beach he toppled inertly
upon the sand, to the astonishment and alarm of Vivian and
Merridew, who were standing by to assist the diving-party.

They divested him of his diving-suit. By this time his arm had
swollen tremendously, and the flesh was turning a dull-grey colour.

Harborough, hastily summoned ashore, diagnosed the symptoms


as being similar to those of snake-bite, There were a couple of
minute punctures on the back of Jack's hand, through which the
poison had been transmitted to his veins.
For the next twelve hours it was touch and go with Jack Villiers. His
comrades plied him with enough raw whisky to make a man in
ordinary health helplessly intoxicated. They walked him up and down
without giving him the slightest chance of rest. The treatment was
drastic, but it was successful, and, although the arm remained
swollen and painful, the danger was past.

Much to his disgust, Villiers had to "stand down", and Swaine


carried on alone. That meant more delay, but it was unavoidable,
and things might have been worse. Further difficulties were met with
through the temporary breakdown of the submarine lighting
arrangements, and until that was rectified Swaine was perforce
obliged to relinquish his visits to the wreck.

"Look here, old man," said Jack, one morning as Swaine was
preparing for a descent. "I'm fit again. There is no reason why I
shouldn't go with you."

"Better wait till you've seen Harborough," objected Swaine. "You


might jolly well think you're all right, but I shouldn't like the
responsibility of passing you fit for duty."

"Right-o," agreed Jack, who saw the force of his fellow-diver's


argument. "Don't wait. I'll push off afloat and see what Harborough
has to say."

Swaine proceeded on the submarine work alone. Although glad of


Villier's company, he realized that the latter was far from being fit for
the strenuous toil demanded of a diver. He, Swaine, could do
sufficient work below to keep the surface-party busy, and the task of
recovering the treasure was now within measureable distance of
conclusion.

It was yet early. The morning mists had not entirely dispersed
when Swaine waded into the water, awkwardly at first, but with
more freedom as the leaden-weighted suit dipped beneath the
surface.
Swaine wasted no time in getting on board the wreck and setting
to work. He had now a fair amount of elbow-room, since most of the
metal-lined boxes had been removed, and a thousand pounds worth
of gold was being sent up every five minutes.

He felt in fine fettle and, to use his own expression, "full of beans".
So intent was he upon his task that the time slipped by rapidly, until
a slight buzzing noise in his ears warned him that the self-contained
air-reservoir was not far off a state of exhaustion. In fifteen minutes
the supply would be "dud", and it usually took him twenty minutes
to reach the shore.

He "knocked off" in a hurry; at the same time, he realized that if


things came to a pitch he could blow himself to the surface. This he
was loth to do, as the sudden ascent generally incapacitated a diver
for several hours.

Slipping over the side of the wreck and grasping the guide-rope,
Swaine began to make his way ashore as rapidly as the resistance of
the water permitted.

"Current's frightfully strong to-day," he soliloquized, as the rush of


water almost swept his feet from under him. As it was, he had to
hang on like grim death to the rope and haul himself along hand
over hand until he had crossed the track of the submarine stream.

Here the lagoon shoaled considerably. There was sufficient depth


to allow a pale-green light to penetrate to five or six fathoms of
water, while visibility increased a distance of ten or twelve feet.

Happening to turn his head within the immobile helmet and to


glance through the side plate-glass window, Swaine came to a
sudden halt and gave a gasp of surprise. Within three yards of him,
and floundering along on a slightly converging course, was a man in
a self-contained diver's suit.
"So Villiers has got into harness after all," he thought. "Wonder
how he came to lose touch with the direction-rope?"

He raised one hand in greeting, at the same time holding up the


rope that served as a guide between the wreck and the shore.

Then to his utter astonishment he discovered that it was not Jack


Villiers, nor indeed any of the Titania's men, indulging in a little
submarine expedition. The diving-dress was different in certain
details.

Swaine was not left long in doubt as to the stranger's intentions.


Apparently the other diver was as surprised as he was, for he halted,
swaying slightly in the comparatively feeble current. Then, slowly
fumbling, he drew out a knife that showed a pale, dull-greenish glint
in the subdued light.

Courageous though he was, Swaine felt his heart beating violently.


He was still undecided as to whether the stranger intended sticking
the point of the steel into him or whether he meant to cut the guide-
rope. In any case, Swaine realized that he would have to act on the
defensive.

Drawing his own knife, Swaine, holding on to the rope with his left
hand, planted his feet firmly and threw his weight slightly forward.
Then he awaited developments. He was handicapped by the fact
that his air-supply was now noticeably weak. He might, with
discretion, attempt to elude his antagonist, but he realized the
disadvantage of showing his back to a man who might possess a
greater degree of mobility. Nor did he fancy a knife-thrust as he was
in the act of blowing himself to the surface.

No, the issue had to be decided there and then.

Holding his knife dagger-wise across his chest, the unknown


assailant advanced. Swaine stood on the defensive. He was in an
awkward predicament, for the current that was helping his opponent
was against him.

The other feinted. It was a comparatively slow movement


compared with the lightning-like thrust of a practised fencer. The
pressure of the water was too great for rapidity of action.

Swaine was not prepared for what followed. His antagonist


arrested the blow and at the same time hacked ponderously with his
leaden-shod boot. The metal rasped on Swaine's bare knuckles
grasping the rope, as he stepped backwards to avoid the full force of
the blow. The next instant a cut with the keen blade of the other's
knife severed the guide-rope.

The sudden release of the tautened rope sent Swaine staggering a


good three yards. He found himself sprawling on the sandy bottom,
his efforts to regain his feet disturbing the sand to such an extent
that it was almost impossible to see anything beyond arm's length.

Not daring to transfer his knife from his right hand to his left,
Swaine fumbled for the release-valve of the buoyancy-flask. His
fingers, numbed with the glancing blow they had received, were
almost useless, and his head was swimming with the effect of the
now impure air. Before he could attain his immediate aim he saw the
distorted figure of his antagonist through the now clearing water.

Still struggling to regain his feet, the while guarding himself with
his knife, Swaine realized that the odds were very much against him.
He found himself vaguely wondering what the effect of a thrust
would be through the thick rubber and canvas fabric of his diving-
suit. All the same, he meant to stick it, and, if needs be, "die game".

The other approached warily, but there was a suggestion of


triumph in his movements. He began circling round his prostrate
opponent, seeking a favourable opportunity of closing. He hesitated,
possibly because he feared a ruse on the part of the Englishman,
who, with knife uplifted, kept turning so that he was always face to
face with his assailant. Obviously these wearing-out tactics were
telling upon Swaine. The longer the other delayed, the worse
became his state owing to the poor quality of his air-supply.

At length the unknown diver raised his arm to deal a stroke. He did
it dramatically, pausing with the blade held high above his head.

With senses dulled, Swaine steeled himself to meet the deadly


stroke, but the stroke never came.

A rush, a swirl of water, and a blurred vision of the other diver


sinking slowly on his face told Swaine that deliverance had come
from a totally unexpected quarter.

A huge shark, attracted by the glitter of the knife, had bitten off
the fellow's hand just above the wrist, at the same time tearing the
india-rubber cuff of his diving-dress and allowing a considerable
amount of air to escape.

The shark, finding its palate unpleasantly tickled by the sharp steel,
and not laying claim to be a sword-swallower, decided that one
mouthful was enough and made off for pastures new, leaving the
interrupted principals of the submarine duel to settle matters as best
they could.

CHAPTER XXVIII
The Explosion

The instinct of self-preservation, coupled with the fact that he yet


had a faint chance of escape, rallied the semi-torpid Swaine
sufficiently to enable him to take action.
He dropped the knife and groped for the release-valve of the
compressed-air reservoir. Half a turn, and he felt the buoyant air
rushing into the double folds of his diving-suit. Even as he realized
that he was parting company with the bottom of the lagoon he
found himself looking at his late antagonist, who was writhing in
agony, with a ruddy stream mixed with air-bubbles rising from the
clean-cut stump of his severed arm.

Not knowing why he did so, whether it was the irresponsible act of
a light-headed man, the sudden impulse of an overstrung brain, or
generous pity for a beaten foe, Swaine gripped the fellow by the
arm, at the same time turning the release-valve of his buoyancy-
flask full on.

Up he shot to the full extent of arm's length and no farther. The


lifting powers of the inflated diving-dress were sufficient only for
one. Weighed down by his former antagonist, Swaine saw no chance
of bringing the latter to the surface, until an inspiration seized him.
Having once set his hand to the plough, he was loth to turn back
until his task was completed.

The unknown's knife was at that moment seriously incommoding a


shark; his own had dropped, but he remembered it was attached by
a lanyard to his belt. He recovered it; then, still retaining his hold of
the other diver, he pulled himself down until he was able to slash the
lashings that secured the leaden weights to the fellow's chest and
shoulders.

Then, and then only, did both men rise to the surface, Swaine
horizontally, the other vertically owing to the fact that his feet were
still weighted with lumps of lead.

For the next hour, as far as Swaine was concerned, everything was
a blank.

He recovered consciousness to find himself lying on a mattress on


the deck of the Titania.
"How's the other bloke?" were his first words.

"The other bloke," replied Villiers, "is progressing favourably in the


circumstances."

As a matter of fact, although the fellow's identity was revealed


directly his helmet was removed, none of the others knew that a life-
and-death duel was in progress when the shark butted in so
opportunely. They were greatly surprised to find Swaine bob up
unconscious from the bottom, still grasping the apparently lifeless
form of his late antagonist—Siegfried Strauss.

While Villiers and Beverley set to work to restore their comrade to


consciousness, Harborough, O'Loghlin, and Trevear did a like office
for the German. They were puzzled as to the cause of the loss of the
man's hand, for the amputation had been performed as cleanly as if
by a knife, while the pressure of his rubber wrist-band had checked
what would have been a dangerous haemorrhage. Applying a
tourniquet before cutting away the diving-dress, the three amateur
surgeons felt that they had succeeded in saving the German's life
unless he sank under the effect of shock to the system.

Although curious to hear Swaine's version of the business, his


comrades wisely forbore to question him until he had completely
recovered from his narrow escape. Meanwhile they were putting
forward numerous conjectures as to the reason for Strauss'
submarine jaunt.

"Where could he have come from?" asked Beverley. "The Zug isn't
anywhere in sight."

"Unless she's off the other side of the island," added Villiers. "Even
then he must have started from a much nearer base. We'll have to
investigate."

"Why did he?" persisted Beverley. "That's what I want to know."


He received his answer in no uncertain way.

A tremendous roar rent the sky, followed by a rush of air and the
noise of cascades of water falling into the sea. Over the spot where
lay the wreck of the Fusi Yama the usually placid surface of the
lagoon was lashed into a wide cauldron of leaping, hissing foam.

"Fritz again—the dirty dog!" exclaimed Harborough, when the


reverberations of the detonation had subsided. "It might have been
worse if we had been working on the boat."

Where the two boats, joined by a platform, had been, was a patch
of discoloured water, on which shattered fragments of timber were
bobbing in the strong sunlight. Had the working-party not ceased
work to convey the rival divers to the yacht, no one would have
escaped the force of the explosion.

"This is not the work of one man," declared Villiers. "Let's get
ashore."

The suggestion was promptly acted upon, and on gaining the


beach Harborough and his companions were greeted by the
spectacle of Dick Beverley and Pete, armed with rifles, driving before
them a couple of the Zug's crew, who marched with arms upheld in
the good old-fashioned way they were taught in the Great War.

"Pete and I had been after pigs," explained Dick. "We were on our
way back when we saw two strange men lying face downwards on
the cliff, apparently watching the Titania. Of course, we couldn't do
anything then, except watch them, because the land isn't our private
property, but when that explosion went off and they began laughing
and shaking hands we thought it time to have a say in the matter.
We did," he added grimly, "and they came quietly."

The prisoners, finding that they were not beaten, kicked, or


otherwise misused by their captors after the custom of certain
German officers in charge of prison-camps during the war, became
fairly communicative.

Four men, under the command of Siegfried Strauss, had left Ni


Telang in one of the Zug's boats, and landed on Nua Leha close to
the spot where Dick had met with a mishap during his first pig-
hunting expedition.

Leaving one man in charge of the boat, Strauss and the other
three, carrying explosives, an electric automatic time-fuse, and two
divers' suits, crossed the island, keeping under the shelter of the
palm groves until they reached the cove where the two sea-planes
had been berthed.

While two of the men kept watch, Siegfried and a companion


donned their diving-dresses and walked into the sea.

What happened could only be left to conjecture, unless Strauss at a


later date thought fit to explain his movements. Apparently they
found the wreck and placed their explosive charges in position. Upon
the return journey they became separated. His course deflected by
the current, Strauss found himself confronted by Swaine, the
former's astonishment being almost as great as the latter's. Of the
fate of the other Hun diver nothing was ever known. He might have
been eaten by a shark, or he might have lost direction and been
killed by the shock of the explosion, or else, which was more likely,
he was asphyxiated owing to the failure of his air-supply.

That afternoon Merridew, O'Loghlin, Griffiths, and Bell, all armed,


proceeded to the place where the Zug's boat lay. They made an easy
capture of the last member of the submarine raiding-party, and,
what was a welcome prize, the boat as well—a stoutly-built 25-feet
cutter.

They returned to the camp in the boat, following the shore inside
the reef, and the three prisoners were placed under lock and key in
one of the Titania's cabins, the crew taking turns to keep watch
outside the door to prevent any attempt to escape.

Next morning Villiers volunteered to descend to the wreck and


ascertain the state of the hull after the explosion. Since the guide-
rope had been severed, the captured boat was pressed into service
and moored as close as possible, going by cross-bearings, to the
spot where the lighting-plant had been stationed. Since the latter
had been destroyed, Villiers had to rely upon his portable electric
lamp.

The depth to which he descended before his feet touched the


bottom surprised him. It was greater than he had previously worked
in, and no natural light penetrated the dark waters. At first he
fancied he was in a submarine forest. Gaunt ribs, distorted in the
rays of the lamp, reared themselves on either hand. Closer
examination showed that they were not metal but timber, badly
eaten by worms, and thickly encrusted with barnacles.

His foot catching in some obstacle caused him to throw the light of
the lamp upon the ground.

He was standing on a bed of coral on which lay dark shapes in


hundreds, like a cart load of bricks dumped on the ground.

"By Jove!" he exclaimed to himself. "I've come to the wrong shop.


This must be the wooden hulk Swaine spoke about. She must have
had lead pigs for ballast. Even that lot's worth a fortune at the
present-day price for lead."

Hardly knowing why he did so, Villiers lashed one of the pigs of
ballast to his shot-rope, then, paying out his distance-line as he
went, he made for his real objective—the wreck of the Fusi Yama.

When that vessel's bilge loomed through the water, Villiers found
that he was close to the starboard bow. Much of the steelwork had
been stripped of its thick covering of weed and barnacles by the
force of the explosion, but of actual damage done to the hull there
was none.

By a rare slice of good luck, as far as Harborough and his


companions were concerned, Strauss had miscalculated the distance
and direction of the wreck of the Fusi Yama from shore, and had
deposited the explosive charges against the side of the old wooden
wreck in the belief that it was the other. The remainder of the gold
was still intact. Von Giespert had shot his last bolt, and the missile
had gone wide of the mark.

CHAPTER XXIX
A Frustrated Escape

Having made this satisfying discovery, Villiers returned to the


surface and reported the good news.

There was, however, much work to be done before the rest of the
gold could be removed. The wreck of the Fusi Yama had to be
buoyed once more, for, amongst other damage, the former mark-
buoys had been destroyed by the explosion. Another guide-rope had
to be established between the wreck and the shore, while, owing to
the loss of the electric submarine lamp and the generating plant, the
remainder of the work under water had to be carried out by the
relatively feeble light afforded by the divers' electric lamps.

By the time these various preliminary tasks were completed Swaine


had recovered from the effects of his perilous adventure. Siegfried
Strauss, too, was out of danger and gave but little trouble. His arm
was healing slowly, and he seemed grateful to his rivals for their kind
and generous treatment.
Swaine bore him no ill will on account of the submarine fight. He
willingly accepted Strauss' explanation that he thought Swaine was
about to attack him and that he was obliged to take action. Strauss
was the loser, and had paid the price for it. The matter was over and
done with: that was Swaine's summing up of the case.

On the other hand, every member of the Titania's crew felt that
they had an account to settle with Kaspar von Giespert. The fellow
hadn't played the game from the very beginning, and his treachery
in dispatching a boat's crew to blow up the wreck, and, as he hoped,
most of the members of Harborough's party as well, put him beyond
the bounds of decency.

Strauss freely admitted that his employer had acted treacherously,


and that von Giespert was filled with a mad rage for revenge at
being baulked of his chance of getting the treasure. He also
volunteered the information that von Giespert intended to take the
Zug back to European waters directly the boat's crew returned. And,
since they weren't in a position to return, it was safe to assume that
von Giespert would not risk searching for them, but, after giving up
all hope of their safety, would carry out his original programme of
leaving Ni Telang and making for home.

The two Germans captured by Dick Beverley did not take kindly to
their detention. Not from any sense of devotion to von Giespert did
they attempt to escape, but because they were under the erroneous
impression that their employer was on the right track after all and
was about to gain possession of the gold. They had heard von
Giespert say that he meant to sink the Titania and gain possession
of the booty by force of arms, and, since they did not like the
prospect of being under lock and key on the yacht when she was
attacked, they took steps to regain their freedom.

It was a bright moonlight night when they put their crudely-formed


plan into execution. Although Griffiths was on guard outside the door
of their cabin-cell, he heard no suspicious noises. Working
desperately and silently, the Huns removed a portion of the inch
match-boarding that separated their cabin from the one adjoining,
which happened to be three cabins knocked into one and utilized as
a store for hydroplanes. Since the two Cormorants were no longer in
existence, the fairly-expansive compartment was empty save for a
few tools, coils of rope, and kegs of paint and varnish.

One of the doors leading to the alley-way was unlocked—unlocked


doors being the rule rather than the exception on board.

They waited until they heard the sentry go for'ard, for Griffiths was
pacing up and down the whole length of the alley-way, then they
silently crept to the accommodation-ladder and gained the deck.

Merridew and Fontayne, the watch on deck, were at that moment


pacing the port side, conversing in low tones in order not to disturb
their sleeping mess-mates. Knowing that Griffiths was on duty
below, they never troubled about the prisoners—it was not their
"pigeon". Their particular duty was to see that the Zug didn't pay a
nocturnal visit with sinister intent to the lagoon at Nua Leha.

In the midst of Fontayne's elaborate description of his "castle in the


air", Merridew laid one hand firmly upon his companion's shoulder.

"Go on talking—anything," he whispered. "These two Fritzes are


trying to do a bunk. Let 'em have a run for their money; we'll see
some fun."

Merridew and his companion waited until they saw the dark
shadows of the Germans flat along the deck; then, each taking up a
rifle, the watchers followed, keeping under cover afforded by the
chart-house.

Right aft crept the two Germans until they halted and peered over
the taffrail as if measuring the distance between them and the
shore. Then, with a few coils of main-sheet, they took a turn round a
belaying-pin and silently lowered the free end of the stout manilla
rope into the water.

Slowly one of the Huns wriggled on his stomach upon the slightly-
rounded top of the taffrail, then, grasping the rope, he began to
make his way down hand over hand, his companion watching his
progress.

Merridew distinctly heard a splash in the water. It was not the noise
of a man swimming.

"Sharks!" he whispered, and opened the cut-off to the magazine of


his rifle.

The German dangling at the rope's end heard it too, for he uttered
a guttural "Achtung!"

The other fell, just below the rail, tried to regain the deck, but the
task of swinging himself round and over the projecting taffrail was
beyond his powers. As he hung desperately to the rope he
prevented his companion's efforts to climb back. Both started to
shout for help.

Bawling for the rest of the duty watch to turn out, Merridew and
Fontayne ran aft. A strange sight met their eyes as they leapt over
the taffrail.

The Germans, gripping the rope with the tenacity of terror, were
swaying to and fro in their efforts to put as great a distance as
possible between them and the swirling water, while clearly visible in
the bright moonlight—as they darted in and out of the dark shadows
cast by the Titania's projecting counter—were two enormous sharks,
their white bellies glistening in the silvery light as they turned to
snap at the tempting bait just above their reach.

Levelling his rifle, Merridew waited his opportunity. It was not long
in coming. One of the sharks was on the point of turning over on its
back to attempt a ferocious snap with its tremendous jaws when the
rifle cracked. At close range the nickel bullet inflicted a large and
mortal wound, and the monster, still writhing, sank out of sight.

Fontayne hit the other, but whether the shot was fatal or not
remained an unsettled question to all concerned except the shark.
But the main point was that it swam off as hard as it could go.

Meanwhile the rest of the duty-watch had come on deck. Curiosity


prompted them to have a glimpse of the two thoroughly-scared
Huns, then they proceeded to lower and man the gig—the only
available boat.

"There's no hurry," remarked Beverley. "Let 'em feel the breeze a


bit longer. It will teach them a lesson."

The sharks having been eliminated from the proposition, all danger
to life was at an end. But before the boat came under the Titania's
counter the uppermost Hun released his hold. In his fall he tore his
companion's grasp from the rope, and the twain hit the water with
tremendous force.

Winded and spluttering they rose to the surface, frantically


grabbing at each other until they were unceremoniously hauled into
the stern-sheets of the gig.

Next morning Harborough had the two Germans brought before


him. The men were thoroughly cowed, for that narrow escape from
being seized and devoured by sharks had knocked all the stuffing
out of them.

Their punishment was solitary confinement, and they were also


ordered to make good the damage done to the woodwork of the
cabin.

"Strange," remarked the baronet, when the culprits had been


removed. "Up to the present we haven't seen a shark in the lagoon
but that it has done us a good turn. Now, then, fall in all hands.
Another couple of days' work will see the job finished, and then, yo
ho, for Old England!"

CHAPTER XXX
Von Giespert's Resolve

Kapitan Karl von Giespert, ex-Unter-Leutnant of the now defunct


Imperial German Navy, was in a very bad temper, which was saying
a good deal, since he was rarely in a good one.

He was beginning to realize that his latest bit of dirty work—one of


many pet schemes—had been a wash-out. The boat containing
Strauss and three of the crew had not returned. He didn't mind
losing the men overmuch, but he regretted his decision to send
Siegfried Strauss in command of the submarine mining expedition;
not that he had any affection for Strauss, but because Strauss was a
capable navigator and he was not. And it was a long, long voyage
back to the Fatherland.

After taking several turns up and down the deck, von Giespert went
for'ard, descended the steep ladder to the fo'c'sle, and thence to the
store-room, where for quite a considerable time he stood pensively
contemplating the for'ard water-tight bulkhead of No. 1 hold.

Then he bawled to one of the men to pass the word for the
carpenter. That individual arrived at the double, rather breathless
and perspiring freely not solely on account of the heat, but in
anticipation of a scene with his employer.
"I want you," ordered von Giespert, "to shore up this bulkhead
from the other side. Use every available baulk of timber. If you want
more, send a party ashore to fell some trees. I want the job done
quickly and properly."

Had von Giespert told the carpenter to construct a ladder long


enough to reach the moon, or given him similar impossible
instructions, the latter's surprise would hardly have been greater.
The bulkhead of No. 1 hold was of massive construction, and its
condition was as good as the day when the ship was launched.

"It will take a day and a half, Herr Kapitan," replied the carpenter,
in reply to his employer's question as to the length of the task
involved.

"Then have it done," snapped von Giespert, and hied him to


interview the chief engineer in his cabin.

"I want steam raised the day after to-morrow," he said. "We're
sailing at noon. What's the working-pressure of the boilers?"

The engineer told him.

"No more?" asked von Giespert.

"I might raise another two atmospheres, Herr Kapitan," replied the
chief dubiously. "The boilers wouldn't stand that for long."

"They'll have to stand it for an hour," declared von Giespert. "An


hour will be enough for my purpose. I will give you ample warning
when I require the additional pressure."

His latest project was to sail for Nua Leha, arriving at dawn. If, as
he expected, the Zug were sighted by the look-out of the Titania, he
would hoist urgent signals—the international NV, signifying "short of
provisions". He would then make out that the Zug intended to
anchor within a cable's length of her rival, and, suddenly increasing
speed and putting her helm hard-a-port, ram the Titania full on her
beam. And, since he still required the Zug to get him home, the
reason for the shoring up of the for'ard watertight bulkhead was
apparent. But at all costs there must be no survivors from the
Titania.

It was a desperate scheme that gave fair promises of success. The


one fly in the ointment was the knowledge that the Titania mounted
a 4.7-inch quickfirer. Von Giespert did not, of course, know that the
"quick-firer" was at that moment performing its ordained task of
carrying off the smoke of the galley-fire in its humble, yet important,
capacity of a chimney.

As a counter-measure, if the Titania's gun should be manned and


trained, von Giespert could hoist a "not under control" signal and
trust that the excuse would pass, but he was beginning to have a
wholesome respect for Harborough. Not once but many times that
fool of an Englishman had got to windward of him. It behoved him
to act warily.

Von Giespert was a firm believer in the German equivalent for the
proverb "Desperate diseases need desperate remedies". To him the
Titania and her crew represented the disease; the Zug was to apply
the remedy. At the same time he realized that it was the last straw,
the final desperate plunge of the despairing gamester, staking his all
upon the cast of the die.

For the greater part of the day the carpenter and his crew toiled in
the burning rays of the sun, hauling and setting in position huge
baulks of timber, supplemented by lengths of stout bamboo, felled
and towed alongside and thence whipped up and placed in the
for'ard hold by means of the vessel's derricks. Before sunset the
carpenter reported complete, but von Giespert was not satisfied.

He ordered the men to fill sacks with sand and pile them up
against the timber shores. He meant to make certain of that
bulkhead. The Zug's bows might be torn like paper in the projected
ramming evolution, but the bulkhead must hold at all costs.

The crew obeyed reluctantly. They were of a type that could be


driven and did not take kindly to being led; but in the matter of
being driven there could be "too much of a good thing ". And von
Giespert failed to realize the presence of the danger-signal.

Headed by one of the quartermasters, the deck hands came aft in


a body and demanded of the now astounded but still mule-headed
von Giespert the reason for this excessive amount of work. They
could not see why the bulkhead should be strengthened, considering
it was strong enough already, unless some desperate scheme were
afloat.

Von Giespert told them. He had to admit failure in the quest of the
gold and that his British rivals had both hoodwinked him and
secured the real prize.

"That is all very well, Herr Kapitan," observed the spokesman of


the deputation. "We don't mind taking desperate measures if there's
anything to be got out of it. If we sink the English yacht, how do we
stand as far as the gold is concerned? And suppose we fail, how do
we stand then? It will mean penal servitude in an English prison."

"Not at all," protested von Giespert. "If we fail, the responsibility is


mine. You are acting under my orders. If we succeed in sinking the
yacht, as I believe we shall, then it's merely a question of diving and
recovering the gold. We would know its position to a certainty this
time."

He stopped to make a rapid calculation.

"How do we stand in, Herr Kapitan?" asked one of the men.

Von Giespert, who was on the point of offering twenty per cent of
the proceeds, came down to ten. Inwardly he vowed that these
swinish fellows of his would pay for their temerity in trying to beard
him in his den.

"Very well, Herr Kapitan," agreed the spokesman. "One tenth of the
proceeds in addition to our wages, and you'll please to sign a paper
absolving us from all blame in the matter of the collision."

Muttering angry oaths, von Giespert drew up and signed a


document to that effect and handed it to the leader of the
deputation. The men withdrew, and for the present at least the
trouble had blown itself out.

At eleven on the following morning smoke began to issue from the


Zug's funnel. Half an hour later steam was raised, and by noon the
safety-valves were lifting under the internal pressure. The chief
engineer reported that all was ready; but no answering clang of the
bridge-telegraph was transmitted to the engine-room.

Von Giespert, on the bridge, was hesitating.

"What is the glass doing?" he inquired.

"It has risen a point since six this morning, Herr Kapitan," reported
the quartermaster.

Von Giespert shrugged his shoulders. He had not even the excuse
of approaching bad weather to delay him.

With feelings akin to those of a man about to plunge into icy-cold


water he leant over the bridge stanchion-rail. The bos'un in the
fo'c'sle had already shortened cable and was awaiting the command
to weigh.

The kapitan nodded. At the signal the steam capstan began to


clink.
"Up and down, sir," announced one of the men, and a few
moments later the rusty stockless anchor came into view.

"Easy ahead."

The Zug began to forge through the placid water, increasing speed
as she passed through the gap in the reef.

Von Giespert turned to the quartermaster.

"Ost zu sud," he ordered.

That course, east by south, was the course for Nua Leha.

CHAPTER XXXI
Exit the "Zug"

"What's that made fast to the shot-line, old man?" inquired


Beverley, as Villiers, divested of his helmet and diving-dress, sat in
the stern-sheets of the boat that von Giespert had unwittingly given
over to the Titania's people.

"That?" replied Villiers. "I dunno. Ballast, I expect. There are tons
of it down there. Wonder if it's lead?"

"If so, it's a fortune for anyone who can get it back to England,"
observed Harborough, unclasping his knife and digging the point into
the block of metal.

"Tough for lead," he commented, "and yet too soft for iron, unless
the stuff's badly corroded. By Jove! Villiers! I believe—yes, I'm sure
—it's silver."

"Regular Tom Tiddler's ground then," remarked Jack. "When we left


England silver was soaring. Wonder what it's worth now?"

"At any rate, we won't fly in the face of Providence," declared


Harborough. "A few days more won't matter very much. When we've
finished with the Fusi Yama, we'll lift some of this stuff."

"There's enough to sink the Titania," declared Villiers. "The hold of


that ship must have been chock-full of silver. Rum sort of ballast."

"Probably a Spanish treasure-ship or a buccaneering craft that sunk


with her booty," suggested Claverhouse. "They did that sort of thing
once, I believe."

"Then that's settled," declared Harborough briskly. "Finish with the


Fusi Yama, and then carry on with the silver that friend von Giespert,
by the hand of pal Strauss, kindly discovered for us. How's the glass,
by the by? I forgot to look this morning."

"It rose a point and a half after eight," reported Villiers, "and now it
is dropping rather too rapidly."

"H'm!" exclaimed Harborough. "That's bad. It may interfere with


our work, and we can't afford to lose much more plant. We'll work
double shifts, and keep our weather-eye lifting."

By sunset the task of clearing the Fusi Yama's strong-room was


accomplished, and an hour later the last of the gold was safely on
board the Titania—an event that was signalized by three hearty
cheers and splicing the "mainbrace" with discreet tots of
champagne.

The while the glass was falling rapidly, although not so low as on
the occasion of the devastating hurricane. Nevertheless, every
possible precaution was taken. The boats were hoisted in and lashed
down, awnings and side-curtains stowed, and additional cable
veered out. The engine-room stood by ready to start the heavy oil-
engines, and thus ease the strain on the anchor-chains should
occasion arise. All hands were on board, preferring to face the storm
in a staunch craft anchored in a fairly-sheltered lagoon to risking a
wet and uncomfortable, if not dangerous, night ashore.

At midnight it was blowing a gale, but, in contrast to the preceding


storm, there was no preliminary rain—simply a terrific blast of wind
that heralded an almost uninterrupted blow.

It started from the nor'-nor'-east, or obliquely to the coast-line off


which the Titania lay at anchor. Although the noise of the breakers
on the reef was like that of a continual roar of thunder, the lagoon
itself was only slightly agitated.

But when, at about 3 a.m., the wind veered four points to the
east'ard, the beach became a dead lee shore. Huge billows, crashing
madly upon the coral reef, swept in masses of white foam across the
lagoon and churned themselves upon the beach, until in the pale
moonlight the palm groves appeared to be growing from an
undulating field of white water.

Pounding and thudding, quivering under the terrific pressure of the


wind, the Titania held grimly to her cables. At one moment full fifty
feet of chain, stretched taut and obliquely like an iron bar, would be
visible; the next the yacht would lurch forward as a giant roller
passed her by, and would threaten to overrun her anchors, until she
"snubbed" with a sickening jerk that almost tore the stout mooring
bits from the deck.

"It won't last long," declared Villiers, as a hissing shower of rain


mingled with the driving spindrift. "Wind before rain, you know. It'll
ease down by dawn."

He was right. By sunrise, although the wind was still high, its force
had moderated considerably, and the sun rose in a grey sky,
betokening fine weather before many hours had passed.

"Vessel making for the island, sir," suddenly announced Merridew,


pointing dead to windward.

"By Jove! It's the Zug!" exclaimed Harborough.

"No doubt about it, sir," agreed Villiers, after a lengthy survey
through his binoculars. "Wonder what she's doing here?"

The Zug was steering due south, and, therefore, on a slightly


diverging course from the eastern side of the island; but when
immediately abeam of the entrance to the lagoon, she ported helm
as if to approach the narrow gap in the coral reef.

"Either von Giespert's mad or he doesn't know the risk he's


running," said Harborough. "Make him a signal, Villiers. Say 'bar
unsafe'."

"He's flying some sort of signal, sir," reported Jack. "Can't make out
the flags; they're dead to windward."

"If we can't see his, he can't see ours," observed Harborough. "But
we'll risk it, and give him a chance."

"I've got it, sir," declared Beverley. "It signifies short of provisions
'."

Harborough shrugged his shoulders.

"What's wrong with the pigs and the bread-fruit trees at Ni


Telang?" he remarked pointedly. "If I were von Giespert, I would
tighten my belt a notch before I'd tackle the entrance to the lagoon.
There's one thing, the wind's moderating, but look at the broken
water on the bar."
"It doesn't look so bad from seaward," said Merridew. "He'll feel
sorry for himself when he's in the thick of it, I fancy."

With a following wind, the Zug was rolling heavily and frequently
obscured from view by the thick cloud of smoke from her funnel.
When quite a mile from the reef, she suddenly fell off her course,
vast quantities of steam issuing from her engine-room. She lost way,
and was now rolling excessively in the trough of the seas.

"Looks like a boiler-explosion," exclaimed Harborough, glancing


over the side at the still tumultuous water within the reef. "We'll
have to get the boats ready for lowering, Mr. Villiers. They'll be
wanted pretty badly, I expect."

The Zug was doomed. Von Giespert had again overreached himself,
although the crew of the Titania had no suspicion of his desperate
move. Von Giespert's orders to his chief engineer had been carried
out only too well. The main steam-pipe, unable to withstand the
abnormal internal pressure, had burst, the explosion killing everyone
in the boiler-room, while the escaping steam had severely injured
the chief engineer and his assistants.

Helpless in the trough of the seas, the Zug was now drifting rapidly
on to the reef. Von Giespert, after bellowing incoherencies, ordered a
storm trysail to be set in the hope that the vessel's head would pay
off. But the moment the canvas was hoisted it blew to atoms.

As a last resource both anchors were let go. Owing to the depth of
water outside the reef, it was a long time before they obtained a
grip. When they did, the Zug was within two hundred yards of the
coral barrier.

Momentarily she swung to her cables, then with a vicious snub


both chains parted simultaneously. Seven minutes later, with a crash
that was audible above the roar of the breakers, the Zug ended her
career upon the outer reef of Nua Leha.
CHAPTER XXXII
Settling Accounts

Harborough had not waited for the doomed vessel to strike.


Already the Titania's two boats—the only serviceable ones—had
been lowered, and were pulling towards the leeside of the reef.

Villiers was in charge of the cutter that had formerly belonged to


the Zug. Beverley was in command of the gig. Both crews were
wearing life-belts.

It was as well they did, for barely had the gig gone fifty yards from
the Titania when she shipped a heavy sea and filled completely.
Luckily all hands managed to gain the yacht by means of ropes
thrown them from the Titania's bows.

Satisfying himself that his comrades late of the gig were safe,
Villiers held on, encouraging the crew by word and gesture, and
skilfully handling the boat to meet every dangerously-crested wave.

It was grim, desperate work. Sometimes the boat would lose


ground in spite of the efforts of the rowers, who, with cracking
sinews and aching backs, stuck gamely to their task. More than once
the stroke had to boat his oar and bale out the water, for, in spite of
her weatherly qualities, the cutter was shipping dangerous quantities
of spray.

As they approached the lee side of the reef, which afforded very
little shelter as the breakers were thundering right over it, Villiers
could hardly see the wreck owing to the volume of spindrift.
The Zug was breaking up fast. Already her after-part, unable to
withstand the terrific hammering, had broken off and had
disappeared in deep water. On her bows, that were momentarily in
danger of being smashed to pieces, were five or six of her crew,
swept by the waves, and hanging on tenaciously to the heavier
fittings. The rest of her crew had disappeared, having been swept
overboard on the impact.

For the present Villiers could do nothing but keep the boat's head
on to the seas and wait. A hundred feet of coral reef, showing in the
trough of every breaker that swept over it, lay between him and the
wreck. To attempt to get alongside the Zug would be hopeless. Had
there been a ghost of a chance, he would have taken it in his efforts
to save life, but there was none. All he could do was to stand by and
wait, trusting that some of the luckless Germans might be swept
over the reef into the smoother water inside the lagoon. At length
one of the Zug's crew took a desperate step and plunged into the
sea. Caught by a crested breaker, he was hurled for a full fifty yards
before he disappeared from view.

"Watch for him!" shouted Villiers. "He's over the reef."

A few seconds later the man reappeared, feebly striking out. He


was in danger of being swept past the cutter before he was seen. To
attempt to turn meant the boat being caught broadside on and
swamped.

"Back all," ordered Villiers, gripping the tiller to prevent the rudder
broaching to as the boat gathered sternway.

The cutter backed almost half-way across the lagoon before Villiers
gave the order to "give way". Then, gradually edging towards the
swimmer, the boat, ably handled, came within an oar's length of the
exhausted man.

A few seconds of breathless suspense, then:

You might also like