Brian H. Hahn
Daniel T. Valentine
Copyright
Academic Press is an imprint of Elsevier
225 Wyman street, Waltham, MA 02451, USA
Linacre House, Jordan Hill, Oxford OX2 8DP, UK
Copyright 2013, Daniel T. Valentine. Published by Elsevier Ltd. All rights reserved.
MATLAB is a trademark of The MathWorks, Inc. and is used with permission.
The MathWorks does not warrant the accuracy of the text or exercises in this book.
This books use or discussion of MATLAB software or related products does not constitute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the MATLAB software.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written permission of the publisher.
Permissions may be sought directly from Elseviers Science & Technology Rights Department in Oxford, UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, E-mail: permissions@elsevier.com. You may also complete your request online via the Elsevier homepage (http://www.elsevier.com), by selecting Support & Contact then Copyright and Permission and then Obtaining Permissions.
Library of Congress Cataloging-in-Publication Data
A catalog record for this book is available from the Library of Congress.
British Library Cataloguing-in-Publication Data
A catalogue record for this book is available from the British Library.
ISBN: 978-0-12-394398-9
For information on all Academic Press publictions visit our website at www.elsevierdirect.com
Printed in United States of America
13 14 15 16 1710 9 8 7 6 5 4 3 2 1
Preface
The main reason for a fourth edition of Essential MATLAB for Engineers and Scientists is to keep up with MATLAB, now in its latest version (7.7 Version 2008B). Like the previous editions, this one presents MATLAB as a problem-solving tool for professionals in science and engineering, as well as students in those fields, who have no prior knowledge of computer programming.
In keeping with the late Brian D. Hahns objectives in previous editions, the fourth edition adopts an informal, tutorial style for its teach-yourself approach, which invites readers to experiment with MATLAB as a way of discovering how it works. It assumes that readers have never used this tool in their technical problem solving.
MATLAB, which stands for Matrix Laboratory, is based on the concept of the matrix. Because readers will be unfamiliar with matrices, ideas and constructs are developed gradually, as the context requires. The primary audience for Essential MATLAB is scientists and engineers, and for that reason certain examples require some first-year college math, particularly in Part 2. However, these examples are self-contained and can be skipped without detracting from the development of readers programming skills. MATLAB can be used in two distinct modes. One, in keeping the modern-age craving for instant gratification, offers immediate execution of statements (or groups of statements) in the Command Window. The other, for the more patient, offers conventional programming by means of script files. Both modes are put to good use here: the former encouraging cut and paste to take full advantage of Windows inter-active environment; the latter stressing programming principles and algorithm development through structure plans.
Although most of MATLABs basic (essential) features are covered, this book is neither an exhaustive nor a systematic reference. This would not be in keeping with its informal style. For example, constructs such as for and if are not always treated, initially, in their general form, as is common in many texts, but are gradually introduced in discussions where they fit naturally. Even so, they are treated thoroughly here, unlike in other texts that deal with them only superficially. For the curious, helpful syntax and function quick references can be found in the appendices. The following list contains other highlights of Essential MATLAB for Engineers and Scientists, fifth edition:
1. Warnings of the many pitfalls that await the unwary beginner.
2. Numerous examples taken from science and engineering (simulation, population modeling, numerical methods) as well as business and everyday life.
3. An emphasis on programming style to produce clear, readable code.
4. Comprehensive chapter summaries.
5. Chapter exercises (answers and solutions to many of which are given in an appendix).
6. A thorough, instructive index.
Essential MATLAB is meant to be used in conjunction with the MATLAB software. The reader is expected to have the software at hand in order to work through the exercises and thus discover how MATLAB does what it is commanded to do. Learning any tool is possible only through hands-on experience. This is particularly true with computing tools, which produce correct answers only when the commands they are given and the accompanying data input are correct and accurate.
Acknowledgments
I would like to thank Mary, Clara, and Zach for their support, and I dedicate the fifth edition of Essential MATLAB for Engineers and Scientists to them.
Daniel T. Valentine
Part 1
Essentials
Part I
Essentials
Part 1 concerns those aspects of MATLAB that you need to know in order to come to grips with MATLABs essentials and those of technical computing. Because this book is a tutorial, you are encouraged to use MATLAB extensively while you go through the text.
Chapter 1
Introduction
The objectives of this chapter are:
To enable you to use some simple MATLAB commands from the Command Window
To examine various MATLAB desktop and editing features
To learn some of the new features of the MATLAB R2012b Desktop
To learn to write scripts in the Editor and Run them from the Editor
To learn some of the new features associated with the tabs (in particular, the PUBLISH and APPS features)
MATLAB is a powerful technical computing system for handling scientific and engineering calculations. The name MATLAB stands for Matrix Laboratory, because the system was designed to make matrix computations particularly easy. A matrix is an array of numbers organized in m rows and n columns. An example is the following m n = 2 3 array: