>> % MATLAB Recitation Demo for Monday, September 29. >> % File: rdemo4 >> % >> % *** Computing bases for the 4 fundamental subspaces >> % *** of the matrix A. >> % >> % *** Reminder: From the Athena Dash menu, start MATLAB using >> % *** Courseware / 18 Mathematics / 18.06 / 18.06 MATLAB >> % *** Otherwise, MATLAB will not be able to find the new >> % *** command "nullbasis" - which is used below. >> % >> % The MATLAB command basis(A) computes a matrix whose >> % columns are a basis for the column space of A. >> % The MATLAB command nullbasis(A) computes a matrix whose >> % columns are a basis for the nullspace of A. >> % The PA = LU factorization is used to obtain the row space of A >> % via the pivot rows of U. >> % >> diary rdemo4 >> >> % Let's enter a matrix with 3 rows and 5 columns, and compute >> % bases for its column space, nullspace, row space and left >> % nullspace. >> % >> A = [-1 3 8 -2 1; -1 3 9 -1 3; 1 -3 -9 1 -3] A = -1 3 8 -2 1 -1 3 9 -1 3 1 -3 -9 1 -3 >> [m, n] = size(A) m = 3 n = 5 >> r = rank(A) r = 2 >> help plu PLU Pivoting, rectangular, LU factorization. [P,L,U] = PLU(A), for a rectangular matrix A, uses Gaussian elimination to compute a permutation matrix P, a lower triangular matrix L and an upper trapezoidal matrix U so that L*U = P*A. U is the same size as A. P and L are square, with as many rows as A. See also SLU, LU, REF, SOLVE, NULL, BASIS. >> [P, L, U] = plu(A) Pivots in columns: 1 3 No pivots in columns: 2 4 5 Pivots in rows: 1 2 P = 1 0 0 0 1 0 0 0 1 L = 1 0 0 1 1 0 -1 -1 1 U = -1 3 8 -2 1 0 0 1 1 2 0 0 0 0 0 >> colspace = basis(A) rank = 2 colspace = -1 8 -1 9 1 -9 >> nullspace = nullbasis(A) nullspace = 3 -10 -15 1 0 0 0 -1 -2 0 1 0 0 0 1 >> % The pivot rows of U are a basis for >> % the row space of A. >> % >> rowspace = [U(1,:)' U(2,:)' ] rowspace = -1 0 3 0 8 1 -2 1 1 2 >> leftnull = nullbasis(A') leftnull = 0 1 1 >> diary off