You are on page 1of 17
Basic Features Running MATLAB creates one or more windows on your computer monitor. One of these windows. entitled MATLAB. is commonly called the MATLAB deskvop. This window is the primary graphical user interface for MATLAB. Within the MATLAB window. there is a window called the Command window. which is the pri- ‘mary place wherein you interact with MATLAB. The prompt >> is displayed in the Command window. and when the Command window is active, a blinking cursor appears to the right of the prompt. This cursor and prompt signify that MATLAB is ‘waiting to perform a mathematical operation, 2.1 SIMPLE MATH Just like a calculator. MATLAB can do basic math. Consider the following simple example: Mary goes to the office supply store and buys four erasers at 25 cents each, six memo pads at 52 cents each, and two rolls of tape at 99 cents each. How many items did Mary buy. and how much did they cost? To solve this problem with a calculator. you enter 446+2-12 items 4X 25 +6 x 5242 x 99 = 610 cents In MATLAB. this problem can be solved in a number of different ways, First. the calculator approach can be taken: >> 44642 ans = 2 Section 2.1 Simple Meth 5 >> 428 + 296 610 Note that MATLAB Goesn’t care about spaces. for the most part.and that muitipli fakes precedence over addition. Note also that MATLAB calls the result ans. h is short for aster for both computations As an alternative. the problem can be solved by storing information in MATLAB variables: sers = 4 erasers = >> pads = 6 pads = é >> tape = 2; >> items = erasers + pads + tape itens >> cost = erasers*25 + pads*52 + tape cost = 610 Here, we created three MATLAB variables—erasers. pads. and tape—t store the number of each item. After entering each statemsent, MATLAB di played the results. except in the case of tape. The semicolon at the end of the fine is MATLAB to evaluate the line. but not to display the answer. Finail than calling the results ans. we told MATLAB to cali the number of items pur- chased tems. and the total price paid cost. At each step. MATLAB remembered past information. Because MATLAB remembers things les ask what the average cest per item was: verage_ average_cost 6 Chapter2 Basic Features In all, MATLAB offers the following basic arithmetic operations: Operation Symbol Example Addition + 3422 Subtraction - 54.4 ~ 16.5 Multiplication * 3.146 Division Jor\ 19.54/7 or 7\19.54 Exponentiation a 208 ‘The order in which these operations are evaluated in a given expression is deter- ‘mined by the usual rules of precedence, summarized as follows: Expressions are evaluated from left to right, with the exponentiation operation having the highest precedence, followed by multiplication and division, having equal prece- dence, and then by addition and subtraction, having equal precedence. Parentheses can be used to alter this ordering, in which case these rules of prece- > tape tape = 2 If you can’t remember the name of « variable, you can ask MATLAB for alist of the variables it knows by using the MATLAB command who: >> who Your variables are:

You might also like