First you need to know how to enter matrices. Here are a few examples:
or, you can use for loops if a matrix is defined via a formula:
or, you can use builtin matlab commands for creating commonly occuring matrices:
Some special matrices
Let n be an integer:
| eye(n) | n by n identity matrix |
| zeros(n) | n by n matrix of zeros |
| ones(n) | n by n matrix of ones |
| ones(n,1) | column vector (n by 1) of ones |
| diag(x) | diagonal matrix whose entries are the vector x |
| rand(n) | an n by n matrix with entries chosen randomly (uniform dist) |
Calculations with matrices
Once you've entered some matrices calculations are easy. The commands described below are pretty self explanatory.
Let A,B be n by n matrices, and x,b be n by 1 column vectors and c be any number
| A*b , A*B | matrix-vector/ matrix-matrix multiplication |
| A' or b' | transpose of any matrix/vector |
| A+B, cA | matric addition and scalar multiplication |
| A.*B | returns a matrix whose elements are a(i,j)*b(i,j) |
| A./B | returns a matrix whose elements are a(i,j)/b(i,j) |
| A\b | equals the solution x of Ax=b |
| A^3 | A*A*A |
| A.^3 | returns a matrix whose entries are a(i,j)^3 |
Try:

In the last command matlab had some problems computing the inverse of Ax=b numerically. Matlab does not use gauss elimination to solve Ax=b. The routine it does use has test for the condition number of the matrix and other checks to decide if a propagating roundoff error may have resulted in an incorrect answer. Matlab computes determinants and upper row echelon forms via different algorithms. For example, if you continue with the commands

they indicate the determinant is zero (A is singular) and the row reduced upper echelon form of A (rref(A)) has a row of zeros. The later indicates the rank of the matrix is 2 hence A is singular.
Moral: Don't always believe the numerical answers you compute. Always try to check by some other means.
Just for fun, try executing:
>> rrefmovie(A)
This shows how matlab performs row reduction with pivoting.
Here are a list of some other matrix operations:
Some matrix operations
Let A be an n by n matrix and b a column vector:
| norm(b) | Euclidean (length) norm or the vector b |
| norm(A) | matrix norm (as defined in class) |
| cond(A) | condition number of a matrix (as defined in class) |
| inv(A) | inverse matrix of A |
| det(A) | determinant of A |
| eig(A) | returns a column vector containing the eigenvalues of A |
| null(A) | returns a vector(s) which is a basis for the nullspace of A |
| [L,U]=LU(A) | returns the L-U factorization of A |
| rref(A) | produces row reduced upper echelon form of A (with pivoting) |
An example of an ill-conditioned system:
Execute the following:

What are r1 and r2?
What does r1=0 imply about x1?
Note that even though r2 is small, norm(x1-x2) is not! Try
>> cond(A)
>> det(A)
These values indicate that A is illconditioned and nearly singular, respectively. Here's a harder one:

What is the smallness of the last number telling you?
So, why is A ill-conditioned?
Naive Gauss Elimination and Vandermonde matrices:
Download the following two M-files:
GaussNaive.m In matlab [U,B,x]=GaussNaive(A,b,trace) will return the upper echelon form of Ax=b, i.e. Ux=B and then backsolve to find x. This is all done with NAIVE gauss elimination. Choose trace = 1 if you want to view each row reduction. Otherwise choos trace=0.
Vander.m Vander(n) creates the n by n Vandermonde matrix discussed on page 248-49 of the text. These matricies are ill-conditioned and can be used to demonstrate failure in NAIVE gauss elimination.
Within matlab execute the code:

and keep hitting return. This code uses Naive gauss elimination to solve the problem:
A x = b
where A and b are the n-dimensional Vandermonde matrix and vector, respectively. It is know that for all n=2,3,4,5,6,7.... the solution is exactly equal to the vector x containing all ones. Note when you run this problem that for a matrix as small as n=14 with the 16 digit matlab accuracy, the so called answer is extremely inaccurate!!! This is another example of how trying to solve ill-conditioned systems naively can lead to incorrect numerical solutions.