Guide to Accessing and Using MATLAB in
the Shelby Center Computer Lab

The computer lab in Shelby Center is located in Room 006.  Lab hours are posted on the door of SC006.  You will need a current I.D. to use the Lab. 

The following steps should enable you to run the MATLAB software in the lab in Shelby.
1.	Take a flash drive with you to the lab.  Select a computer and turn on both the monitor and CPU beside the monitor, if they are off.  After the computer boots up, insert the flash card you brought with you in the computer for use in saving your work.  

2.	At the lower left corner, left click the “Start” icon.  From the menu that appears, left click the “MATLAB” icon.

3.	A MATLAB Command Window will appear.  Wait for the prompt to appear in the window before proceeding.  Be aware that MATLAB is case sensitive.  “A” is not the same as “a”.

4.	Start your session by typing diary followed by a path and filename for your work to be saved under.  An example of this command is: diary a:matlab1.txt.  This will record everything which appears in the MATLAB window (commands you type as well as MATLAB results) in the filename you have selected.  Use the commands diary off and diary on to turn this recording off and back on.  In general, MATLAB does not actually write the information to your disk until a diary off command is entered.  It is recommended that you do this often in a long session to make sure your work is saved.  While the recording is off you can view and edit your diary file.  Turn the diary back on to append to the same file, or enter the diary command with a different path and filename to begin recording to a new file.  See “Editing and Printing the Diary File” on the last page for more information.

5.	The diary file saves your work as text which can be edited and printed but not read back into a later MATLAB session.  If you would like to save the matrices from the current session for use in a subsequent MATLAB session, you can type save a:filename.  When entering MATLAB, you can restore the matrices by entering load a:filename.  This save file is in a format MATLAB understands, but which you cannot otherwise read or edit.
6.	When finished, type diary off followed by quit or exit to exit MATLAB.  DO NOT TURN OFF THE COMPUTER.

Editing and Printing the Diary File

	You may look at your diary file at any time without ending your session of MATLAB.  To do so, you must type diary off.  Then type !notepad a:filename at which time a window will open showing you your file.  You may edit this file at this time if so desired.  You may add comments to the assignments at this time by simply typing them in.  To save your edited version of the diary file, select “File” and “Save”.  If you wish to print the file, select “File” and “Print”.  You may pick up your hard copy from the printer.  If you print each problem separately, give each a different filename.

	To resume your MATLAB session, click on the “X” in the upper right corner of the notepad window.  Your MATLAB window should reappear.  REMEMBER to type diary on to continue with the current diary file or diary a:newfilename to record your new work in a new diary file.

Guidelines Regarding MATLAB Assignments

1.	Each student is expected to do the MATLAB assignments independently.  Duplicate computer printouts will not be accepted.

2.	The MATLAB output from your diary file does not need to be extensively edited.  However, if it contains extraneous commands where you were experimenting or trying something which didn’t work, please edit these out.  Also make sure it is clear which work goes with which problem by labeling the problems and drawing a line across your output between problems to separate them.

3.	Generally, each MATLAB assignment will consist of some work done within MATLAB together with some additional computations or explanations which need to be done by hand to complete the problem or put the answer in final form.  Please write any such additional work directly on the computer printout alongside or nearby the MATLAB commands for that problem.

Additional Computer Facilities

1.	 Library Info Arcade
2.	Engineering Labs
3.	Computer Science Labs

BASIC COMMANDS FOR USING MATLAB IN MA224

After having accessed Matlab, you are now ready to learn how to use the Matlab software. The syntax is quite simple and easy to use. If your have not used Matlab before, you may wish to look at one of the demos. Simply type demo, and select one of the options.
Always keep in mind that Matlab is case sensitive. A and a will represent two different matrices.

Entering Matrices:

	Matrices can be entered in several ways. These include: 
•	By a given list of elements.
•	Created by Matlab commands.
•	Retrieved from M-files.

To enter elements of a matrix row wise, after the prompt type

A  =  [1 2 3; 3 2 1; 2 1 3]

Matlab will display the matrix below.
Note: If you do not want Matlab to display your matrix, simply use a semi-colon after your assignment statement.

A = 
		1	2	3
		3	2	1	
		2	1	3

The built-in Matlab functions rand, hilb, and magic can be used to create matrices. For example, rand (n) will create an n x n matrix with randomly generated entries. The command round (10*rand (m, n)) will generate an m x n matrix with random integer entries.

The following commands were used with the above matrix A.

A (2,3)					This command extracts the entry on row 2, column 3.
ans = 

	1

A(: , 3)	This command extracts the third column of matrix A.
ans = 
	3
	1
	3

A (2, :) 				This command extracts the second row of matrix A.

ans =

	3	2	1

B = A(:,2:3)	This command creates a new matrix B by using columns 2 and 3 of matrix A.
ans = 
2	3
2	1
1	3
A’					This command finds the transpose of the matrix A.

ans =

	1	3	2
	2	2	1
	3	1	3

b = [7  8  9]				b is a row vector

b =
	7	8	9

b’	The apostrophe changes the row vector into a column vector.
ans = 
	7
	8	
	9
NOTE:  The up/down cursor keys can be used to scroll back through the previous commands. These commands can then be edited and then executed. This will save you time.

Matrix Commands:

Below is a brief, but very useful, list of Matlab commands for MA 244. One may also use the help command to find a brief description of a command. Type help and then the command you are interested in.

Note:  Always use lower case letters for commands such as diary, rref, inv(A), etc.

	A + B			Matrix sum

	A * B			Matrix multiplication

	r * A			Scalar multiplication of a number r and a matrix A.

	A^n			Computes the nth power of A.

	rref(A)			Finds the reduced row echelon form of A.

	[A b]			Augmented form of matrix A and a vector b.

rref ([A b])	Finds the reduced row echelon form of the augmented matrix.

	A’			Gives the transpose of A.

	inv(A)			Calculated the inverse of A.

	det(A)			Calculated the determinant of A.

eig(A)	Finds the eigenvalues of A and puts the, in a column vector.

[V,D] = eig(A)	Computes the eigenvalues and eigenvectors of A. The eigenvalues are stored along the diagonal of the matrix D and the corresponding eigenvectors are stored in the columns of the matrix V.

rank(A) 	Finds the rank of A.

eye(n)	The n x n identity matrix.

ones(m, n) 	The m x n matrix of all 1’s.

zeros(m, n)	The m x n matrix of all 0’s.

poly(A)	Finds the coefficients of the charactistic equation of the matrix A.

roots(c)	Computes the roots of the polynomial whose coefficients are the elements of the vector c.
	
	A([i, j],:) = A([j, i],:) 		Swap rows i and j.
	
	A(:,[i,j]) = A(:, [j, i])		Swap columns i and j.

	A(j,:) = b*A(i,:) + A(j,:)	Adds a constant b times row i to row j.

	A(i,:) = b*A(i,:)		Multiplies row i by a nonzero constant b