iii Preface Kermit Sigmon, author of the MATLAB® Primer, passed away in January 1997. Kermit was a friend, colleague, and fellow avid bicyclist (although I’m a mere 10-mile-a- day commuter) with whom I shared an appreciation for the contribution that MATLAB has made to the mathematics, engineering, and scientific community. MATLAB is a powerful tool, and my hope is that in revising our book for MATLAB 7.0, you will be able to learn how to apply it to solving your own challenging problems in mathematics, science, and engineering. A team at The MathWorks, Inc. revised the Fifth Edition for MATLAB Version 5 in November of 1997. I carried on Kermit’s work by creating the Sixth Edition of this book for MATLAB 6.1 in October 2001, and now this Seventh Edition for MATLAB Version 7.0. This edition highlights the many new features of MATLAB 7.0, and includes new chapters on features that were in prior versions of MATLAB but not in prior editions of this book. New or revised topics in this edition include: • calling Java from MATLAB, and using Java objects inside the MATLAB workspace • many more graphics examples, including the seashell on the cover of the book • cell publishing for reports in HTML, LaTeX, Microsoft Word, and Microsoft Powerpoint • powerful suite of code development tools (such as the M-Lint code checker, the file dependency and comparison reports, and a profile coverage report) iv • volume and vector visualization • calling Fortran code from MATLAB • parametric curves and surfaces, and polar plots of symbolic functions • polynomials, interpolation, and numeric integration • solving non-linear equations with fzero • solving ordinary differential equations with ode45 • the revised MATLAB Desktop • short-circuit logical operators • integers and single precision floating-point • more details on the colon operator • linsolve , for solving specific linear systems • the new block comment syntax • function handles ( @ ), which are now simpler to use • anonymous functions • image , and a pretty Mandelbrot set example • the new 4-output sparse lu • abstract symbolic functions • nicely-formatted tables using fprintf • a revised list of all primary functions and operators in MATLAB. I would like to thank Penny Anderson at The MathWorks, Inc. for her detailed review of this book. Tim Davis Associate Professor, Department of Computer and Information Science and Engineering, University of Florida, http://www.cise.ufl.edu/research/sparse v Introduction MATLAB®, developed by The MathWorks, Inc., integrates computation, visualization, and programming in a flexible, open environment. It offers engineers, scientists, and mathematicians an intuitive language for expressing problems and their solutions mathematically and graphically. Complex numeric and symbolic problems can be solved in a fraction of the time required with a programming language such as C, Fortran, or Java. How to use this book: The purpose of this Primer is to help you begin to use MATLAB. It is not intended to be a substitute for the online help facility or the MATLAB documentation (such as Getting Started with MATLAB, available in printed form and online). The Primer can best be used hands-on. You are encouraged to work at the computer as you read the Primer and freely experiment with the examples. This Primer, along with the online help facility, usually suffices for students in a class requiring the use of MATLAB. Start with the examples at the beginning of each chapter. In this way, you will create all of the matrices and M-files used in the examples. Some examples depend on code you write in previous chapters. Larger examples (M-files and MEX-files) are on the web at http://www.cise.ufl.edu/research/sparse/MATLAB and http://www.crcpress.com. Pull-down menu selections are described using the following style. Selecting the Desktop menu, and then the Desktop Layout submenu, and then the Default vi menu item is written as Desktop ► Desktop Layout ► Default . You should liberally use the online help facility for more detailed information. Pressing the F1 key or selecting Help ► MATLAB Help brings up the Help window. You can also type help or doc in the Command window. See Sections 2.1 or 22.26 for more information on how to use the online help. How to obtain MATLAB: Version 7.0 (Release 14) of MATLAB is available for Microsoft Windows (XP, 2000, and NT 4.0), Unix (Linux, Solaris 2.8 and 2.9, and HP- UX 11 or 11i), and the Macintosh (OS X 10.3.2 Panther). A Student Version is available for all but Solaris and HP- UX; it includes MATLAB, Simulink, and key functions of the Symbolic Math Toolbox. Everything discussed in this book can be done in the Student Version of MATLAB, with the exception of advanced features of the Symbolic Math Toolbox discussed in Section 16.13. MATLAB, Simulink, Handle Graphics, StateFlow, and Real-Time Workshop are registered trademarks of The MathWorks, Inc. TargetBox is a trademark of The MathWorks, Inc. For more information on MATLAB, contact: The MathWorks, Inc. 3 Apple Hill Drive Natick, MA, 01760-2098 USA Phone: 508–647–7000 Fax: 508–647–7101 Web: http://www.mathworks.com . bicyclist (although I’m a mere 10-mile-a- day commuter) with whom I shared an appreciation for the contribution that MATLAB has made to the mathematics,. revised the Fifth Edition for MATLAB Version 5 in November of 1997. I carried on Kermit’s work by creating the Sixth Edition of this book for MATLAB 6.1 in