




























































































Estude fácil! Tem muito documento disponível na Docsity
Ganhe pontos ajudando outros esrudantes ou compre um plano Premium
Esta página não é visível na pré-visualização
Não perca as partes importantes!





























































































Rochester Institute of Technology
A JOHN WILEY & SONS, INC., PUBLICATION
Copyright 0 2003 by John Wiley & Sons, Inc. All rights reserved
Published by John Wiley & Sons, Inc., Hoboken, New Jersey. Published simultaneously in Canada.
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, scanning or otherwise, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 750-4470, or on the web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 11 1 River Street, Hoboken, NJ 07030, (201) 748-601 I , fax (201) 748- 6008, e-mail: [email protected].
Limit ofLiability/Disclaimer of Warranty: While the publisher and author have used their best efforts in preparing this book, they make no representation or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a particular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable foi- your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss ofprofit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages.
For general information on our other products and services please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 3 17-572-3993 or fax 3 17-572-4002.
Wiley also publishes its hooks in a variety of electronic formats. Some content that appears in print, however, may not be available in electronic format.
Library of Congress Cataloging-in-Publication Data is availablr.
lSBN 0-47 1-46200-
Printed in the United States of America
10 9 8 7 6 5 4 3 2
1.
2.
4.
5.
1.1. Introduction 1.2. MATLABStart 1.3. MATLABHelp and Demo References
2.1. Mathematical Functions 2.2. MATLABCharacters and Operators 2.3. MATLAB Commands References
3.1. Starting MATLAB 3.2. Basic Arithmetic
3.3.1. 3.3.2. Matrices and Basic Operations with Matrices
Scalars and Basic Operations with Scalars Arrays, Vectors, and Basic Operations 3.4. 3.5. Conditions and Loops 3.6. Illustrative Examples References
4.1. Plotting 4.2. Two- and Three-Dimensional Graphics 4.3. Illustrative Examples References
5.1.
5.2.
Solution of Differential Equations and Dynamic Systems Fundamentals Mathematical Model Developments and MATLAB Amlications
1 1 5 9 26
27 27 31 32 41
42 42 42 49 50 51 53 13 80 98
99 113 125 132
133
133
141
V
I would like to welcome the reader to this MATLAB@ book, which is the companion to the high-performance MATLAB environment and outstanding Mathworks users manuals. I sincerely feel that I have written a very practical problem-solving type of book that provides a synergetic, informa- tive, and entertaining learning experience. Having used MATLAB for almost 20 years, I have been challenged to write a coherent book that assist readers in discovering MATLABfrom its power and ef- ficiency to its advantages and superiority. Many books and outstanding MATLAB reference manuals are available. The Mathworks user manuals provide an excellent collection of the MATLABfeatures
ment for students. Having used the referenced manuals and books with different levels of user and student satisfaction, accomplishment, and success, the critical need to write a focused (companion) book became evident. This is the reason that 1 have embarked upon project. This book, in addition to being an excellent companion and self-study textbook, can be used in science and engineering courses in MATLABas well as a complementary book. In addition to cov- ering MATLAB,the author has strived to build and develop engineering and scientific competence, presenting the material visually, numerically, and analytically.Visualization, numerical and analytical delivery features, fully supported by the MATLABenvironment, are documented and emphasized in this book. Real-world examples and problems introduce, motivate, and illustrate the application of MATLAB. MATLAB books and user manuals have been written, published, and distributed. Unfortunate- ly, the MATLAB environment is usually introduced in the introductory freshman (or sophomore) course with very limited time allocated to cover MATLABduring the allocated modules. This does not allow the instructors to comprehensively cover MATLAB,and inclusive books which cover the materi- al in details and depth cannot be effectively used. Furthermore, there are many engineers and scien- tists who did not have the chance to study MATLAB at colleges, but would like to master it in the every-day practice MATLABenvironment. Therefore, this book covers introductory example-oriented problems. This book is written with the ultimate goal of offering a far-reaching, high-quality, stand- alone and companion-type user-friendly educational textbook which can be efficiently used in intro- ductory MATLAB courses in undergraduate/graduatecourses or course modules, and as a self-study or supplementary book. There are increasing demands for further development in high-performance computing envi- ronments, and hundreds of high-level languages exist including C, FORTRAN, PASCAL, etc. This book covers the MATLAB environment, which is uniquely suited to perform heterogeneous simula- tions, data-intensive analysis, optimization, modeling, code generation, visualization, etc. These fea- tures are extremely important in engineering, science, and technology. To avoid possible obstacles, the material is presented in sufficient detail. MATLABbasics are covered to help the reader to fully un- derstand, appreciate, apply, and develop the skills and confidence to work in the MATLAB environ- ment. A wide range of worked-out examples and qualitative illustrations, which are treated in depth, bridge the gap between theoretical knowledge and practice. Step-by-step, Engineering and Scientijk Computations Using MATLAB guides the reader through the most important aspects and basics in
vii
V l l l ... Preface
MATLABprogramming and problem-solving: form fundamentals to applications. In this book, many practical real-world problems and examples are solved in MATLAB,which promotes enormous gains in productivity and creativity. Analysis (analytical and numerical) and simulation are critical and urgently important as- pects in design, optimization, development and prototyping of different systems, e.g., from living or- ganisms and systems to man-made devices and systems. This book illustrates that MATLABcan be ef- ficiently used to speed up analysis and design, facilitate enormous gains in productivity and creativity, generate real-time C code, and visualize the results. MATLABis a computational environ- ment that integrates a great number of toolboxes (e.g., SIMULINK~,Real-Time Workshop, Optimiza- tion, Signal Processing, Symbolic Math, etc.). A flexible high-performance simulation, analysis, and design environment, MATLABhas become a standard cost-effective tool within the engineering, sci- ence, and technology communities. The book demonstrates the MATLABcapabilities and helps one to master this user-friendly environment in order to attack and solve distinct problems of different com- plexity. The application of MATLABincreases designer productivity and shows how to use the ad- vanced software. The MATLABenvironment offers a rich set of capabilities to efficiently solve a vari- ety of complex analysis, simulation, and optimization problems that require high-level language, robust numeric computations, interactive graphical user interface (GUI), interoperability, data visual- ization capabilities, etc. The MATLABfiles, scripts, statements, and SIMULINKmodels that are docu- mented in the book can be easily modified to study application-specific problems encountered in practice. A wide spectrum of practical real-world problems are simulated and analyzed in this book. A variety of complex systems described by nonlinear differential equations are thoroughly studied, and SIMULINKdiagrams to simulate dynamic systems and numerical results are reported. Users can easily apply these results as well as develop new MATLABfiles and SIMULINKblock diagrams using the enterprise-wide practical examples. The developed scripts and models are easily assessed, and can be straightforwardly modified. The major objectives of this readable and user-friendly book are to establish in students, en- gineers, and scientists confidence in their ability to apply advanced concepts, enhance learning, im- prove problem-solving abilities, as well as to provide a gradual progression from versatile theoretical to practical topics in order to effectively apply MATLABaccomplishing the desired objectives and milestones. This book is written for engineers, scientists and students interested in the application of the MATLABenvironment to solve real-world problems. Students and engineers are not primarily in- terested in theoretical encyclopedic studies, and engineering and scientific results need to be covered and demonstrated. This book presents well-defined MATLABbasics with step-by-step instructions on how to apply the results by thoroughly studying and solving a great number of practical real-world problems and examples. These worked-out examples prepare one to effectively use the MATLABenvi- ronment in practice.
Wiley FTP Web Site For more information on this book and for the MATLABfiles and SIMULINKdiagrams please visit the following site ftp://ftp.wiley.com/public/sci-tech-med/matlab/.
Acknowledgments Many people contributed to this book. First thanks go to my beloved family - my father Ed- ward, mother Adel, wife Marina, daughter Lydia, and son Alexander. I would like to express my sin- cere acknowledgments to many colleagues and students. It gives me great pleasure to acknowledge the help I received from many people in the preparation of this book. The outstanding John Wiley & Sons team assisted me by providing valuable and deeply treasured feedback. Many thanks to Math- Works, Inc. for supplying the MATLABenvironment and encouraging this project.
ABOUTTHE AUTHOR
Sergey Edward Lyshevski was born in Kiev, Ukraine. He received M.S. (1980) and Ph.D. (1987) de- grees from Kiev Polytechnic Institute, both in Electrical Engineering. From 1980 to 1993 Dr. Ly- shevski held faculty positions at the Department of Electrical Engineering at Kiev Polytechnic Insti- tute and the Academy of Sciences of Ukraine. From 1989 to 1993 he was the Microelectronic and Electromechanical Systems Division Head at the Academy of Sciences of Ukraine. From 1993 to 2002 he was with Purdue School of Engineering as an Associate Professor of Electrical and Comput- er Engineering. In 2002, Dr. Lyshevski joined Rochester Institute of Technology as a professor of Electrical Engineering, professor of Microsystems Engineering, and Gleason Chair. Dr. Lyshevski serves as the Senior Faculty Fellow at the US Surface and Undersea Naval Warfare Centers. He is the author of 8 books (including Nano- and Micro-Electromechanical Sys- tems: Fundamentals of Micro- and Nanoengineering, CRC Press, 2000; MEMS and NEMS: Systems, Devices, and Structures, CRC Press, 2002), and author and co-author of more than 250 journal arti- cles, handbook chapters, and regular conference papers. His current teaching and research activities are in the areas of MEMS and NEMS (CAD, design, high-fidelity modeling, data-intensive analysis, heterogeneous simulation, fabrication), micro- and nanoengineering, intelligent large-scale mi- crosystems, learning configurations, novel architectures, self-organization, micro- and nanoscale de- vices (actuators, sensors, logics, switches, memories, etc.), nanocomputers and their components, re- configureable (adaptive) defect-tolerant computer architectures, systems informatics, etc. Dr. Lyshevski has made significant contribution in design, application, verification, and implementation of advanced aerospace, automotive, electromechanical, and naval systems. Dr. Lyshevski made 29 invited presentations (nationally and internationally). He serves as the CRC Books Series Editor in Nano- and Microscience, Engineering, Technology, and Medicine. Dr. Lyshevski has taught undergraduate and graduate courses in NEMS, MEMS, microsystems, computer architecture, microelectromechanical motion devices, integrated circuits, signals and sys- tems, etc.
X
Chapter I: MATLAB Basics
MATLABBasics
1
I (and probably many engineers and researchers) remember the difficulties that we had solving even simple engineering and scientific problems in the 1970s and 1980s. These problems have been solved through viable mathematical methods and algorithms to simplify and reduce the complexity of problems enhancing the robustness and stability. However, many problems can be approached and sdved only through high-fidelity modeling, heterogeneous simulation, parallel computing, and data-intensive analysis. Even in those days, many used to apply Basic, C , FORTRAN,PL, and Pascal in numerical analysis and simulations. Though I cannot regret the great experience I had exploring many high- performance languages, revolutionary improvements were made in the middle 1980s with the development of the meaningful high-performance application-specific software environments (e.g., MATEMATICA, MATLAB@: MATRIX^, etc.). These developments, which date back at least to the mid 1960s when FORTRANand other languages were used to develop the application-specific toolboxes, were partially unsuccessful due to limited software capabilities, flexibility, and straightforwardness. MATLAB, introduced in the middle 198Os, is one of the most important and profound advances in computational and applied engineering and science. MATLAB (MATrix LABoratory) is a high-performance interacting data-intensive software environment for high-efficiency engineering and scientific numerical calculations [ 11. Applications include: heterogeneous simulations and data-intensive analysis of very complex systems and signals, comprehensive matrix and arrays manipulations in numerical analysis, finding roots of polynomials, two- and three-dimensional plotting and graphics for different coordinate systems, integration and differentiation, signal processing, control, identification, symbolic calculus, optimization, etc. The goal of MATLABis to enable the users to solve a wide spectrum of analytical and numerical problems using matrix-based methods, attain excellent interfacing and interactive capabilities, compile with high-level programming languages, ensure robustness in data-intensive analysis and heterogeneous simulations, provide easy access to and straightforward implementation of state-of-the-art numerical algorithms, guarantee powerful graphical features, etc. Due to high flexibility and versatility, the MATLAB environment has been significantly enhanced and developed during recent years. This provides users with advanced cutting-edge algorithms, enormous data-handling abilities, and powerful programming tools. MATLAB is based on a high-level matridarray language with control flow statements, functions, data structures, input/output, and object-oriented programming features. MATLABwas originally developed to provide easy access to matrix software developed by the LINPACKand EISPACKmatrix computation software. MATLAB has evolved over the last 20 years and become the standard instructional tool for introductory and advanced courses in science, engineering, and technology. The MATLAB environment allows one to integrate user-friendly tools with superior computational capabilities. As a result, MATLABis one of the most useful tools for scientific and engineering calculations and computing. Users practice and appreciate the MATLABenvironment interactively, enjoy the flexibility and completeness, analyze and verify the results by applying the range of build-in commands and functions, expand MATLABby developing their own application-specific files, etc. Users quickly access data files, programs, and graphics using MATLABhelp. A family of application-specific toolboxes, with a specialized collection of m-files for solving problems commonly encountered in practice, ensures comprehensiveness and effectiveness. SIMULINKis a companion graphical mouse-driven interactive environment enhancing MATLAB. SIMULINK@ is used for simulating linear and nonlinear continuous- and discrete-time dynamic systems. The MATLABfeatures are illustrated in Figure 1.1.
Chapter I : MATLAB Basics
The mat 1 ab subfolders have 18 MATLABuser manuals as reported in Figure 1.3.
3
Figure 1.3. MATLABuser manuals in the mat 1 ab subfolder
These user manuals can be accessed and printed using the Adobe Acrobat Reader. Correspondingly, this book does not attempt to rewrite these available thousand-page MATLAB user manuals. For example, the outstanding MATLAB The Language of Technical Computing manual, available as the ml.pdf file, consists of 1 188 pages. The front page of the MATLAB The Language of Technical Computing user manual is shown in Figure 1.4.
The Language of Technical Cornputin;
Compubtm 1
Using M. A W NathWrks
Figure 1.4. Front page of the MATLAB The Language of Technical Computing user manual
I’ersion 6
Chapter I: MATLAB Basics 4
This book focuses on MATLABapplications and educates the reader on how to solve practical problems using step-by-step instructions. The MATLABenvironment consists of the following five major ingredients: (1) MATLAB Language, (2) MATLABWorking Environment, (3) Handle Graphics@, (4) MATLABMathematical Function Library, and ( 5 ) MATLABApplication Program Interface. The MATLABLanguage is a high-level matridarray language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows the user to program in the small (creating throw-away programs) and program in the large (creating complete large and complex application-specific programs). The MATLABWorking Environment is a set of tools and facilities. It includes facilities for managing the variables in workspace, manipulation of variables and data, importing and exporting data, etc. Tools for developing, managing, debugging, and profiling m-files for different applications are available. Handle Graphics is the MATLABgraphics system. It includes high-level commands for two- and three-dimensional data visualization, image processing, animation, and presentation. It also includes low- level commands that allow the user to fully customize the appearance of graphics and build complete graphical user interfaces (GUIs). The MATLABMathematical Function Library is a collection of computationally efficient and robust algorithms and functions ranging from elementary functions (sine, cosine, tangent, cotangent, etc.) to specialized functions (eigenvalues, Bessel functions, Fourier and Laplace transforms, etc.) commonly used in scientific and engineering practice. The MATLABApplication Program Interface (API) is a library that allows the user to write C and FORTRANprograms that interact within the MATLABenvironment. It includes facilities for calling routines from MATLAB(dynamic linking), calling MATLABfor computing and processing, reading and writing m-files, etc. Real-Time Workshop@allows the user to generate C code from block diagrams and to run it for real-time systems. MATLAB 6.5 is supported by the following platforms: Microsoft Windows, Windows Millennium, Windows NT, Compaq Alpha, Linux, SGI, and Sun Solaris. In this introduction, before giving in the MATLABdescription, the application of MATLABshould be justified through familiar examples. This will provide the reasoning for MATLABapplications. This book is intended as an introductory MATLABtextbook though advanced application-specific problems are solved to illustrate the applicability and versatility of the MATLAB environment. Therefore familiar examples will be covered. In multivariable calculus, students study parametric and polar equations, vectors, coordinate systems (Cartesian, cylindrical, and spherical), vector-valued functions, derivatives, partial derivatives, directional derivatives, gradient, optimization problems, multiple integration, integration in vector fields, and other topics. In contrast, linear algebra emphasizes matrix techniques for solving systems of linear and nonlinear equations covering matrices and operations with matrices, determinants, vector spaces, independent and dependent sets of vectors, bases for vector spaces, linear transformations, eigenvalues and eigenvectors, orthogonal sets, least squares approximation, interpolation, etc. The MATLABenvironment is uniquely suitable to solving a variety of problems in engineering and science. Using the calculus and physics background, a variety of real-world engineering problems can be attacked and resolved. This book illustrates the application of MATLABin order to solve of this class of problems. MATLABintegrates computation, visualization, and programming in an easy-to-use systematic, robust and computationally efficient environment where problems and solutions are expressed in familiar (commonly used) mathematical notation. The user can perform mathematic computation, algorithm development, simulation, prototyping, data analysis, visualization, interactive graphics, and application- specific developments including graphical user interface features. In MATLAB,the data is manipulated in the array form, allowing the user to solve complex problems. It was emphasized that the MATLAB environment was originally developed using data-intensive matrix computation methods.
Chapter I : MATLAB Basics 6
Figure 1.5. MATLAB 6.5 Command and Workspace windows
For all MATLAB versions, the line
in the Command Window. After each MATLAB command, the Enter (Return) key must be pressed. One interacts with MATLAB using the Command Window. The MATLAB prompt >> is displayed in the Command Window, and a blinking cursor appears to the right of the prompt when the Command Window is active. Typing ver, we have the information regarding the MATLAB version and the MATLABtoolboxes that are available (see Figure 1.6 for MATLAB versions 6.5,6.1, and 6.0).
Chapter I: MTUB Basics^7
Figure 1.6.MATLAB6.5,6.1, and 6.0 Command Window (MATLAB toolboxes are listed)
MATLABCommand Window. The MATLAB Command Window is where the user interacts with MATLAB. We illustrate the MATLAB application through a simple example. To find the sum l t 2 type