HMC Math 73: Linear Algebra (Spring, 1999)
Help and hints with MATLAB for HW#4
(M-Files and matrix generation commands)


Here's some MATLAB info that should make this week's assignment go more quickly...

(i) MATLAB m-files: MATLAB has a built-in programming language that functions via m-files. Any collection of MATLAB commands may be stored in a text file with a .m extension, and typing the filename at the MATLAB command propt causes all commands in the m-file to execute. This allows you to automate tasks and write elaborate programs. You can also use it to define your own MATLAB functions. For this homework, I've created an m-file (hw4.m) that contains the four matrices used in problem 4A. Rather than entering these four matrices yourself, all you need to do is download hw4.m into your MATLAB working directory, then type "hw4" at the MATLAB command prompt. This will put the matrices A, B, C and D into MATLAB's current memory. For more information on m-files, type "help script".

Note: If you are running MATLAB from a working directory that you don't have write permission for, you will need to change MATLAB's working directory to one of your own so that you can save m-files there (use the standard "cd" command within MATLAB). For this assignment, you can probably just copy-and-paste the matrices directly into MATLAB, but eventually you will be required to create your own m-files for assignments. So take this oportunity to try to get the m-file provided to work.

(ii) Matrix generation commands: For problem 4B, you'll need to generate a large matrix manually (figuring out exactly what that matrix is is part of the assignment). However, there are faster ways to generate this matrix than just entering one entry at a time. The follwing sequence of commands generates the 6x6 transition matrix used for our $31 example in class, and can, with only slight modification, generate the needed matrix for this problem. Don't just copy the code below... use the on-line help if necessary and figure out how and why this sequence of commands works!

p=.5
v=(1-p)*ones(5,1)
A=diag(v,-1)
A(1,1:5)=p*ones(1,5)
A(6,6)=1