Matlab Fundamentals: Matrices

To fully understand how Matlab processes lists, we must discuss a bit about linear algebra.
  1. When we define a list using a command such as t=1:3, Matlab creates a row vector containing 3 elements.
  2. A row vectors can be turned into a column vector using the transpose (') operator. Using the definition of t above, note what happens for the command t' and t''
  3. The multiplication, division and exponential operators (*, /, ^) operating on two vectors will do matrix multiplications, not multiplying the elements together.
  4. Given a list x=0:2:10; then x.*x or x.^2 will give a list with the squares of the even integers [0 4 16 36 64 100] because it is doing list or array multiplication
  5. The command x*x will produce an error (since you can't do matrix multiplication of two row vectors together).
  6. The command x*x' be will give the value of 220 (0+4+16+36+64+100=220) since the transpose operator (') means that we have a row times column matrix (resulting in a scalar).
  7. The command x'*x will result in a 6 by 6 matrix
  8. We can extract and modify elements of a list

Two Dimensional Matrices and Three Dimensional Functions

  1. A 3x3 matrix can be initialized using . y = zeros(3)
  2. Using explicit references, e.g. A = [1, 2, 3; 4, 5, 6; 7, 8, 9]
  3. Array operations (+ - .* ./ .^) operate on each element of a matrix, For example, try A.^2 or A.*A
  4. Matrix operations are (+ - * / ^), For example, try A^2 or A*A
  5. We can extend two 1-D vectors to a 2-D matrix (which we can use for calculations) use meshgrid
  6. For example, we can make a multiplication table using array multiplication
  7. Plot using mesh, surf, contour
  8. Calculate and Plot sinc(R)=sin(R)/R using (MAKE SURE YOU USE .^ and ./)
  9. You can select subranges of matrices, A(3,3) or A(1:2,1:2) or A(1:2,:) or A(:,2:3)
    Electronic Copy: http://physics.gac.edu/~huber/matlab/mtlabmat.htm
    Revised: 28-JAN-97 by Tom Huber, Physics Department, Gustavus Adolphus College.