logo资料库

Essential MATLAB for Engineers and Scientists 6ed.pdf

第1页 / 共400页
第2页 / 共400页
第3页 / 共400页
第4页 / 共400页
第5页 / 共400页
第6页 / 共400页
第7页 / 共400页
第8页 / 共400页
资料共400页,剩余部分请下载后查看
Preface
Acknowledgments
1 Introduction
Differentiation and integration
3 Program Design and Algorithm Development
3.1 The program design process
3.1.1 The projectile problem
3.2 Programming MATLAB functions
3.2.1 Inline objects: Harmonic oscillators
3.2.2 MATLAB function: y = fx
Summary
Exercise
4 MATLAB Functions and Data Import-Export Utilities
4.1 Common functions
4.2 Importing and exporting data
4.2.1 The load and save commands
4.2.2 Exporting text ASCII data
4.2.3 Importing text ASCII data
4.2.4 Exporting binary data
4.2.5 Importing binary data
Summary
Exercises
5 Logical Vectors
5.1 Examples
5.1.1 Discontinuous graphs
5.1.2 Avoiding division by zero
5.1.3 Avoiding in?nity
5.1.4 Counting random numbers
5.1.5 Rolling dice
5.2 Logical operators
5.2.1 Operator precedence
5.2.2 Danger
5.2.3 Logical operators and vectors
5.3 Subscripting with logical vectors
5.4 Logical functions
5.4.1 Using any and all
5.5 Logical vectors instead of elseif ladders
Summary
Exercises
Appendix 5.A Supplementary material
6 Matrices and Arrays
7 Function M-?les
7.1 Example: Newton's method again
7.2 Basic rules
7.2.1 Subfunctions
7.2.2 Private functions
7.2.3 P-code ?les
7.2.4 Improving M-?le performance with the pro?ler
7.3 Function handles
7.4 Command/function duality
7.5 Function name resolution
7.6 Debugging M-?les
7.6.1 Debugging a script
7.6.2 Debugging a function
7.7 Recursion
Summary
Exercises
Appendix 7.A Supplementary material
8 Loops
8.1 Determinate repetition with for
8.1.1 Binomial coef?cient
8.1.2 Update processes
8.1.3 Nested fors
8.2 Indeterminate repetition with while
8.2.1 A guessing game
8.2.2 The while statement
8.2.3 Doubling time of an investment
8.2.4 Prime numbers
8.2.5 Projectile trajectory
8.2.6 break and continue
8.2.7 Menus
Summary
Exercises
10 Vectors as Arrays and Other Data Structures
10.1 Update processes
10.1.1 Unit time steps
10.1.2 Non-unit time steps
10.1.3 Using a function
10.2 Frequencies, bar charts and histograms
10.2.1 A random walk
10.2.2 Histograms
10.3 Sorting
10.3.1 Bubble Sort
10.3.2 MATLAB's sort
10.4 Structures
10.5 Cell arrays
10.5.1 Assigning data to cell arrays
10.5.2 Accessing data in cell arrays
10.5.3 Using cell arrays
10.5.4 Displaying and visualizing cell arrays
10.6 Classes and objects
Summary
11 Errors and Pitfalls
11.1 Syntax errors
11.1.1 Incompatible vector sizes
11.1.2 Name hiding
11.2 Logic errors
11.3 Rounding error
Summary
Chapter exercises
12 Dynamical Systems
12.1 Cantilever beam
12.2 Electric current
12.3 Free fall
12.4 Projectile with friction
Summary
Exercises
13 Simulation
13.1 Random number generation
13.1.1 Seeding rand
13.2 Spinning coins
13.3 Rolling dice
13.4 Bacteria division
13.5 A random walk
13.6 Traf?c ?ow
13.7 Normal Gaussian random numbers
Summary
Exercises
15 Signal Processing
15.1 Harmonic analysis
15.2 Fast Fourier Transform FFT
16 SIMULINK"572 Toolbox
16.1 Mass-spring-damper dynamic system
16.2 Bouncing ball dynamic system
16.3 The van der Pol oscillator
16.4 The Duf?ng oscillator
Exercises
Appendix 16.A Supplementary material
17 Symbolics Toolbox
17.1 Algebra
17.1.1 Polynomials
17.1.2 Vectors
17.1.3 Matrices
17.2 Calculus
17.3 Laplace and Z transforms
17.4 Generalized functions
17.5 Differential equations
17.6 Implementation of funtool, MuPAD and help
17.6.1 The funtool
17.6.2 The MuPAD notebook* and Symbolic help
Exercises
A.1 Expressions
A.2 Function M-?les
A.3 Graphics
A.4 if and switch
A.5 for and while
A.6 Input/output
A.7 load/save
A.8 Vectors and matrices
C.1 General-purpose commands
C.1.1 Managing variables and the workspace
C.1.2 Files and the operating system
C.1.3 Controlling the Command Window
C.1.4 Starting and quitting MATLAB
C.2 Logical functions
C.3 MATLAB programming tools
C.3.1 Interactive input
C.4 Matrices
C.4.1 Special variables and constants
C.4.2 Time and date
C.4.3 Matrix manipulation
C.4.4 Specialized matrices
C.5 Mathematical functions
C.6 Matrix functions
C.7 Data analysis
C.8 Polynomial functions
C.9 Function functions
C.10 Sparse matrix functions
C.11 Character string functions
C.12 File I/O functions
C.13 2D graphics
C.14 3D graphics
C.15 General
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 11
Chapter 13
Chapter 14
Essential MATLAB for Engineers and Scientists
Essential MATLAB for Engineers and Scientists Sixth Edition Brian H. Hahn Daniel T. Valentine AMSTERDAM • BOSTON • HEIDELBERG • LONDON SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO NEW YORK • OXFORD • PARIS • SAN DIEGO Academic Press is an imprint of Elsevier
Academic Press is an imprint of Elsevier 50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States 525 B Street, Suite 1800, San Diego, CA 92101-4495, United States The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom 125, London Wall, EC2Y, 5AS, United Kingdom Copyright © 2017, 2013, 2010 Daniel T. Valentine. Published by Elsevier Ltd. All rights reserved. Copyright © 2007, 2006, 2002 Brian D. Hahn and Daniel T. Valentine. Published by Elsevier Ltd. 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 book’s 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 Elsevier’s 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-08-100877-5 For information on all Academic Press publications visit our website at https://www.elsevierdirect.com Publisher: Todd Green Acquisition Editor: Stephen Merken Editorial Project Manager: Nate McFadden Production Project Manager: Stalin Viswanathan Designer: Matthew Limbert Typeset by VTeX
Preface The main reason for a sixth edition of Essential MATLAB for Engineers and Scien- tists is to keep up with MATLAB, now in its latest version (9.0 Version R2016a). 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. Hahn’s objectives in previous editions, the sixth edition adopts an informal, tutorial style for its “teach-yourself” ap- proach, which invites readers to experiment with MATLAB as a way of discov- ering 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 con- structs are developed gradually, as the context requires. The primary audience for Essential MATLAB is scientists and engineers, and for that reason certain ex- amples require some first-year college math, particularly in Part II. 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 pa- tient, 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’ interactive environment. The latter stressing program- ming principles and algorithm development through structure plans. Although most of MATLAB’s basic (“essential”) features are covered, this book is neither an exhaustive nor a systematic reference. This would not be in keep- ing 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 xv
xvi Preface are treated thoroughly here, unlike in other texts that deal with them only su- perficially. 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, Sixth Edition: Warnings of the many pitfalls that await the unwary beginner Numerous examples taken from science and engineering (simulation, pop- ulation modeling, numerical methods) as well as business and everyday life An emphasis on programming style to produce clear, readable code Comprehensive chapter summaries Chapter exercises (answers and solutions to many of which are given in an appendix) A thorough, instructive index Essential MATLAB is meant to be used in conjunction with the MATLAB soft- ware. 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 com- manded to do. Learning any tool is possible only through hands-on expe- rience. 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, Zoe Rae and Zach T. for their support and encouragement. I dedicate the sixth edition of Essential MATLAB for Engineers and Scientists to them. Daniel T. Valentine
1P A R T Essentials Part 1 concerns those aspects of MATLAB that you need to know in order to come to grips with MATLAB’s essentials and those of technical computing. Be- cause this book is a tutorial, you are encouraged to use MATLAB extensively while you go through the text.
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 R2016a 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, be- cause 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 exam- ple is the following m × n = 2 × 3 array: A = 1 3 5 2 4 6 Any one of the elements in a matrix can be plucked out by using the row and column indices that identify its location. The elements in this example are plucked out as follows: A(1, 1) = 1, A(1, 2) = 3, A(1, 3) = 5, A(2, 1) = 2, A(2, 2) = 4, A(2, 3) = 6. The first index identifies the row number counted from top to bottom; the second index is the column number counted from left to right. This is the convention used in MATLAB to locate information in an array. A computer is useful because it can do numerous computations quickly, so operating on large numerical data sets listed in tables as arrays or matrices of rows and columns is quite efficient. This book assumes that you have never used a computer before to do the sort of scientific calculations that MATLAB handles, but are able to find your way Essential MATLAB for Engineers and Scientists. DOI:10.1016/B978-0-08-100877-5.00002-5 Copyright © 2017 Daniel T. Valentine. Published by Elsevier Ltd. All rights reserved. CHAPTER 1 CONTENTS Using MATLAB ...... 5 Arithmetic ................. 5 Variables.................... 7 Mathematical functions.................... 8 Functions and commands................. 8 Vectors....................... 9 Linear equations ...... 11 Tutorials and demos 12 The desktop ......... 13 Using the Editor and running a script....... 13 Help, publish and view ......................... 16 Symbolics and the MuPAD notebook APP.......................... 18 Other APPS.............. 23 Additional features .. 23 Sample program. 25 Cut and paste .......... 25 Saving a program: script files................ 27 Currentdirectory....... 28 Runningascriptfrom thecurrentfolder browser.................... 29 Aprograminaction. 29 3
分享到:
收藏