100% found this document useful (21 votes)
72 views

Immediate download Matlab a practical introduction to programming and problem solving 3e edition Edition Attaway ebooks 2024

introduction

Uploaded by

yumanreyezad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (21 votes)
72 views

Immediate download Matlab a practical introduction to programming and problem solving 3e edition Edition Attaway ebooks 2024

introduction

Uploaded by

yumanreyezad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

Download the full version of the ebook at ebookname.

com

Matlab a practical introduction to programming and


problem solving 3e edition Edition Attaway

https://ebookname.com/product/matlab-a-practical-
introduction-to-programming-and-problem-solving-3e-edition-
edition-attaway/

OR CLICK BUTTON

DOWNLOAD EBOOK

Download more ebook instantly today at https://ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

Java An Introduction to Problem Solving and Programming


6th Edition Walter Savitch

https://ebookname.com/product/java-an-introduction-to-problem-solving-
and-programming-6th-edition-walter-savitch/

ebookname.com

Programming problem solving abstraction with C Moffat

https://ebookname.com/product/programming-problem-solving-abstraction-
with-c-moffat/

ebookname.com

Problem Solving and Programming Concepts 9th Edition


Maureen Sprankle

https://ebookname.com/product/problem-solving-and-programming-
concepts-9th-edition-maureen-sprankle/

ebookname.com

Marx s Inferno the political theory of Capital Third


Printing. And First Paperback Printing Edition Roberts

https://ebookname.com/product/marx-s-inferno-the-political-theory-of-
capital-third-printing-and-first-paperback-printing-edition-roberts/

ebookname.com
Breakthrough Business Results With MVT A Fast Cost Free
Secret Weapon for Boosting Sales Cutting Expenses and
Improving Any Business Process 1st Edition Charles W.
Holland
https://ebookname.com/product/breakthrough-business-results-with-mvt-
a-fast-cost-free-secret-weapon-for-boosting-sales-cutting-expenses-
and-improving-any-business-process-1st-edition-charles-w-holland/
ebookname.com

Misconceptions Unmarried Motherhood and the Ontario


Children of Unmarried Parents Act 1921 1969 1st Edition
Lori Chambers
https://ebookname.com/product/misconceptions-unmarried-motherhood-and-
the-ontario-children-of-unmarried-parents-act-1921-1969-1st-edition-
lori-chambers/
ebookname.com

Russia s Foreign Trade and Economic Expansion in the


Seventeenth Century Windows on the World Northern World 13
1st Edition J. T. Kotilaine
https://ebookname.com/product/russia-s-foreign-trade-and-economic-
expansion-in-the-seventeenth-century-windows-on-the-world-northern-
world-13-1st-edition-j-t-kotilaine/
ebookname.com

Purity Body and Self in Early Rabbinic Literature 1st


Edition Mira Balberg

https://ebookname.com/product/purity-body-and-self-in-early-rabbinic-
literature-1st-edition-mira-balberg/

ebookname.com

Ancestors of Worthy Life Plantation Slavery and Black


Heritage at Mount Clare 1st Edition Teresa S. Moyer

https://ebookname.com/product/ancestors-of-worthy-life-plantation-
slavery-and-black-heritage-at-mount-clare-1st-edition-teresa-s-moyer/

ebookname.com
Additive Combinatorics 1st Edition Terence Tao

https://ebookname.com/product/additive-combinatorics-1st-edition-
terence-tao/

ebookname.com
MATLABÒ
A Practical Introduction to Programming
and Problem Solving
This page intentionally left blank
MATLAB Ò
A Practical Introduction to Programming
and Problem Solving

Third Edition

Stormy Attaway
Department of Mechanical Engineering,
Boston University

Amsterdam  Boston  Heidelberg  London  New York  Oxford


Paris  San Diego  San Francisco  Singapore  Sydney  Tokyo
Butterworth-Heinemann is an imprint of Elsevier
Butterworth-Heinemann is an imprint of Elsevier
The Boulevard, Langford Lane, Kidlington, Oxford, OX5 1GB
225 Wyman Street, Waltham, MA 02451, USA
First published 2009
Second edition 2012
Third edition 2013
Copyright Ó 2013 Elsevier Inc. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or by any means, electronic or
mechanical, including photocopying, recording, or any information storage and retrieval system, without
permission in writing from the publisher. Details on how to seek permission, further information about the
Publisher’s permissions policies and our arrangement with organizations such as the Copyright Clearance Center
and the Copyright Licensing Agency, can be found at our website: www.elsevier.com/permissions
This book and the individual contributions contained in it are protected under copyright by the Publisher (other
than as may be noted herein).
Notices
Knowledge and best practice in this field are constantly changing. As new research and experience broaden our
understanding, changes in research methods, professional practices, or medical treatment may become necessary.
Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any
information, methods, compounds, or experiments described herein. In using such information or methods
they should be mindful of their own safety and the safety of others, including parties for whom they have
a professional responsibility.
To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability
for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or
from any use or operation of any methods, products, instructions, or ideas contained in the material herein.
MATLABÒ is a trademark of TheMathWorks, Inc., and is used with permission. TheMathWorks does not warrant
the accuracy of the text or exercises in this book. This book’s use or discussion of MATLABÒ software or related
products does not constitute endorsement or sponsorship by TheMathWorks of a particular pedagogical approach
or particular use of the MATLABÒ software.
MATLABÒ and Handle GraphicsÒ are registered trademarks of TheMathWorks, Inc.
British Library Cataloguing in Publication Data
A catalogue record for this book is available from the British Library
Library of Congress Cataloguing in Publication Data
A catalog record for this book is available from the Library of Congress
ISBN: 978-0-12-405876-7

For information on all Butterworth-Heinemann publications


visit our website at store.elsevier.com

Printed and bound in the United States


13 14 15 16 10 9 8 7 6 5 4 3 2 1
Dedication

This book is dedicated to my husband, Ted de Winter.


This page intentionally left blank
Contents

PREFACE ...................................................................................................... xi
ACKNOWLEDGMENTS............................................................................. xxi

PART 1 Introduction to Programming Using MATLAB


CHAPTER 1 Introduction to MATLAB.................................................... 3
1.1. Getting into MATLAB .......................................................... 4
1.2. The MATLAB Desktop Environment.................................. 5
1.3. Variables and Assignment Statements.............................. 6
1.4. Numerical Expressions ...................................................... 12
1.5. Characters and Encoding .................................................. 21
1.6. Relational Expressions....................................................... 23
Common Pitfalls ........................................................................... 27
Programming Style Guidelines ................................................... 28

CHAPTER 2 Vectors and Matrices........................................................ 33


2.1. Vectors and Matrices.......................................................... 33
2.2. Vectors and Matrices as Function Arguments................ 50
2.3. Scalar and Array Operations on Vectors
and Matrices........................................................................ 54
2.4. Matrix Multiplication.......................................................... 57
2.5. Logical Vectors.................................................................... 59
2.6. Applications: The diff and meshgrid Functions ............. 64
Common Pitfalls ........................................................................... 66
Programming Style Guidelines ................................................... 67

CHAPTER 3 Introduction to MATLAB Programming ......................... 73


3.1. Algorithms ........................................................................... 74
3.2. MATLAB Scripts ................................................................. 75
3.3. Input and Output ................................................................ 78
3.4. Scripts with Input and Output .......................................... 86 vii
viii Contents

3.5. Scripts to Produce and Customize Simple Plots ............. 87


3.6. Introduction to File Input/Output (Load and Save) ........ 93
3.7. User-Defined Functions That Return a Single Value...... 97
3.8. Commands and Functions ............................................... 106
Common Pitfalls ......................................................................... 107
Programming Style Guidelines ................................................. 107

CHAPTER 4 Selection Statements ...................................................... 117


4.1. The if Statement ............................................................... 117
4.2. The if-else Statement ....................................................... 121
4.3. Nested if-else Statements................................................ 123
4.4. The switch statement ...................................................... 129
4.5. The menu Function .......................................................... 131
4.6. The “is” Functions in MATLAB...................................... 133
Common Pitfalls ......................................................................... 136
Programming Style Guidelines ................................................. 137

CHAPTER 5 Loop Statements and Vectorizing Code ....................... 147


5.1. The for Loop ...................................................................... 148
5.2. Nested for Loops............................................................... 155
5.3. while Loops ....................................................................... 162
5.4. Loops with Vectors and Matrices: Vectorizing............. 172
5.5. Timing ................................................................................ 181
Common Pitfalls ......................................................................... 183
Programming Style Guidelines ................................................. 184

CHAPTER 6 MATLAB Programs......................................................... 195


6.1. More Types of User-Defined Functions ......................... 195
6.2. MATLAB Program Organization ..................................... 204
6.3. Application: Menu-Driven Modular Program ................ 209
6.4. Variable Scope................................................................... 215
6.5. Debugging Techniques .................................................... 220
Common Pitfalls ......................................................................... 226
Programming Style Guidelines ................................................. 226

CHAPTER 7 String Manipulation ........................................................ 235


7.1. Creating String Variables................................................. 235
7.2. Operations on Strings....................................................... 238
7.3. The “is” Functions for Strings ........................................ 252
7.4. Converting Between String and Number Types........... 252
Common Pitfalls ......................................................................... 256
Programming Style Guidelines ................................................. 256
Contents ix

CHAPTER 8 Data Structures: Cell Arrays and Structures ............... 265


8.1. Cell Arrays......................................................................... 266
8.2. Structures .......................................................................... 271
Common Pitfalls ......................................................................... 288
Programming Style Guidelines ................................................. 289

CHAPTER 9 Advanced File Input and Output .................................. 295


9.1. Lower-Level File I/O Functions....................................... 296
9.2. Writing and Reading Spreadsheet Files ........................ 310
9.3. Using MAT-files for Variables.......................................... 311
Common Pitfalls ......................................................................... 313
Programming Style Guidelines ................................................. 314

CHAPTER 10 Advanced Functions....................................................... 321


10.1. Anonymous Functions ................................................... 321
10.2. Uses of Function Handles .............................................. 323
10.3. Variable Numbers of Arguments .................................. 326
10.4. Nested Functions............................................................ 333
10.5. Recursive Functions ....................................................... 334
Common Pitfalls ......................................................................... 339
Programming Style Guidelines ................................................. 339

PART 2 Advanced Topics for Problem Solving


with MATLAB
CHAPTER 11 Advanced Plotting Techniques ..................................... 347
11.1. Plot Functions ................................................................. 347
11.2. Animation ........................................................................ 354
11.3. 3D Plots ............................................................................ 355
11.4. Customizing Plots........................................................... 359
11.5. Handle Graphics and Plot Properties ........................... 360
11.6. Plot Applications............................................................. 372
11.7. Saving and Printing Plots .............................................. 377
Common Pitfalls ......................................................................... 378
Programming Style Guidelines ................................................. 378

CHAPTER 12 Basic Statistics, Sets, Sorting, and Indexing ............... 387


12.1. Statistical Functions ....................................................... 388
12.2. Set Operations................................................................. 394
12.3. Sorting.............................................................................. 397
12.4. Index Vectors .................................................................. 404
x Contents

12.5. Searching ......................................................................... 408


Common Pitfalls ......................................................................... 412
Programming Style Guidelines ................................................. 412

CHAPTER 13 Sights and Sounds .......................................................... 419


13.1. Sound Files ...................................................................... 419
13.2. Image Processing............................................................ 421
13.3. Introduction to Graphical User Interfaces ................... 431
Common Pitfalls ......................................................................... 450
Programming Style Guidelines ................................................. 450

CHAPTER 14 Advanced Mathematics ................................................. 461


14.1. Fitting Curves to Data.................................................... 462
14.2. Complex Numbers .......................................................... 466
14.3. Matrix Solutions to Systems of Linear Algebraic
Equations......................................................................... 473
14.4. Symbolic Mathematics ................................................... 491
14.5. Calculus: Integration and Differentiation .................... 498
Common Pitfalls ......................................................................... 504
Programming Style Guidelines ................................................. 504

APPENDIX I ............................................................................................... 517


APPENDIX II .............................................................................................. 525
INDEX......................................................................................................... 527
Preface

MOTIVATION
The purpose of this book is to teach basic programming concepts and skills
needed for basic problem solving, all using MATLABÒ as the vehicle. MATLAB is
a powerful software package that has built-in functions to accomplish a diverse
range of tasks, from mathematical operations to three-dimensional imaging.
Additionally, MATLAB has a complete set of programming constructs that
allows users to customize programs to their own specifications.
There are many books that introduce MATLAB. There are two basic flavors of
these books: those that demonstrate the use of the built-in functions in
MATLAB, with a chapter or two on some programming concepts, and those
that cover only the programming constructs without mentioning many of the
built-in functions that make MATLAB efficient to use. Someone who learns
just the built-in functions will be well prepared to use MATLAB, but would
not understand basic programming concepts. That person would not be able
to then learn a language such as C++ or Java without taking another intro-
ductory course, or reading another book, on the programming concepts.
Conversely, anyone who learns only programming concepts first (using any
language) would tend to write highly inefficient code using control statements
to solve problems, not realizing that in many cases these are not necessary in
MATLAB.
Instead, this book takes a hybrid approach, introducing both the programming
and the efficient uses. The challenge for students is that it is nearly impossible to
predict whether they will, in fact, need to know programming concepts later on
or whether a software package such as MATLAB will suffice for their careers.
Therefore, the best approach for beginning students is to give them both: the
programming concepts and the efficient built-in functions. As MATLAB is very
easy to use, it is a perfect platform for this approach to teaching programming
and problem solving.
xi
xii Preface

As programming concepts are critically important to this book, emphasis is not


placed on the time-saving features that evolve with every new MATLAB release.
For example, in most versions of MATLAB, statistics on variables are available
readily in the Workspace Window. This is not shown in any detail in the book,
as whether this feature is available depends on the version of the software and
because of the desire to explain the concepts in the book.

MODIFICATIONS IN THE THIRD EDITION


The changes in the Third Edition of this book include the following.
n New section at the end of every chapter, “Explore Other Interesting
Features”, which lists related language constructs, functions, and tools that
readers may wish to investigate.
n Expanded coverage of:
n image processing, including the use of different data types in image

matrices
n plot functions, including those that use logarithmic scales

n graphical user interfaces.

n Use of MATLAB Version R2012b.


n Modified and new “Practice” problems.
n Modified, new, and some more challenging end-of-chapter exercises.
n Reorganization of some material, principally:
n separate chapter (Chapter 2) on vectors and matrices, which includes

some functions and operators on vectors and matrices, and prepares for
vectorizing code
n matrix multiplication covered much earlier (in Chapter 2)

n vectorized code covered in the loop chapter in order to compare the use

of loops with arrays and vectorized code.


n Use of randi instead of round(rand).
n Use of true/false instead of logical(1)/logical(0).
n Expanded coverage of elementary math functions, including mod, sqrt,
nthroot, log, log2, and log10, as well as more trigonometric functions.
n New Appendix with complete list of functions covered in the book.
n New Appendix with list of Toolboxes that readers may wish to investigate.

KEY FEATURES
Side-by-Side Programming Concepts and Built-in
Functions
The most important, and unique, feature of this book is that it teaches
programming concepts and the use of the built-in functions in MATLAB side-
by-side. It starts with basic programming concepts, such as variables,
Preface xiii

assignments, input/output, selection and loop statements. Then, throughout


the rest of the book many times a problem will be introduced and then solved
using the “programming concept” and also using the “efficient method”. This
will not be done in every case to the point that it becomes tedious, but just
enough to get the ideas across.

Systematic Approach
Another key feature is that the book takes a very systematic, step-by-step
approach, building on concepts throughout the book. It is very tempting in
a MATLAB text to show built-in functions or features early on with a note that
says “we’ll do this later”. This book does not do that; functions are covered
before they are used in examples. Additionally, basic programming concepts
will be explained carefully and systematically. Very basic concepts, such as
looping to calculate a sum, counting in a conditional loop, and error-checking,
are not found in many texts, but are covered here.

File Input/Output
Many applications in engineering and the sciences involve manipulating large
data sets that are stored in external files. Most MATLAB texts at least mention
the save and load functions, and, in some cases, also some of the lower-level
file input/output functions. As file input and output are so fundamental to so
many applications, this book will cover several low-level file input/output
functions, as well as reading from and writing to spreadsheet files. Later
chapters will also deal with audio and image files. These file input/output
concepts are introduced gradually: first load and save in Chapter 3, then lower-
level functions in Chapter 9, and, finally, sound and images in Chapter 13.

User-Defined Functions
User-defined functions are a very important programming concept, and yet
many times the nuances and differences between concepts, such as types of
functions and function calls versus function headers, can be very confusing to
beginner programmers. Therefore, these concepts are introduced gradually.
First, arguably the easiest type of functions to understand, those that calculate
and return one single value, are demonstrated in Chapter 3. Later, functions
that return no values and functions that return multiple values are introduced
in Chapter 6. Finally, advanced function features are shown in Chapter 10.

Advanced Programming Concepts


In addition to the basics, some advanced programming concepts, such as string
manipulation, data structures (e.g., structures and cell arrays), recursion,
anonymous functions, and variable number of arguments to functions, are
xiv Preface

covered. Sorting, searching, and indexing are also addressed. All of these are
again approached systematically; for example, cell arrays are covered before
they are used in file input functions and as labels on pie charts.

Problem-Solving Tools
In addition to the programming concepts, some basic mathematics necessary
for solving many problems will be introduced. These will include statistical
functions, solving sets of linear algebraic equations, and fitting curves to data.
The use of complex numbers and some calculus (integration and differentia-
tion) will also be introduced. The basic math will be explained and the built-in
functions in MATLAB to perform these tasks will be described.

Plots, Imaging, and Graphical User Interfaces


Simple two-dimensional plots are introduced very early in the book (Chapter 3)
so that plot examples can be used throughout. A separate chapter, Chapter 11,
shows more plot types, and demonstrates customizing plots and how the
graphics properties are handled in MATLAB. This chapter makes use of strings
and cell arrays to customize labels. Also, there is an introduction to image
processing and the basics necessary to understand programming graphical user
interfaces (GUIs) in Chapter 13.

Vectorized Code
Efficient uses of the capabilities of the built-in operators and functions in
MATLAB are demonstrated throughout the book. In order to emphasize the
importance of using MATLAB efficiently, the concepts and built-in functions
necessary for writing vectorized code are treated very early in Chapter 2.
Techniques such as preallocating vectors and using logical vectors are then
covered in Chapter 5 as alternatives to selection statements and looping
through vectors and matrices. Methods of determining how efficient the code is
are also covered.

LAYOUT OF TEXT
This text is divided into two parts: the first part covers programming constructs
and demonstrates the programming method versus efficient use of built-in
functions to solve problems. The second part covers tools that are used for basic
problem solving, including plotting, image processing, and mathematical
techniques to solve systems of linear algebraic equations, fit curves to data, and
perform basic statistical analyses. The first six chapters cover the very basics in
MATLAB and in programming, and are all prerequisites for the rest of the book.
After that, many chapters in the problem-solving section can be introduced,
Preface xv

when desired, to produce a customized flow of topics in the book. This is true
to an extent, although the order of the chapters has been chosen carefully to
ensure that the coverage is systematic.
The individual chapters are described here, as well as which topics are required
for each chapter.

PART 1: INTRODUCTION TO PROGRAMMING


USING MATLAB
Chapter 1: Introduction to MATLAB begins by covering the MATLAB Desktop
Environment. Variables, assignment statements, and types are introduced.
Mathematical and relational expressions and the operators used in them are
covered, as are characters, random numbers, and the use of built-in functions
and the Help browser.
Chapter 2: Vectors and Matrices introduces creating and manipulating vectors
and matrices. Array operations and matrix operations (such as matrix multi-
plication) are explained. The use of vectors and matrices as function arguments,
and functions that are written specifically for vectors and matrices are covered.
Logical vectors and other concepts useful in vectorizing code are emphasized in
this chapter.
Chapter 3: Introduction to MATLAB Programming introduces the idea of
algorithms and scripts. This includes simple input and output, and com-
menting. Scripts are then used to create and customize simple plots, and to do
file input and output. Finally, the concept of a user-defined function is intro-
duced with only the type of function that calculates and returns a single value.
Chapter 4: Selection Statements introduces the use of logical expressions in if
statements, with else and elseif clauses. The switch statement is also demon-
strated, as is the concept of choosing from a menu. Also, functions that return
logical true or false are covered.
Chapter 5: Loop Statements and Vectorizing Code introduces the concepts of
counted (for) and conditional (while) loops. Many common uses, such as
summing and counting, are covered. Nested loops are also introduced. Some
more sophisticated uses of loops, such as error-checking and combining loops
and selection statements, are also covered. Finally, vectorizing code, by using
built-in functions and operators on vectors and matrices instead of looping
through them, is demonstrated. Tips for writing efficient code are emphasized
and tools for analyzing code are introduced.
The concepts in the first five chapters are assumed throughout the rest of the
book.
xvi Preface

Chapter 6: MATLAB Programs covers more on scripts and user-defined


functions. User-defined functions that return more than one value and also that
do not return anything are introduced. The concept of a program in MATLAB
which consists of a script that calls user-defined functions is demonstrated with
examples. A longer, menu-driven program is shown as a reference, but could be
omitted. Subfunctions and scope of variables are also introduced, as are some
debugging techniques.
The concept of a program is used throughout the rest of the book.
Chapter 7: String Manipulation covers many built-in string manipulation
functions, as well as converting between string and number types. Several
examples include using custom strings in plot labels and input prompts.
Chapter 8: Data Structures: Cell Arrays and Structures introduces two main
data structures e cell arrays and structures. Once structures are covered, more
complicated data structures, such as nested structures and vectors of structures,
are also introduced. Cell arrays are used in several applications in later chapters,
such as file input in Chapter 9, variable number of function arguments in
Chapter 10, and plot labels in Chapter 11, and are therefore considered
important and are covered first. The rest of the chapter on structures can be
omitted, although the use of structure variables to store object properties is
shown in Chapter 11.
Chapter 9: Advanced File Input and Output covers lower-level file input/
output statements that require opening and closing the file. Functions that can
read the entire file at once, as well as those that require reading one line at
a time, are introduced, and examples that demonstrate the differences in their
use are shown. Additionally, techniques for reading from and writing to
spreadsheet files and also .mat files that store MATLAB variables are introduced.
Cell arrays and string functions are used extensively in this chapter.
Chapter 10: Advanced Functions covers more advanced features of and types
of functions, such as anonymous functions, nested functions, and recursive
functions. Function handles, and their use with both anonymous functions and
function functions are introduced. The concept of having a variable number of
input and/or output arguments to a function is introduced; this is implemented
using cell arrays. String functions are also used in several examples in this
chapter. The section on recursive functions is at the end and may be omitted.

PART 2: ADVANCED TOPICS FOR PROBLEM


SOLVING WITH MATLAB
Chapter 11: Advanced Plotting Techniques continues with more on the plot
functions introduced in Chapter 3. Different two-dimensional plot types, such
Preface xvii

as logarithmic scale plots, pie charts, and histograms are introduced, as is


customizing plots using cell arrays and string functions. Three-dimensional
plot functions, as well as some functions that create the coordinates for spec-
ified objects, are demonstrated. The notion of Handle Graphics is covered, and
some graphics properties, such as line width and color, are introduced. Core
graphics objects and their use by higher-level plotting functions are demon-
strated. Applications that involve reading data from files and then plotting use
both cell arrays and string functions.
Chapter 12: Basic Statistics, Sets, Sorting, and Indexing starts with some of
the built-in statistical and set operations in MATLAB. As some of these require
a sorted data set, methods of sorting are described. Finally, the concepts of
indexing into a vector and searching a vector are introduced. Sorting a vector of
structures and indexing into a vector of structures are described, but these
sections can be omitted. A recursive binary search function is in the end and
may be omitted.
Chapter 13: Sights and Sounds briefly discusses sound files and introduces
image processing. An introduction to programming GUIs is also given,
including the creation of a button group and embedding images in a GUI.
Nested functions are used in the GUI examples.
Chapter 14: Advanced Mathematics covers four basic topics: curve fitting,
complex numbers, solving systems of linear algebraic equations, and inte-
gration and differentiation in calculus. Matrix solutions using the
GausseJordan and GausseJordan elimination methods are described. This
section includes the mathematical techniques and also the MATLAB functions
that implement them. Finally, some of the symbolic math toolbox functions
are shown, including those that solve equations. This method returns a struc-
ture as a result.

PEDAGOGICAL FEATURES
There are several pedagogical tools that are used throughout this book that are
intended to make it easier to learn the material.
First, the book takes a conversational tone with sections called “Quick Ques-
tion!”. These are designed to stimulate thought about the material that has just
been covered. The question is posed, and then the answer is given. It will be
most beneficial to the reader to try to think about the question before reading
the answer! In any case, they should not be skipped over, as the answers often
contain very useful information.
“Practice” problems are given throughout the chapters. These are very simple
problems that drill the material just covered.
xviii Preface

“Explore Other Interesting Features”: this section has been added to the end of
every chapter in this third edition. This book is not intended to be a complete
reference book, and cannot possibly cover all of the built-in functions and tools
available in MATLAB; however, in every chapter there will be a list of functions
and/or commands that are related to the chapter topics, which readers may
wish to investigate.
When some problems are introduced, they are solved using both “The
Programming Concept” and “The Efficient Method”. This facilitates under-
standing the built-in functions and operators in MATLAB, as well as the
underlying programming concepts. “The Efficient Method” highlights methods
that will save time for the programmer, and, in many cases, are also faster to
execute in MATLAB.
Additionally, to aid the reader:
n identifier names are shown in italic
n MATLAB function names are shown in bold
n reserved words are shown in bold and underline
n key important terms are shown in bold and italic.
The end-of-chapter “Summary” contains, where applicable, several sections:
Common Pitfalls: a list of common mistakes that are made, and how to
avoid them.
Programming Style Guidelines: in order to encourage “good” programs,
that others can actually understand, the programming chapters will have
guidelines that will make programs easier to read and understand, and
therefore easier to work with and modify.
Key Terms: a list of the key terms covered in the chapter, in sequence.
MATLAB Reserved Words: a list of the reserved key words in MATLAB.
Throughout the text, these are shown in bold, underlined type.
MATLAB Functions and Commands: a list of the MATLAB built-in
functions and commands covered in the chapter, in the order covered.
Throughout the text, these are shown in bold type.
MATLAB Operators: a list of the MATLAB operators covered in the chapter,
in the order covered.
Exercises: a comprehensive set of exercises, ranging from the rote to more
engaging applications.

ADDITIONAL BOOK RESOURCES


A companion website with additional teaching resources is available for faculty
using this book as a text for their course(s). Please visit www.textbooks.elsevier.
com/9780750687621 to register for access to:
Preface xix

n instructor solutions manual for end-of-chapter problems


n instructor solutions manual for “Practice” problems
n electronic figures from the text for creation of lecture slides
n downloadable M-files for all examples in the text.
Other book-related resources will also be posted there from time to time.
This page intentionally left blank
Acknowledgments

I am indebted to many, many family members, colleagues, mentors, and


students.
Throughout the last 26 years of coordinating and teaching the basic compu-
tation courses for the College of Engineering at Boston University, I have been
blessed with many fabulous students, as well as graduate teaching fellows and
undergraduate teaching assistants (TAs). There have been hundreds of TAs over
the years e too many to name individually e but I thank them all for their
support. In particular, the following TAs were very helpful in reviewing drafts of
the original manuscript and subsequent editions, and suggesting examples:
Edy Tan, Megan Smith, Brandon Phillips, Carly Sherwood, Ashmita Randhawa,
Mike Green, Kevin Ryan, Brian Hsu, Paul Vermilion, Jake Herrmann, Ben
Duong, and Alan Morse. Kevin Ryan wrote the MATLAB scripts that were used to
produce the cover illustrations.
A number of colleagues have been very encouraging throughout the years. In
particular, I would like to thank my former and current department chairmen
Tom Bifano and Ron Roy for their support and motivation, and Tom for his
graphical user interface example suggestions. I am also indebted to my mentors
at Boston University, Bill Henneman of the Computer Science Department and
Merrill Ebner of the Department of Manufacturing Engineering, as well as Bob
Cannon from the University of South Carolina.
I would like to thank all of the reviewers of the proposal and drafts of this
book. Their comments have been extremely helpful and I hope I have incor-
porated their suggestions to their satisfaction. They include: Pedro J.N. Silva,
Departamento de Biologia Vegetal, Faculdade de Ciências da Universidade de
Lisboa; Dr. Dileepan Joseph, Professor, University of Alberta; Dr. Joseph
Goddard, Professor, UC San Diego; Dr. Geoffrey Shiflett, University of
Southern California; Dr. Steve Brown, University of Delaware; Dr. Jackie
Horton, Senior Lecturer, University of Vermont; Dr. Robert Whitman, Senior
Lecturer, University of Denver; Dr. Lauren Black, Assistant Professor, Tufts
University; Dr. Chris Fietkiewicz, Professor, Case Western Reserve University;
Dr. Philip Wong, Professor, Portland State University; Dr. Mark Lyon,

xxi
xxii Acknowledgments

Professor, University of New Hampshire; and Dr. Cheryl Schlittler, Professor,


University of Colorado, Colorado Springs.
Also, I thank those at Elsevier who helped to make this book possible,
including: Joseph Hayton, Publisher; Stephen Merken, Acquisitions Editor; Jeff
Freeland, Editorial Project Manager; Lisa Jones, Project Manager; and Tim Pitts,
a Publisher at Elsevier in the United Kingdom.
Much of the work on this edition was done in Scotland on the Isle of Skye and
in Balquhidder and in Esquel, Argentina. Many thanks to the folks at Mon-
achyle Mhor and Patagonia River Guides, and to Donald and Dinah Rankin for
their hospitality!
Finally, thanks go to all of my family, especially my parents Roy Attaway and
Jane Conklin, both of whom encouraged me at an early age to read and to
write. Thanks also to my husband Ted de Winter for his encouragement and
good-natured taking care of the weekend chores while I worked on this
project!
The photo used in the image processing section was taken by Ron Roy.
1 PART

Introduction to Programming
Using MATLAB
Random documents with unrelated
content Scribd suggests to you:
According to this estimate the cat is a domestic comfortable
creature, usually found curled up like the ammonite, and in a state
of semi-torpor; it is essentially selfish and essentially cruel, but apart
from these two drawbacks, essentially feminine. “The cat is selfish,
and the dog is faithful.” This sums up a judgment founded on wilful
ignorance and gross egotism.
In respect to what is the dog faithful and the cat selfish? Simply in
this regard, that the dog takes the vainest man on something better
than his own estimate, while of the cat’s life and world the human
being forms but a little part.
Here plainly Greek meets Greek, and we had better let the
accusation of egotism alone. But apart from this point, the above
summary of the cat’s nature is about as true as the following
summary of the sportsman’s nature from the cat’s point of view.
“The sportsman is a quiet, domestic creature, fond of his comforts
and his meals; he is generally found smoking in an armchair before
the fire. The only thing which interferes with his domesticity is his
tendency to absent himself from the house for hours together; this
appears to be the result of a curious mania quite foreign to his
nature; and it will cause him even to miss his meals. If you come
upon him at such times he is engaged in a prosaic kind of wholesale
slaughter; he has no exciting chases after his prey, no display of
ability, no well-planned ambushes; but he kills at a distance through
an unpleasantly noisy instrument. The sportsman, too, is absolutely
dangerous to life at such time, and I have known cats fall victims to
his rage; whereas, if you meet him in his normal condition, he is
usually quite tame; you can safely leave kittens in the room with
him, and I have never known him kill a caged bird. The keeper is a
very dangerous sort of sportsman, and must be regarded as radically
unsafe. The difference between sportsmen and keepers is much the
same as that between capricious bulls and mad bulls.”
The fact is, that the usual judgment of cats rests on a total
misapprehension of the scope of a cat’s life; and the root of the
misunderstanding goes wider and deeper than this. The average
human being takes account only of those qualities of animals which
have some practical bearing on human life; even the animal lover is
wont to take account only of animal qualities, physical, mental, and,
at a stretch, moral; whereas that which is the pivot of human life
and human relations; that which, rudimentary as it is in animals, is
still the pivot of animal qualities—namely, the force of personality—is
altogether left out of account.
No judgment of animals can be adequate, or in any sense true,
which does not take account of personality, more or less developed,
and of the scope of the creature’s life as determined by it.
The more intimately one knows animals, the more one is struck by
their individuality, and the varying force of their personality.
Persis had the most intense personality of any animal I have ever
known. Mentu’s, less vivid, was still as individual and distinct; Ra had
a little narrow nature, Alexander was undeveloped, and the tabby is
frankly common; but all are as distinct from one another, as
essentially personal, as five human beings.
And it is greatly through this personality that the scope of an
animal’s life, as of the life of the human being, is determined; we are
all more or less at the mercy of what we, in our blindness, call “blind
forces;” but in all of us there is something which out of the
“manifold” of the world seeks and selects a consistent experience,
some principle which determines the scope of life.
Out of the many chemicals of the soil each plant draws those which
are appropriate to its own life, each plant transforms them into a
living thing, a definite beauty of leaf and bud.
And the alchemy of the higher creature does not only transform the
material particles of the world, now into the ashen silky hair and
yellow eyes of Mentu, now into the curly grizzled coat of Taffy; but
through the intelligence and sensibilities, through the desire for
approbation and of admiration, through the protective love of the
offspring, and the pure straining after the affection of the human
being, dimly understood, these dawning consciousnesses gather
from the world of sensation, of intelligence, of emotion, such
material as they can assimilate and transform, defining it into a life
and world of their own.
If we cannot from the point of more developed moral consciousness,
and higher intelligence, even seek to understand the dawnings in the
lower creatures of that which makes us what we are, then to us
animals are mere playthings or mere slaves, and we can have no
least perception of what is meant by that earnest, if unrealised,
“expectation of the creature.”

II

“All instincts immature,


All purposes unsure.”

The difference between different races of animals appears to lie very


greatly in the different scope of their lives.
The cat’s life, as distinguished from the dog’s, is essentially
independent; and this, combined with finer sensibilities and a less
facile intelligence, give a predominance in the cat of these elements
of character which as developed in the human being we call the
artistic temperament.
The cat is, above all things, a dramatist; its life is lived in an endless
romance though the drama is played out on quite another stage
than our own, and we only enter into it as subordinate characters,
as stage managers, or rather stage carpenters.
We realise this with kittens; we see that the greater part of their life,
of the sights and sounds of it, are the material of a drama half
consciously played; they are determined to make mysteries, and as
a child will seize upon the passing light or shadow to help him to
transform some well-known object into the semblance of living
creature, so you may see the kitten reach a paw again and again to
touch a reflection on a polished floor, or conjure the shadows of
evening into the forms of enemies.
We cannot but see this, and our mistake comes later when the kitten
passes partly out of our ken to reappear from time to time, a
serious, furtive creature with the weight of the world on its
shoulders. We think then that the romance has ceased, when it has
in reality gone deeper; the stage has widened out of sight, and if the
cat no longer plays before us it is because we have lost sympathy
with this side of its life; if we encourage it, it will play like a kitten up
to old age. This same fact possibly explains the reason of the theory
that cats care for places and not for people—it may be because
these same people care for kittens and not for cats; thus the cat
transfers the affection it might have felt for the human being to the
scene of its romances and the places where it has experienced the
surprise and joy of its kittens.
Corresponding to the dramatic instinct the cat appears to have its
sensibilities more developed in the direction of æsthetic enjoyment
than the dog’s, which are almost purely utilitarian. But it is a strange
fact that the most universal kind of æsthetic enjoyment among
animals—namely, the pleasures of music—seem to be keenest
among those races which comparatively we rank low in respect of
intelligence—namely, reptiles and birds.
I whistled “God Save the Queen” once to two green lizards in an
Italian garden; they drew by little runs and jerks out of their holes,
and their paths converged. Suddenly when their nerves were tense
with excitement of the air (rendered slightly out of tune) they saw
each other, sprang with one impulse together, bit until I saw the
green skin wrinkle, rolled over and disappeared. I have never seen
either cat or dog show anything approaching to the emotion which
music produces in Joey, though Persis showed some pleasurable
excitement in whistling, and some desire to try the notes of a piano
for herself. Dogs for the most part take the pleasures of music with
extreme seriousness almost amounting to gloom. It is not
uncommon to find dogs who will “sing,” following to some small
extent the air as it rises or falls. But they do this with an aspect of
extreme melancholy, and a thrill sometimes seems to run through
the whole body before the sound is produced; that they do not
absolutely dislike it can only be judged from the fact that they do
not try to go away.
Both dogs and cats appear to be unconscious of the sounds they
utter until experience has taught them the result or until their
attention has been specially directed to it. I have indeed met a
Scotch terrier who would “sing” to order, but his face expressed a
painful tension of will. To do him justice he sang a strain or two with
apparent ease under my window in the middle of the night.
Frequently, too, a dog who wishes to make his presence realised has
his voice strangulated by nervousness like a shy girl at a music
lesson; and a well-bred cat anxious to attract attention sometimes
opens its mouth silently.
All such facts seem to point to the conclusion that many animals do
not produce their voices voluntarily, but solely on physical impulse;
that even imitative utterance may often be based on some such
physical sensation, as many people feel a tremble in the throat when
a Bourdon stop is on the organ. If this be so we are on the wrong
tack in comparing the sounds of animals, however varied and
specified they may be, to language, and we should rather compare
them to weeping, groaning, sighing, yawning, and laughter, which in
the same way produce an imitative response, which are by nature
involuntary, and have no tendency to develop into definite language.
If cats and dogs have, compared with other creatures, little feeling
for music, they seem to have still less for pleasures of sight. I have
known a mare which again and again at the same place seemed to
look out with pleasure over a view, when no definite object was
moving to catch her eye, but I have never known a dog do this, and
though a cat often takes up this attitude, the focus of her eyes
seems to be more definitely fixed, and she is probably attracted by
some movement too minute to arrest our attention. To colour they
seem still more indifferent, not sharing even the susceptibility of the
mad bull. I have heard indeed of a dog preferring scarlet to light
blue; but it is impossible with a single instance to eliminate individual
association. Cats, however, though showing no susceptibility to
colour, show a very clear perception of texture. It is not necessarily
the most strictly comfortable textures that are preferred; velvet may
do to sleep on, but it is on thin crackling paper or stiff silk that a cat
would choose to sit, and, above all, to eat. And contrary to all
expectation, woolly textures are chosen to lick. A cat has been
known to go round the garden in order to lick the soft underside of
foxglove leaves; and will even tear a paper wrapper in order to be
able to stroke flannelette with his tongue. As flannelette is prepared
with a poisonous chemical this pleasure is hazardous.
But the real region of æsthetic pleasure for a cat is the region of
smell. The dog uses smell as a medium of information; the cat revels
in it. The dog smells the ground to trace friend or foe, food or prey,
but the cat will linger near a tree-trunk, smelling each separate
aromatic leaf. If the window of a close room is opened the cat goes
to it, and puts her head out to sniff the air; she will smell the dress
of a friend, partly for recognition no doubt, but apparently partly for
pleasure also. An aromatic smell is pleasant; a strong spirituous
smell not only disagreeable but absolutely painful. Lavender water or
eau-de-cologne may please a tiger but will put a cat to flight.
The cat’s drama is a drama of the twilight, when the earth refreshed
gives up her secret, subtle scents. It is not to be played in broad
daylight; it is a mystery play of things half revealed, subtly
transformed, hardly understood, secretly suggestive.

III
“But when she came back the dog was laughing.”
Counterbalancing the rudimentary powers of æsthetic pleasure in
the cat, we find in the dog a more facile intelligence, and a far more
adaptable nature. Some boast that they have taught tricks to a cat;
but the fact shows not so much that the cat was intelligent and
docile as that its owners were; for their ability has been usually to
seize on some natural movement of the cat, in jumping or in sitting
up, and gradually to induce the animal to exaggerate it. But the
tricks we teach a dog are against his nature, and it needs not only
intelligence but docility to take a savoury bite and abstain from
swallowing until the precisely right word is pronounced.
A cat walks about with a great purpose dimly imagined in its brain,
but a dog plans; he is “the low man adding one to one,” but his
sums are the most correct, for he is of a practical nature. He does
not have to pretend that a stick is alive before he can glean pleasure
from playing with it.
How far a dog, or indeed how far any animal is capable of using an
instrument for effecting its purposes is an undecided question; but I
have heard on near authority of a dog scraping a mat up against a
swing door through which he had to pass so that the door was kept
open. To use an instrument involves a complicated mental process,
in which not only association but reflection on the nature of the
thing is required. Taffy associated his muzzle with his walk, and
fetched it with pleasure when the association was established; but
reflection did not sufficiently come into the process to prevent him
from fetching a clothes brush or a Bible instead if convenient.
One clear point of superiority in the dog is his rudimentary sense of
humour. Almost any good-tempered dog, when well treated, will try
from time to time to laugh off a scolding. If he is encouraged, the
fooling is repeated again and again with growing exaggeration as he
rolls over with wide mouth and absurd contortions, or flies at one’s
face to lick it. He appreciates humour in others at his own expense,
a thing which not every human being is capable of doing; if he is
teased laughingly, he too will play the fool; if he is teased cruelly he
is cross or wretched. No dog likes one to blow in his face or ear, but
Taffy, though not wholly good-tempered, will allow the bellows to be
placed even in his mouth if he is assured that it is a game. When the
puff of air comes he darts up, jumps at and licks the person who is
teasing him, and barks with a wagging tail. If he is really bored or
tired he licks the nozzle of the bellows, or the hand that holds them,
deprecatingly; he declines the game, but in perfect good humour.
Now a cat has no sense of humour at all. Its very comedies are
serious; and to tease it is to outrage its dignity. The better bred a cat
is the more easily it takes offence. But after all the “sense of the
ridiculous” is a gross quality, and the humour of one age or of one
class seems vulgarity to another a little in advance. A cat is never
vulgar.

IV

“The tumult of unproved desire, the unaimed,


Uncertain yearnings, aspirations blind.”

If the scope of life and the qualities of intelligence differ from race to
race of animals, the strictly moral qualities appear to differ from
individual to individual.
Cats are called “selfish”; but even on the undiscriminating view such
qualities differ from cat to cat. Ra was certainly self-absorbed, but I
attribute this greatly to unhappy family circumstances when he was
young. Persis and Mentu were not selfish in this sense at all. Again
and again they have been found in the room with food untouched.
When one came in there was a greeting and short display of
affection, and not till then would the cat go to its food, and eat with
good appetite. Few people think of accusing a straightforward genial
collie of selfishness; yet if I left Taffy alone with his dinner, or even
with some one else’s dinner, there is a strong presumption that I
should find the plate clean and shining on return.
What people usually mean by this assertion is that the cat does not,
like the dog, depend entirely on human companionship; there are no
touching stories of faithfulness to a departed master; there is no
overwhelming interest in the human race. A cat has more of what
the average Briton calls “self-respect,” a quality he likes far better in
himself than in others.
On the other hand, a cat has more interest in other races of beings
than a dog. The only creatures in which most dogs show
spontaneous interest, unsolicited and untaught, are horses; and
even here the interest rests on association. But we have all known
cases of cats which deliberately set themselves to woo dogs; Ra and
his grandmother, unlike in all else, adored the same fox-terrier. I
have indeed seen a dog which had lost her puppies nurse a half-
grown cat, but the cat seemed to take the initiative. On the other
hand, a Manx cat, in a house where I was staying, allowed a beloved
terrier to take food out of her mouth. A cat has been known to bring
up squirrels; a tom-cat of our own fondled and protected chickens;
finally, a cat has been known to bring a half-starved friend to share
its dinner.
So-called “animal instincts” cannot account for the greater part of
these cases, which involve rather definite sacrifice. Dog friendships,
on the other hand, rarely involve sacrifice except for the sake of
man.
This instinct of benevolence may be noticed among birds. I have
heard on good authority of an Uncle canary bringing up a deserted
brood, and even with apparent embarrassment taking his place on
the nest; of sparrows bringing up young starlings, which, taken from
their own nest and placed on a window-ledge, sought refuge in the
sparrows’ nest; and finally, of a sparrow helping a wagtail to feed a
young cuckoo. Unless birds absolutely enjoy filling each other’s
mouths, such operations involve sacrifice; but in any case there is a
large social instinct shown; and when, as I sit in the garden, the
bean poles and seed sticks near me begin to blossom into robins, I
find I am suddenly the centre towards which such social instincts are
directed.
Temper differs in the same way from individual to individual, in
extent and quality. Ra had a cross temper; it irritated him if one took
liberties, and he struck without warning; but with regard to other
animals cowardice kept his temper in check. Mentu had the
occasional irritability of a nervous temperament, whether animal or
human; he often kept a bold front upon danger, when fear made
him afterwards positively sick and unable to eat for some time.
Persis was a very fiend to other animals, but had an utterly sweet
and grateful temper towards human beings unless jealousy came
into play.
Dogs are more often misjudged in respect to temper than cats,
probably because their ill-temper is more formidable; and the
nervous excitability of the collie is often mistaken for bad temper. I
have known a bad-tempered collie, but the clergyman who owned
him did not keep him long, as it was apt to make difficulties in the
parish if the congregation of the mission church was kept at bay on
a dark, windy evening.
Pugnacity is perhaps a different thing from ill-temper, and appears to
be a very wide-spread quality in bird-life. A great robin-tamer told
me that no robin could support his position unless he was very
pugnacious. Those who have tried to tame wild birds, or even those
who feed birds in the winter, will notice the extraordinary displays of
temper among them; how the blackbird loses half his meal through
trying to chase other birds away; how the tits play with him,
reckoning on this pugnacity; how the robin after he has made a
hearty meal lies in wait for late comers. Barn-door cocks are too
universally condemned in respect of temper; my patriarch has been
several times reported to me as having placed himself between two
young combatants; and he lives on excellent terms with a younger
replica of himself, the only point of quarrel being the distance to
which the young cock may chase a hen of the other’s harem which
has strayed into his own yard. Pugnacity is indeed apt to develop
into ill-temper with caged birds, but gentle handling in taming and
increased freedom would probably go far to obviate this.
I have spoken of moral qualities, but the centre of all these is the
question of conscience. It is impossible to deny that at any rate the
higher animals have conscience, if conscience means the recognition
of a law or principle higher than the immediate personal desire and
sometimes antagonistic to it.
Even if we allow that the sense of duty in human beings is based on
the “sanctions” of pleasures and pain, this makes no difference to
the quality of the sense once evolved; neither can it make any
difference in the quality of the sense in animals whether this is
produced by the “sanction” of nature or of the human race.
The more intelligent domestic creatures accept to some extent a
standard given by the power above them. The human standard is to
them in a sense as the law written on stone to us; and all know the
law has gone forth against the indulgence of ill-temper. Joey
recognises this law, and it is a moral effort he makes (very seldom)
to refrain from biting; he, too, has a conscience, though a singularly
bad one. Taffy with the nozzle of the bellows in his mouth can
choose whether to accept the situation cheerfully or crossly.
But the dog accepts his moral code more entirely from the human
being than the cat does. In this respect the cat is as the Gentile,
without the law, but a law unto himself. There is sacrifice of the
lower desires to the higher when the cat brings a friend to share her
dinner; when she lets a dog take food out of her mouth; when she
carries on towards her kittens, after the immediate needs and
desires of motherhood have ceased, a course of conduct more or
less consistently educative. A cat, the Egyptians said, reasoned like a
man, and this is true in that she determines, like a man, her own
ends and purposes in life. It is not approbation but admiration that
the cat demands from man; the dog accepts the purposes of life as
given from above. But he recognises, as clearly as he recognises the
sanction of the ginger-bread and the whip, the sanction of moral
appreciation or disapproval. He claims applause when he has done
well, and when the whip has been endured he still clings with
renewed trust to his diviner friend, and seeks by affection to win
back approval.
Such animals have wills essentially free as our own, but with dimmer
intelligence these wills are more at the mercy of their passions; and
the blinder intelligence leaves them, too, more at the mercy of
spiritual influences which flow out from us to them. There is a quick
response, as with children, not only to our treatment, but to the
spirit of our treatment, for they reward our trust with trust, and
answer our cheerfulness with heart and courage. And we, too, war
with principalities and powers, and are helped in the high and
hidden places by influences unseen. We call these creatures blind
and unconscious, but our consciousness, too, is dim, and our eyes
blinder to things divine than theirs to things human; we both move
gropingly and feebly in a great world and battle against the Will that
made us and has mercy on us—“so many men that know not their
right hand from their left, and also much cattle.”

Printed by Ballantyne, Hanson & Co.


London & Edinburgh
TRANSCRIBER’S NOTE
Unusual, archaic and obsolete spellings and word usage have been maintained as in the
original book. Obvious printing errors have been fixed as detailed below. The Table of
Contents was expanded to cover portions of the book other than the stories. The cover
was produced by the transcriber from materials in the book. The cover is hereby placed
in the public domain.
The placement of the drawings of cats by Madame Ronner made more sense in the
printed book, where they filled blank space. I have shrunk them a little so that they are
not distracting.
Details of the changes:
Page 35 asparagus bed; the walked[**walk] quickened as he got nearer,
Page 79 it as clearly; if [**he] has done well, he goes
Page 84 to give it board and longing[**lodging], and it surely
*** END OF THE PROJECT GUTENBERG EBOOK THE SOUL OF A
CAT, AND OTHER STORIES ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like