Preface xvii Selectable menu items(from the menu bars in the MATLAB Desktop,figure windows,etc.)are typeset in a boldface font.Submenu items are separated from menu items by a colon,as in File:Open....Labels such as the names of windows and buttons are quoted,in a "regular"font.File and folder names, as well as Web addresses,are printed in a typewriter font.Finally,names of keys on your computer keyboard are set in a sMALL CAPs font. We use four special symbols throughout the book.Here they are together with their meanings. Paragraphs like this one contain cross-references to other parts of the book or suggestions of where you can skip ahead to another chapter. Paragraphs like this one contain important notes.Our favorite is "Save your work frequently."Pay careful attention to these paragraphs. Paragraphs like this one contain useful tips or point out features of interest in the surrounding landscape.You might not need to think carefully about them on the first reading,but they may draw your attention to some of the finer points of MATLAB if you go back to them later. Paragraphs like this discuss features of MATLAB's Symbolic Math Toolbox,used for symbolic (as opposed to numerical)calculations.If you are not using the Symbolic Math Toolbox,you can skip these sections. Incidentally,if you are a student and you have purchased the MATLAB Student Version,then the Symbolic Math Toolbox and SIMULINK are auto- matically included with your software,along with basic MATLAB.Caution: The Student Edition of MATLAB,a different product,does not come with SIMULINK. About the Authors We are mathematics professors at the University of Maryland,College Park. We have used MATLAB in our research,in our mathematics courses,for pre- sentations and demonstrations,for production of graphics for books and for the Web,and even to help our kids do their homework.We hope that you'll find MATLAB as useful as we do and that this book will help you learn to use it quickly and effectively.Finally,we would like to thank our editor,Alan Harvey,for his personal attention and helpful suggestions
Preface xvii Selectable menu items (from the menu bars in the MATLAB Desktop, figure windows, etc.) are typeset in a boldface font. Submenu items are separated from menu items by a colon, as in File : Open.... Labels suchas the names of windows and buttons are quoted, in a “regular” font. File and folder names, as well as Web addresses, are printed in a typewriter font. Finally, names of keys on your computer keyboard are set in a SMALL CAPS font. We use four special symbols throughout the book. Here they are together withtheir meanings. ☞ Paragraphs like this one contain cross-references to other parts of the book or suggestions of where you can skip ahead to another chapter. ➱ Paragraphs like this one contain important notes. Our favorite is “Save your work frequently.” Pay careful attention to these paragraphs. ✓ Paragraphs like this one contain useful tips or point out features of interest in the surrounding landscape. You might not need to think carefully about them on the first reading, but they may draw your attention to some of the finer points of MATLAB if you go back to them later. Paragraphs like this discuss features of MATLAB’s Symbolic Math Toolbox, used for symbolic (as opposed to numerical) calculations. If you are not using the Symbolic Math Toolbox, you can skip these sections. Incidentally, if you are a student and you have purchased the MATLAB Student Version, then the Symbolic Math Toolbox and SIMULINK are automatically included withyour software, along withbasic MATLAB. Caution: The Student Edition of MATLAB, a different product, does not come with SIMULINK. About the Authors We are mathematics professors at the University of Maryland, College Park. We have used MATLAB in our research, in our mathematics courses, for presentations and demonstrations, for production of graphics for books and for the Web, and even to help our kids do their homework. We hope that you’ll find MATLAB as useful as we do and that this book will help you learn to use it quickly and effectively. Finally, we would like to thank our editor, Alan Harvey, for his personal attention and helpful suggestions
Chapter 1 Getting Started In this chapter,we will introduce you to the tools you need to begin using MATLAB effectively.These include:some relevant information on computer platforms and software versions;installation and location protocols;how to launch the program,enter commands,use online help,and recover from hang- ups;a roster of MATLAB's various windows;and finally,how to quit the soft- ware.We know you are anxious to get started using MATLAB,so we will keep this chapter brief.After you complete it,you can go immediately to Chapter 2 to find concrete and simple instructions for the use of MATLAB.We describe the MATLAB interface more elaborately in Chapter 3. Platforms and Versions It is likely that you will run MATLAB on a PC (running Windows or Linux) or on some form of UNIX operating system.(The developers of MATLAB, The MathWorks,Inc.,are no longer supporting Macintosh.Earlier versions of MATLAB were available for Macintosh;if you are running one of those,you should find that our instructions for Windows platforms will suffice for your needs.)Unlike previous versions of MATLAB,version 6 looks virtually identi- cal on Windows and UNIX platforms.For definitiveness,we shall assume the reader is using a PC in a Windows environment.In those very few instances where our instructions must be tailored differently for Linux or UNIX users, we shall point it out clearly. We use the word Windows to refer to all flavors of the Windows operating system,that is,Windows 95,Windows 98,Windows 2000, Windows Millennium Edition,and Windows NT. 1
Chapter 1 Getting Started In this chapter, we will introduce you to the tools you need to begin using MATLAB effectively. These include: some relevant information on computer platforms and software versions; installation and location protocols; how to launch the program, enter commands, use online help, and recover from hangups; a roster of MATLAB’s various windows; and finally, how to quit the software. We know you are anxious to get started using MATLAB, so we will keep this chapter brief. After you complete it, you can go immediately to Chapter 2 to find concrete and simple instructions for the use of MATLAB. We describe the MATLAB interface more elaborately in Chapter 3. Platforms and Versions It is likely that you will run MATLAB on a PC (running Windows or Linux) or on some form of UNIX operating system. (The developers of MATLAB, The MathWorks, Inc., are no longer supporting Macintosh. Earlier versions of MATLAB were available for Macintosh; if you are running one of those, you should find that our instructions for Windows platforms will suffice for your needs.) Unlike previous versions of MATLAB, version 6 looks virtually identical on Windows and UNIX platforms. For definitiveness, we shall assume the reader is using a PC in a Windows environment. In those very few instances where our instructions must be tailored differently for Linux or UNIX users, we shall point it out clearly. ➱ We use the word Windows to refer to all flavors of the Windows operating system, that is, Windows 95, Windows 98, Windows 2000, Windows Millennium Edition, and Windows NT. 1
2 Chapter 1:Getting Started This book is written to be compatible with the current version of MATLAB, namely version 6(also known as Release 12).The vast majority of the MATLAB commands we describe,as well as many features of the MATLAB interface (M-files,diary files,M-books,etc.),are valid for version 5.3(Release 11),and even earlier versions in some cases.We also note that the differences between the Professional Version and the Student Version(not the Student Edition) of MATLAB are rather minor and virtually unnoticeable to the new,or even mid-level,user.Again,in the few instances where we describe a MATLAB feature that is only available in the Professional Version,we highlight that fact clearly. Installation and Location If you intend to run MATLAB on a PC,especially the Student Version,it is quite possible that you will have to install it yourself.You can easily accomplish this using the product CDs.Follow the installation instructions as you would with any new software you install.At some point in the installation you may be asked which toolboxes you wish to include in your installation.Unless you have severe space limitations,we suggest that you install any that seem of interest to you or that you think you might use at some point in the future.We ask only that you be sure to include the Symbolic Math Toolbox among those you install.If possible,we also encourage you to install SIMULINK,which is described in Chapter 8. Depending on your version you may also be asked whether you want to specify certain directory (i.e.,folder)locations associated with Microsoft Word. If you do,you will be able to run the M-book interface that is described in Chapter 6.If your computer has Microsoft Word,we strongly urge you to include these directory locations during installation. If you allow the default settings during installation,then MATLAB will likely be found in a directory with a name such as matlabR12 or matlab-SR12 or MATLAB-you may have to hunt around to find it.The subdirectory bin\win32,or perhaps the subdirectory bin,will contain the executable file matlab.exe that runs the program,while the current working directory will probably be set to matlabR12\work. Starting MATLAB You start MATLAB as you would any other software application.On a PC you access it via the Start menu,in Programs under a folder such as MatlabR12
2 Chapter 1: Getting Started This book is written to be compatible with the current version of MATLAB, namely version 6 (also known as Release 12). The vast majority of the MATLAB commands we describe, as well as many features of the MATLAB interface (M-files, diary files, M-books, etc.), are valid for version 5.3 (Release 11), and even earlier versions in some cases. We also note that the differences between the Professional Version and the Student Version (not the Student Edition) of MATLAB are rather minor and virtually unnoticeable to the new, or even mid-level, user. Again, in the few instances where we describe a MATLAB feature that is only available in the Professional Version, we highlight that fact clearly. Installation and Location If you intend to run MATLAB on a PC, especially the Student Version, it is quite possible that you will have to install it yourself. You can easily accomplish this using the product CDs. Follow the installation instructions as you would withany new software you install. At some point in the installation you may be asked which toolboxes you wishto include in your installation. Unless you have severe space limitations, we suggest that you install any that seem of interest to you or that you think you might use at some point in the future. We ask only that you be sure to include the Symbolic Math Toolbox among those you install. If possible, we also encourage you to install SIMULINK, which is described in Chapter 8. Depending on your version you may also be asked whether you want to specify certain directory (i.e., folder) locations associated withMicrosoft Word. If you do, you will be able to run the M-book interface that is described in Chapter 6. If your computer has Microsoft Word, we strongly urge you to include these directory locations during installation. If you allow the default settings during installation, then MATLAB will likely be found in a directory witha name suchas matlabR12 or matlab SR12 or MATLAB — you may have to hunt around to find it. The subdirectory bin\win32, or perhaps the subdirectory bin, will contain the executable file matlab.exe that runs the program, while the current working directory will probably be set to matlabR12\work. Starting MATLAB You start MATLAB as you would any other software application. On a PC you access it via the Start menu, in Programs under a folder suchas MatlabR12
Typing in the Command Window 3 or Student MATLAB.Alternatively,you may have an icon set up that enables you to start MATLAB with a simple double-click.On a UNIX machine,gen- erally you need only type matlab in a terminal window,though you may first have to find the matlab/bin directory and add it to your path.Or you may have an icon or a special button on your desktop that achieves the task. On UNIX systems,you should not attempt to run MATLAB in the background by typing matlab&.This will fail in either the current or older versions. However you start MATLAB,you will briefly see a window that displays the MATLAB logo as well as some MATLAB product information,and then a MATLAB Desktop window will launch.That window will contain a title bar,a menu bar,a tool bar,and five embedded windows,two of which are hidden.The largest and most important window is the Command Window on the right.We will go into more detail in Chapter 3 on the use and manipulation of the other four windows:the Launch Pad,the Workspace browser,the Command History window,and the Current Directory browser.For now we concentrate on the Command Window to get you started issuing MATLAB commands as quickly as possible.At the top of the Command Window,you may see some general information about MATLAB,perhaps some special instructions for getting started or accessing help,but most important of all,a line that contains a prompt.The prompt will likely be a double caret (>or >)If the Command Window is"active",its title bar will be dark,and the prompt will be followed by a cursor(a vertical line or box,usually blinking).That is the place where you will enter your MATLAB commands(see Chapter 2).If the Command Window is not active,just click in it anywhere.Figure 1-1 contains an example of a newly launched MATLAB Desktop. In older versions of MATLAB,for example 5.3,there is no integrated Desktop.Only the Command Window appears when you launch the application.(On UNIX systems,the terminal window from which you invoke MATLAB becomes the Command Window.)Commands that we instruct you to enter in the Command Window inside the Desktop for version 6 can be entered directly into the Command Window in version 5.3 and older versions. Typing in the Command Window Click in the Command Window to make it active.When a window becomes active,its titlebar darkens.It is also likely that your cursor will change from
Typing in the Command Window 3 or Student MATLAB. Alternatively, you may have an icon set up that enables you to start MATLAB witha simple double-click. On a UNIX machine, generally you need only type matlab in a terminal window, though you may first have to find the matlab/bin directory and add it to your path. Or you may have an icon or a special button on your desktop that achieves the task. ➱ On UNIX systems, you should not attempt to run MATLAB in the background by typing matlab &. This will fail in either the current or older versions. However you start MATLAB, you will briefly see a window that displays the MATLAB logo as well as some MATLAB product information, and then a MATLABDesktop window will launch. That window will contain a title bar, a menu bar, a tool bar, and five embedded windows, two of which are hidden. The largest and most important window is the Command Window on the right. We will go into more detail in Chapter 3 on the use and manipulation of the other four windows: the Launch Pad, th e Workspace browser, th e Command History window, and the Current Directory browser. For now we concentrate on the Command Window to get you started issuing MATLAB commands as quickly as possible. At the top of the Command Window, you may see some general information about MATLAB, perhaps some special instructions for getting started or accessing help, but most important of all, a line that contains a prompt. The prompt will likely be a double caret (>> or ). If the Command Window is “active”, its title bar will be dark, and the prompt will be followed by a cursor (a vertical line or box, usually blinking). That is the place where you will enter your MATLAB commands (see Chapter 2). If the Command Window is not active, just click in it anywhere. Figure 1-1 contains an example of a newly launched MATLAB Desktop. ➱ In older versions of MATLAB, for example 5.3, there is no integrated Desktop. Only the Command Window appears when you launch the application. (On UNIX systems, the terminal window from which you invoke MATLAB becomes the Command Window.) Commands that we instruct you to enter in the Command Window inside the Desktop for version 6 can be entered directly into the Command Window in version 5.3 and older versions. Typing in the Command Window Click in the Command Window to make it active. When a window becomes active, its titlebar darkens. It is also likely that your cursor will change from
4 Chapter 1:Getting Started Launch rat wertagse Csmreand Hictory Ouere Cimieny Figure 1-1:A MATLAB Desktop. outline form to solid,or from light to dark,or it may simply appear.Now you can begin entering commands.Try typing 1+1;then press ENTER or RETURN. Next try factor(123456789),and finally sin(10).Your MATLAB Desktop should look like Figure 1-2. Online Help MATLAB has an extensive online help mechanism.In fact,using only this book and the online help,you should be able to become quite proficient with MATLAB. You can access the online help in one of several ways.Typing help at the command prompt will reveal a long list oftopics on which help is available.Just to illustrate,try typing help general.Now you see a long list of "general purpose"MATLAB commands.Finally,try help solve to learn about the command solve.In every instance above,more information than your screen can hold will scroll by.See the Online Help section in Chapter 2 for instructions to deal with this. There is a much more user-friendly way to access the online help,namely via the MATLAB Help Browser.You can activate it in several ways;for example, typing either helpwin or helpdesk at the command prompt brings it up
4 Chapter 1: Getting Started Figure 1-1: A MATLAB Desktop. outline form to solid, or from light to dark, or it may simply appear. Now you can begin entering commands. Try typing 1+1; then press ENTER or RETURN. Next try factor(123456789), and finally sin(10). Your MATLAB Desktop should look like Figure 1-2. Online Help MATLAB has an extensive online help mechanism. In fact, using only this book and the online help, you should be able to become quite proficient with MATLAB. You can access the online help in one of several ways. Typing help at the command prompt will reveal a long list of topics on which help is available. Just to illustrate, try typing help general. Now you see a long list of “general purpose” MATLAB commands. Finally, try help solve to learn about the command solve. In every instance above, more information than your screen can hold will scroll by. See the Online Help section in Chapter 2 for instructions to deal withthis. There is a much more user-friendly way to access the online help, namely via the MATLAB Help Browser. You can activate it in several ways; for example, typing either helpwin or helpdesk at the command prompt brings it up