Interrupting Calculations 5 0 44 Eaceor(129456789) .544 t4268e12456189 Figure 1-2:Some Simple Commands. Alternatively,it is available through the menu bar under either View or Help. Finally,the question mark button on the tool bar will also invoke the Help Browser.We will go into more detail on its features in Chapter 2-suffice it to say that as in any hypertext browser,you can,by clicking,browse through a host of command and interface information.Figure 1-3 depicts the MATLAB Help Browser. If you are working with MATLAB version 5.3 or earlier,then typing help,help general,or help solve at the command prompt will work as indicated above.But the entries helpwin or helpdesk call up more primitive,although still quite useful,forms of help windows than the robust Help Browser available with version 6. If you are patient,and not overly anxious to get to Chapter 2,you can type demo to try out MATLAB's demonstration program for beginners. Interrupting Calculations If MATLAB is hung up in a calculation,or is just taking too long to perform an operation,you can usually abort it by typing CTRL+C(that is,hold down the key labeled CTRL,or CONTROL,and press c)
Interrupting Calculations 5 Figure 1-2: Some Simple Commands. Alternatively, it is available through the menu bar under either View or Help. Finally, the question mark button on the tool bar will also invoke the Help Browser. We will go into more detail on its features in Chapter 2 — suffice it to say that as in any hypertext browser, you can, by clicking, browse through a host of command and interface information. Figure 1-3 depicts the MATLAB Help Browser. ➱ If you are working with MATLAB version 5.3 or earlier, then typing help, help general, or help solve at the command prompt will work as indicated above. But the entries helpwin or helpdesk call up more primitive, although still quite useful, forms of help windows than the robust Help Browser available with version 6. If you are patient, and not overly anxious to get to Chapter 2, you can type demo to try out MATLAB’s demonstration program for beginners. Interrupting Calculations If MATLAB is hung up in a calculation, or is just taking too long to perform an operation, you can usually abort it by typing CTRL+C (that is, hold down the key labeled CTRL, or CONTROL, and press C)
6 Chapter 1:Getting Started Holp Eile Edit Mow Go Wob Widow Help Helg Na物ta ◆马dng oto分MC56 ctad Sooct- MATLAB Top Page 习A加Foverte R o a d m a p ◆12e1eao8¥oE6a MATLAB ◆T里 中0 etting se南rted 国Learning MATLAB 书动s1时服TL团 登Printab1n0 cuontacs1通(刊 ◆ihMT△B-8ru0e0 MATA8 ●ndax.o1Dacum2 Eamzie反·maior cames in the MATLAB 零igl1nk docemertatan yabolie Math Toolbox Instellation EFinding Functions and Properties ifyou know the funchion rame: Cick Search in the Halp Eroweor'e lat pano SelectFunction Mame tor the bpe of searth Handhe Grppbr:Eraaer Brgwaer.wew descrptona ofal graphks obtert propertes Printing the Documentation Figure 1-3:The MATLAB Help Browser. MATLAB Windows We have already described the MATLAB Command Window and the Help Browser,and have mentioned in passing the Command History window,Cur- rent Directory browser,Workspace browser,and Launch Pad.These,and seve- ral other windows you will encounter as you work with MATLAB,will allow you to:control files and folders that you and MATLAB will need to access;write and edit the small MATLAB programs (that is,M-files)that you will utilize to run MATLAB most effectively;keep track of the variables and functions that you define as you use MATLAB;and design graphical models to solve prob- lems and simulate processes.Some of these windows launch separately,and some are embedded in the Desktop.You can dock some of those that launch separately inside the Desktop(through the View:Dock menu button),or you can separate windows inside your MATLAB Desktop out to your computer desktop by clicking on the curved arrow in the upper right. These features are described more thoroughly in Chapter 3.For now,we want to call your attention to the other main type of window you will en- counter;namely graphics windows.Many of the commands you issue will generate graphics or pictures.These will appear in a separate window.MAT- LAB documentation refers to these as figure windows.In this book,we shall
6 Chapter 1: Getting Started Figure 1-3: The MATLAB Help Browser. MATLAB Windows We have already described the MATLAB Command Window and the Help Browser, and have mentioned in passing the Command History window, Current Directory browser, Workspace browser, and LaunchPad. These, and several other windows you will encounter as you work with MATLAB, will allow you to: control files and folders that you and MATLAB will need to access; write and edit the small MATLAB programs (that is, M-files) that you will utilize to run MATLAB most effectively; keep track of the variables and functions that you define as you use MATLAB; and design graphical models to solve problems and simulate processes. Some of these windows launch separately, and some are embedded in the Desktop. You can dock some of those that launch separately inside the Desktop (through the View:Dock menu button), or you can separate windows inside your MATLAB Desktop out to your computer desktop by clicking on the curved arrow in the upper right. These features are described more thoroughly in Chapter 3. For now, we want to call your attention to the other main type of window you will encounter; namely graphics windows. Many of the commands you issue will generate graphics or pictures. These will appear in a separate window. MATLAB documentation refers to these as figure windows. In this book, we shall
Ending a Session 7 also call them graphics windows.In Chapter 5,we will teach you how to gen- erate and manipulate MATLAB graphics windows most effectively. See Figure 2-1 in Chapter 2 for a simple example of a graphics window. Graphics windows cannot be embedded into the MATLAB Desktop. Ending a Session The simplest way to conclude a MATLAB session is to type quit at the prompt. You can also click on the special symbol that closes your windows(usually an x in the upper left-or right-hand corner).Either of these may or may not close all the other MATLAB windows(which we talked about in the last section)that are open.You may have to close them separately.Indeed,it is our experience that leaving MATLAB-generated windows around after closing the MATLAB Desktop may be hazardous to your operating system.Still another way to exit is to use the Exit MATLAB option from the File menu of the Desktop.Before you exit MATLAB,you should be sure to save any variables,print any graphics or other files you need,and in general clean up after yourself.Some strategies for doing so are addressed in Chapter 3
Ending a Session 7 also call them graphics windows. In Chapter 5, we will teach you how to generate and manipulate MATLAB graphics windows most effectively. ☞ See Figure 2-1 in Chapter 2 for a simple example of a graphics window. ➱ Graphics windows cannot be embedded into the MATLAB Desktop. Ending a Session The simplest way to conclude a MATLAB session is to type quit at the prompt. You can also click on the special symbol that closes your windows (usually an × in the upper left- or right-hand corner). Either of these may or may not close all the other MATLAB windows (which we talked about in the last section) that are open. You may have to close them separately. Indeed, it is our experience that leaving MATLAB-generated windows around after closing the MATLAB Desktop may be hazardous to your operating system. Still another way to exit is to use the Exit MATLAB option from the File menu of the Desktop. Before you exit MATLAB, you should be sure to save any variables, print any graphics or other files you need, and in general clean up after yourself. Some strategies for doing so are addressed in Chapter 3
Chapter 2 MATLAB Basics In this chapter,you will start learning how to use MATLAB to do mathematics. You should read this chapter at your computer,with MATLAB running.Try the commands in a MATLAB Command Window as you go along.Feel free to experiment with variants of the examples we present;the best way to find out how MATLAB responds to a command is to try it. For further practice,you can work the problems in Practice Set A.The Glossary contains a synopsis of many MATLAB operators,constants, functions,commands,and programming instructions. Input and Output You input commands to MATLAB in the MATLAB Command Window.MAT- LAB returns output in two ways:Typically,text or numerical output is re- turned in the same Command Window,but graphical output appears in a separate graphics window.A sample screen,with both a MATLAB Desktop and a graphics window,labeled Figure No.1,is shown in Figure 2-1. To generate this screen on your computer,first type 1/2 1/3.Then type ezplot ('x3 -x'). While MATLAB is working,it may display a"wait"symbol-for example, an hourglass appears on many operating systems.Or it may give no visual evidence until it is finished with its calculation. Arithmetic As we have just seen,you can use MATLAB to do arithmetic as you would a calculator..You can use“+”to add,.“-”to subtract,.“*”to multiply,“/”to divide, 8
Chapter 2 MATLAB Basics In this chapter, you will start learning how to use MATLAB to do mathematics. You should read this chapter at your computer, with MATLAB running. Try the commands in a MATLAB Command Window as you go along. Feel free to experiment with variants of the examples we present; the best way to find out how MATLAB responds to a command is to try it. ☞ For further practice, you can work the problems in Practice Set A. The Glossary contains a synopsis of many MATLABoperators, constants, functions, commands, and programming instructions. Input and Output You input commands to MATLAB in the MATLAB Command Window. MATLAB returns output in two ways: Typically, text or numerical output is returned in the same Command Window, but graphical output appears in a separate graphics window. A sample screen, with both a MATLAB Desktop and a graphics window, labeled Figure No. 1, is shown in Figure 2–1. To generate this screen on your computer, first type 1/2 + 1/3. Then type ezplot(’xˆ3 - x’). ✓ While MATLAB is working, it may display a “wait” symbol — for example, an hourglass appears on many operating systems. Or it may give no visual evidence until it is finished with its calculation. Arithmetic As we have just seen, you can use MATLAB to do arithmetic as you would a calculator. You can use “+” to add, “-” to subtract, “*” to multiply, “/” to divide, 8
Arithmetic 9 suiuti'vh 0#日e4A产座P Figure 2-1:MATLAB Output. and“∽”to exponentiate.For example, >>3^2-(5+4)/2+6*3 ans 22.5000 MATLAB prints the answer and assigns the value to a variable called ans. If you want to perform further calculations with the answer,you can use the variable ans rather than retype the answer.For example,you can compute the sum of the square and the square root of the previous answer as follows: >ans2 sqrt(ans) ans 510.9934 Observe that MATLAB assigns a new value to ans with each calculation. To do more complex calculations,you can assign computed values to variables of your choosing.For example, >>u=co8(10) u= -0.8391
Arithmetic 9 Figure 2-1: MATLAB Output. and “ˆ” to exponentiate. For example, >> 3ˆ2 - (5 + 4)/2 + 6*3 ans = 22.5000 MATLAB prints the answer and assigns the value to a variable called ans. If you want to perform further calculations with the answer, you can use the variable ans rather than retype the answer. For example, you can compute the sum of the square and the square root of the previous answer as follows: >> ansˆ2 + sqrt(ans) ans = 510.9934 Observe that MATLAB assigns a new value to ans witheachcalculation. To do more complex calculations, you can assign computed values to variables of your choosing. For example, >> u = cos(10) u = -0.8391