An Engineers Guide to MATLAB


Download An Engineers Guide to MATLAB


Preview text

An Engineer’s Guide to MATLAB®

This page intentionally left blank

An Engineer’s Guide to MATLAB®
With Applications from Mechanical, Aerospace, Electrical, Civil, and Biological Systems Engineering
Third Edition
Edward B. Magrab
Department of Mechanical Engineering, University of Maryland, College Park, MD
Shapour Azarm
Department of Mechanical Engineering, University of Maryland, College Park, MD
Balakumar Balachandran
Department of Mechanical Engineering, University of Maryland, College Park, MD
James H. Duncan
Department of Mechanical Engineering, University of Maryland, College Park, MD
Keith E. Herold
Fischell Department of Bioengineering, University of Maryland, College Park, MD
Gregory C. Walsh
Leica Geosystems, Inc., San Ramon, CA
Prentice Hall Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo

VP/Editorial Director, Engineering/Computer Science: Marcia J. Horton Assistant/Supervisor: Dolores Mars Senior Editor: Tacy Quinn Associate Editor: Dee Bernhard Director of Marketing: Margaret Waples Senior Marketing Manager: Tim Galligan Marketing Assistant: Mack Patterson Senior Managing Editor: Scott Disanno Project Manager: Greg Dulles Senior Operations Supervisor: Alan Fischer Production Manager: Wanda Rockwell Creative Director: Jayne Conte Cover Designer: Bruce Kenselaar Cover Art: Getty Images, Inc. Media Editor: Daniel Sandin Composition: Integra Printer/Binder: Courier Companies, Inc.
Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on appropriate pages within text.
MATLAB and Simulink are registered trademarks of The Mathworks, Inc., 3 Apple Hill, Natick MA 01760-2098.
Copyright © 2011, 2005, 2000 Pearson Education, Inc., publishing as Prentice Hall, One Lake Street, Upper Saddle River, New Jersey 07458. All rights reserved. Manufactured in the United States of America. This publication is protected by Copyright, and permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. To obtain permission(s) to use material from this work, please submit a written request to Pearson Education, Inc., Permissions Department, One Lake Street, Upper Saddle River, New Jersey 07458.
Many of the designations by manufacturers and seller to distinguish their products are claimed as trademarks. Where those designations appear in this book, and the publisher was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Library of Congress Cataloging in Publication Data
ISBN 13: 978-0-13-199110-1 ISBN 10: 0-13-199110-8

For June Coleman Magrab

This page intentionally left blank

Contents

List of Examples

xv

Preface to Third Edition

xxi

1 Introduction

1

Edward B. Magrab

1.1 Introduction 1 1.1.1 Organization of the Book and Its Goals 2 1.1.2 Some Suggestions on How to Use MATLAB 2 1.1.3 Book Notation Conventions 3
1.2 The MATLAB Environment 3 1.2.1 Introduction 3 1.2.2 Preliminaries—Command Window Management 5 1.2.3 Executing Expressions from the MATLAB Command Window—Basic MATLAB Syntax 8 1.2.4 Clarification and Exceptions to MATLAB’S Syntax 11 1.2.5 MATLAB Functions 14 1.2.6 Creating Scripts and Executing Them from the MATLAB Editor 19
1.3 Online Help 29 1.4 The Symbolic Toolbox 32 1.5 Summary of Functions Introduced in Chapter 1 41
Exercises 42

2 Vectors and Matrices

51

Edward B. Magrab

2.1 Introduction 51 2.2 Definitions of Matrices and Vectors 52 2.3 Creation of Vectors 53 2.4 Creation of Matrices 64 2.5 Dot Operations 83 2.6 Mathematical Operations with Matrices 92
2.6.1 Addition and Subtraction 92 2.6.2 Multiplication 92 2.6.3 Determinants 101 2.6.4 Matrix Inverse 104 2.6.5 Solution of a System of Equations 107 2.7 Summary of Functions Introduced in Chapter 2 112 Exercises 113

vii

viii

Contents

3 Data Input/Output

127

Edward B. Magrab

3.1 Strings and Annotated Output 127 3.1.1 Creating Strings 127 3.1.2 Converting Numerical Values to Strings and Displaying Them 130
3.2 Entering Data with input 135 3.2.1 Entering a Scalar with input 135 3.2.2 Entering a String with input 136 3.2.3 Entering a Vector with input 137 3.2.4 Entering a Matrix with input 137
3.3 Input/Output Data Files 137 3.4 Cell Arrays 141 3.5 Input Microsoft Excel Files 143 3.6 Summary of Functions Introduced in Chapter 3 144
Exercises 145

4 Program Flow Control

148

Edward B. Magrab

4.1 Introduction—The Logical Operator 148 4.2 Control of Program Flow 151
4.2.1 Branching—If Statement 151 4.2.2 Branching—Switch Statement 154 4.2.3 For Loop 155 4.2.4 While Loop 162 4.2.5 Early Termination of Either a for or a while Loop 166 4.3 Summary of Functions Introduced in Chapter 4 166 Exercises 167

5 Function Creation and Selected MATLAB Functions

172

Edward B. Magrab

5.1 Introduction 173 5.1.1 Why Use Functions 173 5.1.2 Naming Functions 174 5.1.3 Length of Functions 174 5.1.4 Debugging Functions 174
5.2 User-Defined Functions 175 5.2.1 Introduction 175 5.2.2 Function File 175 5.2.3 Subfunctions 181 5.2.4 Anonymous Functions 183 5.2.5 inline 184 5.2.6 Comparison of the Usage of Subfunctions, Anonymous Functions, and inline 185

Contents

ix

5.3 User-Defined Functions, Function Handles, and feval 186 5.4 MATLAB Functions that Operate on Arrays of Data 187
5.4.1 Introduction 187 5.4.2 Fitting Data with Polynomials—polyfit/polyval 188 5.4.3 Fitting Data with spline 190 5.4.4 Interpolation of Data—interp1 192 5.4.5 Numerical Integration—trapz 193 5.4.6 Area of a Polygon—polyarea 195 5.4.7 Digital Signal Processing—fft and ifft 196 5.5 MATLAB Functions that Require User-Defined Functions 201 5.5.1 Zeros of Functions—fzero and roots/poly 202 5.5.2 Numerical Integration—quadl and dblquad 207 5.5.3 Numerical Solutions of Ordinary Differential
Equations—ode45 212 5.5.4 Numerical Solutions of Ordinary Differential
Equations—bvp4c 217 5.5.5 Numerical Solutions of Delay Differential
Equations—dde23 231 5.5.6 Numerical Solutions of One-Dimensional Parabolic–Elliptic
Partial Differential Equations—pdepe 233 5.5.7 Local Minimum of a Function—fminbnd 235 5.5.8 Numerical Solutions of Nonlinear Equations—fsolve 238 5.6 Symbolic Solutions and Converting Symbolic Expressions into Functions 240 5.7 Summary of Functions Introduced in Chapter 5 246 Exercises 247

6 2D Graphics

265

Edward B. Magrab

6.1 Introduction: Graphics Management 266 6.2 Basic 2D Plotting Commands 269
6.2.1 Introduction 269 6.2.2 Changing a Graph’s Overall Appearance 281 6.2.3 Special Purpose Graphs 281 6.2.4 Reading, Displaying, and Manipulating Digital Images 288 6.3 Graph Annotation and Enhancement 291 6.3.1 Introduction 291 6.3.2 Axes and Curve Labels, Figure Titles, Legends,
and Text Placement 291 6.3.3 Filling Regions 294 6.3.4 Greek Letters, Mathematical Symbols, Subscripts,
and Superscripts 296 6.3.5 Altering the Attributes of Axes, Curves, Text,
and Legends 299 6.3.6 Positioning One Figure Inside Another Figure 304

Preparing to load PDF file. please wait...

0 of 0
100%
An Engineers Guide to MATLAB