MATLAB Lecture 3 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr MATLAB Lecture 3--Linear Space 线性空间 Ref: matlab-Mathematics-Matrices and Linear algebra Solving linear Systems of equations ● Vocabulary Vector/linear space向量线性空间 linear relation线性关系 linear combination线性组合 linear expression/ representation线性表示 inearly dependence/correlation线性相关 linearly dependent线性相关的 linearly independence线性无关 linearly independent线性无关的 Linear space线性空间 linear spanning线性生成 dimension维数 linear subspace线性子空间 maximal linearly independent subset极大线性无关组 scalar数,标量 span生成,张成 basis ■■■■■■■a■■■■m■ factorization分解 metric matriⅸx对称矩阵 product乘积 triangular matⅸx三角矩阵 transpose转置 upper triangular matrix上三角阵 lower triangular matrix下三角阵 diagonal matrix对角阵 permutation置换 orthogonal matrix正交阵 unitary matrⅸx酉阵 operations and functions e Application on linear space ☆ Review V Let x,, x2,,x, be vectors in vector space V. A sum of the form k, x,+k2-x2+.+k,x where k,k,,.k, are scalars, is called a linear combination of x,, x,,, ,x, The set of all linear combinations of x, x2. is called the span of x, x,,],.The span of x,x2,…, x, will be denoted by Span(x1x2,…,xn) Y The vectors x,,x,,,x, in a vector space V are said to be linearly independent if kx+k2x2+…+knx implies that all the scalars k,, k,, ,k, must equal 0
MATLAB Lecture 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec31 MATLAB Lecture 3 Linear Space 线性空间 Ref: MATLAB→Mathematics→Matrices and Linear Algebra →Solving Linear Systems of Equations l Vocabulary: Vector/linear space 向量/线性空间 linear relation 线性关系 linear combination 线性组合 linear expression/representation 线性表示 linearly dependence/correlation 线性相关 linearly dependent 线性相关的 linearly independence 线性无关 linearly independent 线性无关的 Linear space 线性空间 linear spanning 线性生成 dimension 维数 linear subspace 线性子空间 maximal linearly independent subset 极大线性无关组 scalar 数,标量 span 生成,张成 basis 基 factorization 分解 symmetric matrix 对称矩阵 product 乘积 triangular matrix 三角矩阵 transpose 转置 upper triangular matrix 上三角阵 lower triangular matrix 下三角阵 diagonal matrix 对角阵 permutation 置换 orthogonal matrix 正交阵 unitary matrix 酉阵 l Some operations and functions rank rref rrefmovie null l Application on linear space ² Review: ¸ Let 1 2 , ,..., n x x x be vectors in vector space V. A sum of the form 1 1 2 2 ... n n k x + k x + + k x , where 1 2 , ,..., n k k k are scalars, is called a linear combination of 1 2 , ,..., n x x x . The set of all linear combinations of 1 2 , ,..., n x x x is called the span of 1 2 , ,..., n x x x . The span of 1 2 , ,..., n x x x will be denoted by Span 1 2 ( , ,..., ) n x x x . ¸ The vectors 1 2 , ,..., n x x x in a vector space V are said to be linearly independent if 1 1 2 2 ... n n k x + k x + + k x implies that all the scalars 1 2 , ,..., n k k k must equal 0
ATLAB Lecture 3 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr t If the only way the linear combination k, x,+k,x,+.+k, can equal the zero vector is for all scalars k,, k,,,k, to be 0, then x, x 2,,, are linearly independent The vectors x,,x,,,x, in a vector space V are said to be linearly dependent if there exist scalars k, k2, ..,k, not all zero such that tk 2 If there are nontrivial choices of scalars for which the linear combination K,x+k,x,+.+,r, equals the zero vector, then x,, x,,,x, are linearly dependent A vector x is said to can be written as a linear combination of x,,x,, ,, if there exist scalars k,k2,k, such that x=k,x,+kx2+.+k,x The vectors x,, x,,,x, in a vector space V are said to be a basis of v if x,,x,,,x are linearly independent and for any vector xE V can be written(uniquely)as a linear bination of x,, x ,, xn,. The n is called as the dimension of v, and will be denoted dim(v) Let s denotes a set of vectors xi,x2,,, in a vector space V. x,,x,,,xi is a subset of S If for any xES, x can be written uniquely as a linear combination of xi, i,,x, x,,x,,,x will be called as one of the maximal linearly independent subsets of s Y MATLAB suppose that V=R near relation >>A=fix(10*rand(3, 3)): %Obtain a set of vectors which are the columns of A >>r=rank(A) >> ifr disp"The columns of A are linear disp The columns of A are linearly dependent end linear combination
MATLAB Lecture 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec32 ² If the only way the linear combination 1 1 2 2 ... n n k x + k x + + k x can equal the zero vector is for all scalars 1 2 , ,..., n k k k to be 0, then 1 2 , ,..., n x x x are linearly independent. ¸ The vectors 1 2 , ,..., n x x x in a vector space V are said to be linearly dependent if there exist scalars 1 2 , ,..., n k k k not all zero such that 1 1 2 2 ... n n k x + k x + + k x . ² If there are nontrivial choices of scalars for which the linear combination 1 1 2 2 ... n n k x + k x + + k x equals the zero vector, then 1 2 , ,..., n x x x are linearly dependent. ¸ A vector x is said to can be written as a linear combination of 1 2 , ,..., n x x x if there exist scalars 1 2 , ,..., n k k k such that 1 1 2 2 ... n n x = k x + k x + + k x . ¸ The vectors 1 2 , ,..., n x x x in a vector space V are said to be a basis of V if 1 2 , ,..., n x x x are linearly independent and for any vector x ŒV can be written (uniquely) as a linear combination of 1 2 , ,..., n x x x . The n is called as the dimension of V, and will be denoted by dim(V) . ¸ Let S denotes a set of vectors 1 2 , ,..., n x x x in a vector space V. 1 2 , ,..., r i i i x x x is a subset of S. If for any x ŒS, x can be written uniquely as a linear combination of 1 2 , ,..., r i i i x x x , 1 2 , ,..., r i i i x x x will be called as one of the maximal linearly independent subsets of S. ² MATLAB suppose that 1 V R n¥ = linear relation >> A = fix (10*rand(3, 3)); % Obtain a set of vectors which are the columns of A >> r = rank(A); >> if r == 3 disp ‘The columns of A are linearly independent.’ else disp ‘The columns of A are linearly dependent.’ end linear combination
MATLAB Lecture 3 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr >>A=fix(10*rand(3, 2)): %Obtain a set of vectors which are the columns ofA >>X=fx(10°rand(3,1)) >>r0=rank(A ); >>r l=rank (AxD) >>ifro=rl disp can be written by the columns ofA else disp 'x cannot be written by the columns of A d basis of a vector space >>A=fix(10*rand( 3, 4)): %Obtain a set of vectors which are the columns of A >>B=rref(a) Observe the columns of b we may obtain the basis of the linear spanning space of columns ofA > rrefmovie(A) Movie of the computation of the reduced row echelon form .*Advanced study for linear system 令 Cholesky,LU, and QR Factorizations(分解) tic toc All three of these factorizations make use of triangular matrices where all the elements either above or below the diagonal are zero. Systems of linear equations involving triangular matrices are easily and quickly sol ved using either forward or back substitution. The Cholesky factorization expresses a symmetric matrix(对称矩阵) as the product of a triangular matrix and its transpose A=RR, where r is an upper triangular matrix LU factorization, or Gaussian elimination, expresses any square matrix A as the product of a permutation of a lower triangular matrix and an upper triangular matrix A=LU where L is a permutation of a lower triangular matrix with ones on its diagonal and U is an upper triangular matrix The orthogonal, or QR, factorization expresses any rectangular matrix as the product of an orthogonal or unitary matrix and an upper triangular matrix. A column permutation may also be involved. A=ORor AP=OR where g is orthogonal or unitary, R is upper triangular, and P is a permutation. An orthogonal matrix or a matrix with orthonormal columns. is a real matrix whose columns all have unit length and are perpendicular to each other. If g is orthogonal, then 00=7 For complex matrices, the corresponding term is unitary
MATLAB Lecture 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec33 >> A = fix (10*rand ( 3, 2 ) ); % Obtain a set of vectors which are the columns of A >> x = fix (10*rand ( 3,1 ) ); >> r 0 = rank ( A ); >> r 1= rank ([A x]); >> if r 0 == r1 disp ‘x can be written by the columns of A.’ else disp ‘x cannot be written by the columns of A.’ end basis of a vector space >> A = fix (10*rand ( 3, 4 ) ); % Obtain a set of vectors which are the columns of A >> B = rref (A) % Observe the columns of B we may obtain the basis of the linear … spanning space of columns of A >> rrefmovie (A) % Movie of the computation of the reduced row echelon form l *Advanced study for linear system ² Cholesky, LU, and QR Factorizations (分解) lu qr chol tic toc ² Theorem All three of these factorizations make use of triangular matrices where all the elements either above or below the diagonal are zero. Systems of linear equations involving triangular matrices are easily and quickly solved using either forward or back substitution. The Cholesky factorization expresses a symmetric matrix(对称矩阵)as the product of a triangular matrix and its transpose A = R¢ R , where R is an upper triangular matrix. LU factorization, or Gaussian elimination, expresses any square matrix A as the product of a permutation of a lower triangular matrix and an upper triangular matrix A = LU where L is a permutation of a lower triangular matrix with ones on its diagonal and U is an upper triangular matrix. The orthogonal, or QR, factorization expresses any rectangular matrix as the product of an orthogonal or unitary matrix and an upper triangular matrix. A column permutation may also be involved. A = QR or AP = QR where Q is orthogonal or unitary, R is upper triangular, and P is a permutation. An orthogonal matrix, or a matrix with orthonormal columns, is a real matrix whose columns all have unit length and are perpendicular to each other. If Q is orthogonal, then Q¢Q = I . For complex matrices, the corresponding term is unitary
ATLAB Lecture 3 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr 令 MATLAB Ax=b Cholesky >>A=fix(10*rand(3)) >>d= linspace (1, 50, 3); %Generates a row vector of 3 linearly equally spaced points between 1 and 50 > Diag d= diag(d) %o Generate a diagonal matrix with the input arguments >>A=A*Diag d(A) %o Generate a symmetric matrix >>b=fix(10 rand (3, 1)); >>R= chol(A) >>X= RIRIb >>A=fix(10°rand(3) >>b=fx(10*rand(3,1) >>[L,U]=lu(A) >>X=U(L\b) QR >>A=fix(10*rand(3)) >>b=fx(10°rand(3,1) >>[Q,R]=qr(a) >>X=RYQIb) >>A=fx(10*rand(100) >>d= linspace(1, 50, 100); %Generates a row vector of 100 linearly equally spaced points between I and 50 >> Diag d=diag(d) Generate a diagonal matrix with the input arguments >>A= A Diag d°(A) >>b=fix(10 rand(100, 1)) >>tic, R=chol(A) x chol= RMR\b) t chol=toc Compute the time spent > tic, [ L, U=lu(A) x LU=U\LIb); t LU=toc >>tic;Q, R]=qr(A); x QR= RYQ\b); t QR=toc Lec3-4
MATLAB Lecture 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec34 ² MATLAB Ax = b Cholesky >> A = fix (10*rand(3)); >> d = linspace (1, 50, 3); %Generates a row vector of 3 linearly equally spaced points… between 1 and 50 >> Diag_d = diag(d); % Generate a diagonal matrix with the input arguments >> A = A*Diag_d*(A’); % Generate a symmetric matrix >> b = fix (10*rand(3,1)); >> R = chol(A); >> x = R\(R'\b) LU >> A = fix (10*rand(3)); >> b = fix (10*rand(3,1)); >> [L, U] = lu(A) >> x = U\(L\b) QR >> A = fix (10*rand(3)); >> b = fix (10*rand(3,1)); >> [Q, R] = qr (a) >> x = R\(Q\b) >> A = fix (10*rand(100)); >> d = linspace (1, 50, 100); %Generates a row vector of 100 linearly equally spaced… points between 1 and 50 >> Diag_d = diag(d); % Generate a diagonal matrix with the input arguments >> A = A*Diag_d*(A’); >> b = fix (10*rand(100,1)); >> tic; R = chol(A); x_chol = R\(R’\b); t_chol=toc % Compute the time spent >> tic; [L, U] = lu(A); x_LU = U\(L\b); t_LU=toc >> tic; [Q, R] = qr(A); x_QR = R\(Q\b); t_QR=toc