(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".
(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