Lab 1 - Practicing MATLAB M221-3 Just in case you need some MATLAB practice, take the time to go through this introductory lab, it’s easy and it will help you become more comfortable with MATLAB. You do not need to turn any part of this lab in. 1. Getting started. MATLAB is a powerful linear algebra tool that can easily perform all of the tasks that we have learned in class (as well as many other tasks), like matrix multiplication and Gauss-Elimination. MATLAB is installed all across campus, so go find a computer on campus that runs MATLAB. Two places that you have access to MATLAB is in the computer labs in Reid and Roberts. (a) If you have trouble logging into any of the computers on campus that you should have access to, contact the ITC helpdesk in the library. (b) Now that you are logged into a computer on campus that has MATLAB, there should be an icon on the desktop for MATLAB. Double-click on the icon to start MATLAB, at which point MATLAB’s command window will appear. Yes, you are now the commander. Another option to hit the Windows Start Button on the bottom left of the desktop, click on “All Programs”, and find the icon for MATLAB on the list of programs that appears. 2. Defining vectors and matrices. In the MATLAB command window, perform the following commands. (a) Define the 1 × 3 row vector v T = (1 0 3). Enter: v=[1 0 3] 1 (b) Make ”v” a column vector v = 0 . Enter: v=v’ 3 2 (c) Define the 3 × 1 column vector w = 2 . Enter: w=[2 2 1]’ 1 (d) Set w 2 = 5, the second component of w to a 5. Enter: w(2)=5 (e) Define the 1 × 10 row vector x T = (82 83 84 ... 91). Enter: x=82:91 (f) Define the 1 × 1001 row vector u T = (1 1.001 1.002 ... 2). Enter: u=1:.001:2 1 5 1 (g) Define the 3 × 3 matrix A = 0 3 21 . Enter: A=[1 5 1; 0 3 1/2; pi 6 2] π 6 2 10 3 (h) Define the 3 × 2 matrix B = 5 4 . Enter: B=[10 3; 5 4;1 0] 1 0 (i) Set B32 = 2, the component of B in the 3rd row and 2nd column to 2. Enter: B(3,2)=2 0 (j) Set the third column of A equal to 0 . Enter: A(: , 3)=[0 0 1]’ 1 1 (k) Set the second row of B equal to the row vector (sin(.2) exp(2)]. e2 ). Enter B(2,:)=[sin(.2) (l) Define a matrix by “blocks” C = [A B v]. Enter: C=[A B v] (m) Also, try D=[B; [5 5]]. 3. Matrix and Vector Operations (a) Perform the dot product w · v = w T v . Enter: w’*v (b) Perform w + v . Enter: w + v (c) Compute kvv k. Enter: norm(v) (d) Perform the matrix multiplication AB. Enter: A*B (e) Define C = AB. Enter: C=A*B w . Enter A*w (f) Perform the matrix-vector multiplication Aw (g) Perform the matrix addition 3A + I. Enter: 3*A + eye(3) 4. Solving Matrix Systems x = v for x using Gauss Elimination. Enter: x=A\v (a) Solve the system Ax x = v . Enter: A*x (b) Verify that x is a solution to Ax (c) Compute det(A). Enter: det(A) (d) Find A−1 . Enter: inv(A) (e) Solve the system Ayy = v for y using A−1 . Enter: y=inv(A)*v (f) How close are x and y ? Enter: norm(x - y) (g) Find rref(A) and rref(B). Enter: rref(A) and rref(B) (h) Find rank(A) and rank(B). Enter: rank(A) and rank(B) (i) Find the nullspace N (C). Enter: null(C). The columns of the matrix ans that MATLAB returns form the basis for N (C) (j) Find the eigenvalue decomposition A = SΛS −1 . Enter: [S Lambda]=eig(A) Check it: S*Lambda*inv(S) Why doesn’t S*Lambda*inv(S) look like A? 2