www.TheSolutionManual.com www.TheSolutionManual.com An Engineer’s Guide to MATLAB® www.TheSolutionManual.com This page intentionally left blank www.TheSolutionManual.com 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 www.TheSolutionManual.com 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., 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 www.TheSolutionManual.com For June Coleman Magrab www.TheSolutionManual.com This page intentionally left blank www.TheSolutionManual.com Contents List of Examples Preface to Third Edition Introduction Edward B Magrab 1.1 1.2 1.3 1.4 1.5 2.7 xxi Introduction 1.1.1 Organization of the Book and Its Goals 1.1.2 Some Suggestions on How to Use MATLAB 1.1.3 Book Notation Conventions The MATLAB Environment 1.2.1 Introduction 1.2.2 Preliminaries—Command Window Management 1.2.3 Executing Expressions from the MATLAB Command Window—Basic MATLAB Syntax 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 Online Help 29 The Symbolic Toolbox 32 Summary of Functions Introduced in Chapter 41 Exercises 42 Vectors and Matrices Edward B Magrab 2.1 2.2 2.3 2.4 2.5 2.6 xv 51 Introduction 51 Definitions of Matrices and Vectors 52 Creation of Vectors 53 Creation of Matrices 64 Dot Operations 83 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 Summary of Functions Introduced in Chapter 112 Exercises 113 vii www.TheSolutionManual.com viii Contents Data Input/Output Edward B Magrab 3.1 3.2 3.3 3.4 3.5 3.6 4.3 Strings and Annotated Output 127 3.1.1 Creating Strings 127 3.1.2 Converting Numerical Values to Strings and Displaying Them 130 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 Input/Output Data Files 137 Cell Arrays 141 Input Microsoft Excel Files 143 Summary of Functions Introduced in Chapter 144 Exercises 145 Program Flow Control Edward B Magrab 4.1 4.2 5.2 148 Introduction—The Logical Operator 148 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 Summary of Functions Introduced in Chapter 166 Exercises 167 Function Creation and Selected MATLAB Functions Edward B Magrab 5.1 127 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 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 172 ...www.TheSolutionManual.com An Engineer? ??s Guide to MATLAB? ? www.TheSolutionManual.com This page intentionally left blank www.TheSolutionManual.com An Engineer? ??s Guide to MATLAB? ? With Applications from... 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... Command Window—Basic MATLAB Syntax 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 Online