Some instructions for using the computer languages MATLAB or OCTAVE in support of Math 310 (Applied Linear Algebra) compiled by Stephen D. Smith (18aug99) FOREWORD: Students should be able to use the language MATLAB on the machines in the various campus labs maintained by the Computer Center. Also, you can check the website indicated at the end of this handout, for a path to a site from which you should be able to download (free) OCTAVE to your own machine. This handout describes the basic usage of those languages, as used for vector and matrix algebra in Math 310---the syntax is essentially the same for both. (A different handout on the course web page describes additionally the login procedures in the Math Dept computer lab in 200 SEO). (Step A: Login) Do whatever is usual, on the particular machine you are using. (Step B: Open the OCTAVE or MATLAB program) Depending on your particular machine, you would either click on some icon bearing the name of the program; or else if you have a command line, on the line enter the name of the program, that is, either matlab or octave From this point on, let's assume we are using OCTAVE. Things should be the same with MATLAB... (Step C: using OCTAVE for Math 310: Applied linear algebra) After you have opened "octave", you should get a startup screen, with prompt just given by > The syntax of Octave is fairly simple: the standard arithmetic operations are given by + - * / (On some other systems, you may have the system MATLAB. The syntax is almost exactly like that of OCTAVE. So these directions should work if you have MATLAB on one of the Computer Center's machines, or your home machine...) To enter a matrix, start with [ separate entries with a blank space separate rows with a semicolon ";" and end with ] Thus if you type a = [ 1 2 ; 3 4 ] the system will respond with A = ( 1 2 ) ( 3 4 ) (I'm approximating the graphics!) (the system always uses capital letters, you can use either) It's useful to know that "transpose" is given by the apostrophe; this is handy, since it's easier to enter a row than a column. Thus to get a column vector of constants, I could type b = [ 5 6 ]' and the system would respond B = (5) (6) You can combine matrices: say I wanted to use the above A as coefficient matrix, and the b as the column of constants. Let me invent some name like "aug" to be the augmented matrix. I could type aug = [a,b] and the system would respond with AUG = ( 1 2 5 ) ( 3 4 6 ) (C.1: doing row operations) To start to row-reduce the above matrix, I would start with the operation "add -3 times the first row to the second". To do this is OCTAVE, it's useful to know that the colon (:) is a wild card---so A(1,:) is the first row of A; A(:,2) is the second column of A; and so on. Thus the above row operation is accomplished by a(2,:) = (-3) * a(1,:) + a(2,:) Do you see why this works? Then you would want to do operation "multiply second row by -1/2". So type a(2,:) - (-1/2) * a(2,:) Suppose at some stage I also had to do operation "exchange rows 1 and 2". This is trickier--it requires three steps, not just two, since I don't want to write over a value and lose it. For that reason we need first to store one row in a dummy location. So three steps accomplishing this are: dummy = a(1,:) a(1,:) = a(2,:) a(2,:) = dummy With these 3 operation types, you can now use the computer to do any row-reduction problem. (C.2: shortcuts/ more complicated operations) Of course, Octave also knows how to do the whole row-reduction process all at once. To get the row-reduced echelon form of the above augmented matrix, type r = rref(aug) You should then be able to read off the answers to the original system---it does the whole algorithm for Gauss-Jordan elimination. Suppose you wanted just the Gaussian elimination algorithm done. This we will study more carefully in Section 1.4, as the LU-decomposition. You can get the LU-decomposition of the above A by typing LU(A) to see the factors; if you want the factors stored for later as say x and y, you could type [x,y] = LU(A) (But be careful: the system may do some row exchanges that you would not expect, based on philosophy described in sections 7.2 and 7.3 --- so the answer may differ from what you would expect doing it by hand. You can see the permutation matrix P used, if you want...check via "help" on the LU command...) The system has lots of other useful features. For inverse, use the function INV For determinant, use the function DET When we study chapters 5 and 6 of the Leon text, we'll return to the Lab and see how to do other important operations such as Gram-Schmidt orthonormalization (with the QR function) and eigenvalues and eigenvectors (with the EIG function). But enough for now. With this much practice completed, it's time to see how to get out: (Ending step C) To get out of Octave, type quit (Ending step B) On most machine, quitting as above will also close the window. If not, do whatever you usually do to kill a window. (Ending step A) Logout in whatever way is usual for your machine. ------------------------------------------------------------- (added 29 January 1999) Software Options (a partial list) QUESTION: How can I use OCTAVE/MATLAB in the future? ANSWER: There are many ways, including the following: 1) Return to the Math Computer Lab, 200 SEO, during standard hours; and use your course account and OCTAVE, just as above. 2) Once you have a 200 SEO account, you can also "remotely" use the machines in that Lab, from any other computer on the Internet (to which you also have access): typically you would use "telnet". So use either the telnet icon/application, or the command line with for example: telnet hank.math.uic.edu and then you can login and use OCTAVE as above. (There are various machines in the Lab, with the first names of baseball players, like "hank" and "mickey" and "jackie" ... most of them have OCTAVE, make sure to telnet in to one that does have OCTAVE...) (Other computers may also have MATLAB or OCTAVE installed, you can check; then you wouldn't even need to telnet. But for example, I think the EECS network does not have these languages, so you may need to telnet as above.) 3) From any of the Computer Center's labs on the campus: these machines should have MATLAB installed. So you should not need the login/security procedures above---just open MATLAB, and proceed with essentially the same syntax as for OCTAVE above. (If I recall, some older versions of MATLAB use angle brackets <...> instead of square brackets [...] for matrices ...) 4) From your own machine: you can download (free) OCTAVE; or purchase the student version of MATLAB. Instructions for the former, and contact with Prentice-Hall for the latter, can be found on Prof. Hurder's "generic" Math 310 homepage at URL http://www.math.uic.edu/math310 by following the appropriate links. The student version of MATLAB is also on sale at many software stores; for example I believe it costs $93.95 at the Micro Station in CCC. You may find (4), using your own machine, most convenient in the long run. Notice also that DOCUMENTATION on OCTAVE/MATLAB is available through the links on the above page (in addition to the online documentation available via the "help" command inside those systems).