
MATLAB for Linear Algebra
Prof. S.Hudson
Last modified on
MATLAB is popular mathematics/engineering software, originally designed for professional use with linear algebra problems. It has become more user-friendly over the years, and now it's quite popular for instruction. It is required this term (unless you see me to arrange something else, such as a major project). You will have to think hard about some of the MATLAB exercises, and may have to deal with occasional technical issues, but this will eventually help you learn linear algebra deeper and faster.
The Basics
Getting Started: Go to one of FIU's open labs and try it yourself [Try PC 413, or DM 409A weekdays from about 9am to 8pm, or the Engineering School. In PC 413, the lab monitor should be able to help you find a machine with MATLAB. Your LA may be able to help you in DM 409A during his normal work hours].
Some students suggest working from home with elabs + Citrix . I am told that any FIU student can use elabs [a virtual computer lab, including MATLAB and other common programs], but only Eng majors can access Citrix, which makes it faster.
In PC413, just sit down, click START, then PROGRAMS, then the MATLAB icon. A window should open up, divided into 2 or 3 parts. Click on Help and explore that. Or if you prefer to experiment, try typing "x=2" (and ENTER) in the command window, and then "y = x+3".. It should display "y=5". Play with it a while.
See the Appendix in Leon's text (8th Edn, pg 456) for a quick introduction to the software. Practice entering a matrix into MATLAB and doing the other easy examples on these pages. When you feel ready, try problem 1 on page 78. Stuck? You will have to use a MATLAB command (rand) which is not mentioned in the exercise itself. But it is in the Appx and the intro on page 78. Play around with the commands in the intro before you start the Ch 1 MATLAB homework (MHW1). Next time you get stuck, remember this advice ! You are welcome to discuss MATLAB with me or classmates, but do not share work/solutions to the MHW. Need more help ?
1) Read the Tips and FAQ's below, and practice with the MATLAB help feature.
2) MATLAB has many built-in tutorials (explore the menus at the top). I'd suggest going thru one or two at the start of the semester, but skip the advanced/specialized ones.
3) Our Learning Assistant (Eric W, in Spring 2012) is learning it now, but can probably help with most questions.
4) A supplementary MATLAB manual by Kleinfeld may come with our textbook (but the two books were not written together). It explains many of the basic commands in plain English and includes extended examples called "worksheets" that tell you exactly what to type. [Don't worry about their "EDU prompt" - the FIU computers probably have a different prompt]. If you need this and can't find it, tell me, and I'll put it on reserve.
Tips and FAQs
You are welcome to visit my office hours, and we can look over MATLAB then and there. I've compiled the following FAQ/advice list, and add a bit to it every term -
1) Most of the problems practically tell you what to type, but sometimes they assume you know some basic commands. Before you start Ch 1, you should probably look over the appendix and practice a little with the commands in boldface on page 78. See if you can use inv to compute the inverse of a matrix, etc. Use help on all these commands, if necessary.
2) How to save a session? If you click "FILE" and then save, it will save the values of all your variables (including matrices, etc) but I don't think it saves the commands you typed. Apparently, the diary command does not work properly, as a method of saving a session. But one simple option is to cut-and-paste. That is, highlight your entire session and type Ctrl-C to copy it. Then you can paste it into a notepad file, or an email, with Ctrl-V. And edit it, if you want. Feel free to correct me or expand on this advice. I do sometimes give extra credit for helping out.
What to do when you enter a bad command by mistake? If it doesn't change any key variables, I'd suggest ignoring the mistake (cross it out later with a pencil or with a word processor) and continuing. If it does change some variables, you may have to start the problem over [the command history window makes that pretty easy] and cross out the bad parts later on. Any other suggestions?
3) Problem 3a, page 78: You are supposed to explain why A is singular based on the results of the A*x calculation. Then, you use rref(A) just to check this a different way [you can also try det(A), though that's a Ch 2 idea]. Of course, you should think about what you are doing and briefly discuss the results of the rref(A) experiment. You can do this with a pencil after printing your session. Or, you can type in comments as you go - just start the command line with "%" and MATLAB knows it is just a comment. Such explanations are a large part of your MHW grade. Also, make sure your paper is easily readable, by leaving some space between problems, circling new problem numbers, etc.
4) Before trying Ch.1, problem 6, read about networks and graphs in Ch 1.4. Notice that your adjacency matrix will be a symmetric 8x8 matrix. Regarding problems 1.9 and 2.2, you can read more about magic squares in the MATLAB tutorial if you want. [ If you've never heard of them, enter magic(3) to create one, and then try adding the numbers in each row and each column ! They may not be very useful, but they can be fun]
5) The command format long (ENTER) doesn't give you any output. But after that, all answers will include a lot more digits. You can cancel it with format short (ENTER). If confused, try help (eg help format) first, but you may need some trial and error to see how some commands work.
6) MATLAB is case-sensitive. So, `x' is NOT the same as `X'.
The Homework
I'll call the MATLAB homeworks "MHW". You can print out your MHW sessions on the printer in PC 413 for a small fee (or bring your own paper). Ask the lab monitor how to do it. Some of the MHW questions require you to write out an explanation, or do additional work - do this directly on the printout near the numerical part of your answer. You can use a pencil or the computer for this. It will be a big part of your grade. If there are problems with the PC 413 printer, you have options - -
Remember - Do the work alone and try to do it early. If you ever have problems with the FIU labs or the wording of the questions, please contact me. I'll try to help, and may post answers here, if I think other students would benefit. Also, if you find any of the problems especially good or bad (eg too confusing, or lots of work with no pay off), please let me know.
Note: You can download various freeware that (almost) substitutes for MATLAB, such as Octave and SciLab. Expect a few difficulties, use them at your own risk, and see me in advance about these. There may be special problems with MHW3, for example. Mathematica would probably be harder than the previous options.
See your HW page for the MHW due dates.
MHW 1
Ch1 (pg 78) - 1, 3, 4, 6 (first, read Ch1.4, Appl 3), 7, 10. Also, do 9 if you have time.
Ch2 - 1, 2, 5
If you like, see my remarks on MHW1, after grading it (Summer 2006). But I will probably grade different problems each term.
MHW 2
Ch3 - 1, 2
Ch4 - 1, 3. Also, do 2 if you have time.
MHW 3 . Start ASAP, so you have time to finish !
Ch5 - 1, 2, 5
Ch6 - 1, 2, 3, 4, 5 [you do not have to print the pictures for 1-5], 10, 11
Back to the schedule and regular HW lists