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 is now quite popular for instruction. It is required this term (unless you see me to arrange something else, such as a major project). You may have to think hard about some of the MATLAB exercises, and deal with occasional technical issues, but MATLAB will eventually help you learn linear algebra deeper and faster. If you have used it before, you can skip down to the bottom for the exercise list.

The Basics

Getting Started: Go to PC 413 and try it yourself ! There are other such open labs available, such as VH 133, and in the Engineering School, on weekdays 9am to 8pm. The lab monitor should be able to help you find a machine with MATLAB. Some students suggest working from home with elabs + Citrix . Apparently 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. I think you can also purchase MATLAB online for roughly $100, but this is certainly not required. If you use a PC 413 computer, for example, just 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 and you will get the basic idea. You may see me or your LA with questions during normal office hours, or by email.

See the Appendix in Leon's text 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 may or may not know MATLAB and might help you with questions.  Or, see me.

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.

5) Check out this web site for learning MATLAB (free registration required), or surf the net for more, if needed.

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) Many 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 ! These 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

You can print out your MATLAB homework [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 (cut and paste your session into a text editor). This 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. Students have also asked about using Mathematica, but that would probably be harder.

See your HW page for the MHW due dates.

MHW 1

Ch1 (pg 80) - 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 notes on MHW1 after grading it in 2016. Maybe also these similar remarks on MHW1, from long ago.

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 ! If you are using alternative software, plan ahead for the Ch.6 problems.

Ch5 - 1, 2, 5

Ch6 - 1, 2, 3, 4, 5, 10, 11

Note on Ch.6 1-5: These use the "eigshow" command, which creates some nice interactive graphics. You do not have to print the graphics for your HW. I hear that recent editions of MATLAB no longer include "eigshow". In 2016 and 2017, all students found a way around this online, but for now I don't have the link for that [help?].

Please: 1) Start these asap in case tech issues arise, and 2) let me know asap if you have problems, and if you find a link that helps.


Back to the schedule and regular HW lists