Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen University httplgdipke.xmuedu Key to matLAB Exercise 3- Linear Space >>al=[1,0;0;a2=0;1;1;a3=10;1A=al,a2,a3 010 >> rank(A) ans fal, a2, a3) is spanning set for R, because the rank of a equals to 3 > det(A) fal, a2, a3) is spanning set for R, for the determinant of A is not zero 2) >>al=[10,0;a2=0;1;1a3=[10;1;a4=1,2;3l,A=al,a2,a3,a4l;refA) 100 The result shows that (al a2 a3) is spanning set for R Or >>Al=A(,1:3) Al= 10 0 0 > rank(Al) ans > rank(A) ans The result shows that fal a2 a3) is spanning set for R >>al=[2;1-2]a2=32-2l,a3=220];A=al,a2a 2 Key to Ex3-1
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex31 Key to MATLAB Exercise 3 – Linear Space 1. 1) >> a1=[1;0;0]; a2=[0;1;1]; a3=[1;0;1]; A=[a1,a2,a3] A = 1 0 1 0 1 0 0 1 1 >> rank(A) ans = 3 {a1,a2,a3} is spanning set for 3 1 R ¥ , because the rank of A equals to 3. Or >> det(A) ans = 1 {a1,a2,a3} is spanning set for 3 1 R ¥ , for the determinant of A is not zero. 2) >> a1=[1;0;0]; a2=[0;1;1]; a3=[1;0;1]; a4=[1;2;3]; A=[a1,a2,a3,a4]; rref(A) ans = 1 0 0 0 0 1 0 2 0 0 1 1 The result shows that {a1 a2 a3} is spanning set for 3 1 R ¥ . Or >> A1=A(:, 1:3) A1 = 1 0 1 0 1 0 0 1 1 >> rank(A1) ans = 3 >> rank(A) ans = 3 The result shows that {a1 a2 a3} is spanning set for 3 1 R ¥ . 3) >> a1=[2;1;2]; a2=[3;2;2]; a3=[2;2;0]; A=[a1,a2,a3] A = 2 3 2 1 2 2 2 2 0
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen Univer httplgdipke.xmuedu > rref(A) ans 0 0 00 220 They are not spanning sets for r, because there are less than 3 independent vectors > det(A) They are not spanning sets for R, because the matrix A, which is formed by the corresponding vectors, is singular >>A=[2-14;1-12;-22-4l >>rref(A) 200 > rank(A) They are not spanning sets for R >>x1-123];x2=342]:x=[266;y=-9:-25 >>Al=xl, x2, X > rref(Al ans x E Span(, x2), for the vectors x1, x2, x are independent >> rank(Al) ans >>rank((x1, x2)) x Span(x, x ,) for the rank of( x, x2) is not equal to that of (x,x2, x) Key to Ex3-2
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex32 >> rref(A) ans = 1 0 2 0 1 2 0 0 0 They are not spanning sets for 3 1 R ¥ , because there are less than 3 independent vectors. Or >> det(A) ans = 0 They are not spanning sets for 3 1 R ¥ , because the matrix A, which is formed by the corresponding vectors, is singular. 4) >> A=[2 1 4; 1 1 2; 2 2 4 ]; >> rref(A) ans = 1 1 2 0 0 0 0 0 0 Or >> rank(A) ans = 1 They are not spanning sets for 3 1 R ¥ . 2. 1) >> x1=[1;2;3]; x2=[3;4;2]; x=[2;6;6]; y=[9;2;5]; >> A1=[x1,x2,x]; >> rref(A1) ans = 1 0 0 0 1 0 0 0 1 Span 1 2 xœ (x , x ) , for the vectors x1, x2, x are independent. Or >> rank(A1) ans = 3 >> rank([x1, x2]) ans = 2 Span 1 2 xœ (x , x ) , for the rank of { x1, x2} is not equal to that of {x1, x2, x}
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen Univer httplgdipke.xmuedu >>rref((x1, x2,y)) 03 Result implies that y E Span(x,, x,) >>x1=[1,0;0];x2=00,1x3=1;0.1A=x1,x2,x3,r=rank(A) >>m2=size(A, 1); calculate the row size of A >>ifrm2 disp( They are spanning sets for P3) disp( They are not spanning sets for P3) It is not spanning set for P3 >>x1=[2,00]x2=-2;1;0];x3=0,1;0;x4=1;0,2];,rank(xl,x2,x3,x4]) (2, x-2, x, 2x+1) is spanning set for Ps >>x1=[1;1;0;x2=-2;1;0]:x3=3:0;l;refx1,x2,x3) 00 0 0 001 that x+lx-2,x+3 is spanning set for P3 1) >>al=[l 1 1: a2= 1 1: a3=[10 1: rank(lal, a2, a3D) ans They are linearly independent >>al=[2-12};a2=[220;A=al,a2l, > rank(A)=size(A, 2) %check whether the rank of A is equal to the column size of A. ans They are linearly independent Key to Ex3-3
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex33 2) >> rref([x1,x2,y]) ans = 1 0 3 0 1 2 0 0 0 Result implies that Span 1 2 y Œ (x , x ) . 3. 1) >> x1=[1; 0; 0]; x2=[0; 0; 1]; x3=[1; 0; 1]; A=[x1, x2, x3]; r=rank(A); >> m2=size(A, 1); % calculate the row size of A >> if r==m2 disp (' They are spanning sets for P3 '); else disp (' They are not spanning sets for P3'); end It is not spanning set for P3. 2) >> x1=[2; 0; 0]; x2=[2; 1; 0]; x3=[0; 1; 0]; x4=[1; 0; 2]; rank([x1, x2, x3, x4]) ans= 3 { } 2 2, x - 2, x, 2x +1 is spanning set for P3. 3) >> x1=[1; 1; 0]; x2=[2; 1; 0]; x3=[3; 0; 1]; rref([x1, x2, x3]) ans = 1 0 0 0 1 0 0 0 1 It means that { } 2 x +1, x - 2, x + 3 is spanning set for P3. 4. 1) >> a1=[1 1 1]'; a2=[0 1 1]'; a3=[1 0 1]'; rank([a1, a2, a3]) ans = 3 They are linearly independent. 2) >> a1=[2 1 2]'; a2=[2 2 0]'; A=[a1, a2]; >> rank(A)==size(A, 2) %check whether the rank of A is equal to the column size of A. ans = 1 % 1 means “true”, 0 means “false” They are linearly independent
Key to mATLAB Exercise 3 3 School of Mathemat atical Sciences xiamen univer httplgdipke.xmuedu >>al=[2-12];a2=-21-2};a3=42-4,A=lala2,a3];rank(A)==size(A,2) They are linearly dependent For example 2) >>x1=2,0,0];x2=-2,1;0]x3=0,1;0];x4=1;0,2];ref(xl,x2,x3,x4]) 100 0 Spn92x-2,x2x2+2=pn(2x-2,2x2+1 >>X1+-123;x2=[342];x3=[0101Iy 1) >> rank((x1, x2, x3)) > rank(x1, x2, X3-size((x1, x2, X3, 2) ans x,,x2,x, are linearly dependent > rank(xl, x2) ans 2 x, and x, are linearly independent 3)The rank of vector set(x,,x2,x3) shows the dimension is 2 4)They are the 2-dimension subspace of R 7 >>X1+-123;x2=[342;x3=01011,x4=273,x5=-132;, rref(xI,x2,x3,x4,x5]) ans 1.0000 03.0000 0.4194 01.00001.0000 0-0.6452 01.00000.6774 (x1, x2, x4) forms a basis for R >>x1=32]x2=[1;3];A=x1x2l;x=[10,7,c=invA)*x Key to Ex3-4
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex34 3) >> a1=[2 1 2]'; a2=[2 1 2]'; a3=[4 2 4]'; A=[a1,a2,a3]; rank(A)==size(A, 2) ans = 0 They are linearly dependent. 5. For example 2) >> x1=[2; 0; 0]; x2=[2; 1; 0]; x3=[0; 1; 0]; x4=[1; 0; 2]; rref([x1, x2, x3, x4]) ans = 1 0 1 0 0 1 1 0 0 0 0 1 Span{ } 2 2, x - 2, x, 2x +1 =Span{ } 2 2, x - 2, 2x +1 . 6. >> x1=[1 2 3]'; x2=[3 4 2]'; x3=[0 10 11]'; 1) >> rank([x1,x2,x3]) ans = 2 Or >> rank(x1, x2, x3)==size([x1, x2, x3], 2) ans = 0 1 2 3 x , x , x are linearly dependent. 2) >> rank([x1 ,x2]) ans = 2 1 x and 2 x are linearly independent. 3) The rank of vector set { 1 2 3 x , x , x } shows the dimension is 2. 4) They are the 2dimension subspace of 3 1 R ¥ . 7. >> x1=[1 2 3]'; x2=[3 4 2]'; x3=[0 10 11]'; x4=[2 7 3]'; x5=[1 3 2]'; rref([x1,x2,x3,x4,x5]) ans = 1.0000 0 3.0000 0 0.4194 0 1.0000 1.0000 0 0.6452 0 0 0 1.0000 0.6774 {x1, x2, x4} forms a basis for R3 . 8. >> x1=[3;2]; x2=[1;3]; A=[x1 x2]; x=[10;7]; c=inv(A)*x
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen Univer httplgdipke.xmuedu 3.2857 0.1429 >>Transition matrix-B Transition matrix 10,7 > coordinates=inv(Transition matrix)*x 11.5000 13.0000 10. X=x1,x2]:Y=y1,y2] >>Transition matrix =XY Transition matrix -2.50002.5000 4.0000-2.0000 >>A=[123:-236946 6 46 >>xl=A(1,),x2=A(2,)x3=A(3,) >>y1=A(:,1)y2=A(:2),y3=A(;3) 00 So a basis for the row space is (xl, x2, X3), a basis for the column space is yl, y2, y3 The nullspace is (10; >>x1=A(1),x2=A(2,),X3=A(3)yl=A(;1),y2=A(2),y3=A(:3),y4=A(:,4) ans 00 So a basis for the row space is (x1, x2, x3 a basis for the column space is yl, y2, y4) and
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex35 c = 3.2857 0.1429 9. >> x1=[2; 4]; x2=[1; 3]; B=[x1, x2]; >> Transition_matrix=B Transition_matrix = 2 1 4 3 >> x=[10; 7]; >> coordinates =inv(Transition_matrix) *x coordinates = 11.5000 13.0000 10. >> X=[x1, x2]; Y=[y1, y2]; >> Transition_matrix =X\Y Transition_matrix = 2.5000 2.5000 4.0000 2.0000 11. 1) >> A=[1 2 3;2 3 6;9 4 6] A = 1 2 3 2 3 6 9 4 6 >> x1=A(1,:); x2=A(2,:); x3=A(3,:); >> y1=A(:,1); y2=A(:,2); y3=A(:,3); >> rref(A) ans = 1 0 0 0 1 0 0 0 1 So a basis for the row space is {x1, x2, x3}, a basis for the column space is {y1, y2, y3}. The nullspace is {0}. 2) >> x1=A(1,:); x2=A(2,:); x3=A(3,:); y1=A(:,1); y2=A(:,2); y3=A(:,3); y4=A(:,4); >> rref(A) ans = 1 0 1 0 0 1 1 0 0 0 0 1 So a basis for the row space is {x1, x2, x3}; a basis for the column space is {y1, y2, y4} and
Key to mAtlaB Exercise 3 School of Mathematical Sciences Xiamen University httplgdipke.xmuedu a basis for the null space is [-1-11] >>A=-121032562066 >>x1=A(1)x2=A(2:)X3=A(3,),yl=A(:,1),y2=A(:,2y3=A(:3)y4=A(4), > rref(A) ans 1.0000 00.7500 01.0000 0 01.00000.7500 So a basis for the row space is (xl, x2, x3); a basis for the column space is yl, y2, y3; Notice that[-0.75000-0.7500 1]is a solution of Ax0 and rank(A)=3, then a basis for the null space is[-0.75000-0.75001] ◇>>A10=and(10) >>b10=rand(10,1); > tIc >>xl=inv(A10)*b10, > toc Elapsed time is 28.611000 seconds >>[u=lu(A10) yl=inv()*b10; =inv(u)y > toc Elapsed time is 50.012000 seconds. ☆>>tic >>[qr=qr(A10) >>yl=q*b y1=q*bl0 >>X1=nv(r)*y1 > toc Elapsed time is 105.983000 seconds Key to Ex3-6
Key to MATLAB Exercise 3 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex36 a basis for the null space is [1 1 1 0]’. 3) >> A=[1 2 1 0;3 2 5 6;2 0 6 6 ]; >> x1=A(1,:); x2=A(2,:); x3=A(3,:); y1=A(:,1); y2=A(:,2); y3=A(:,3); y4=A(:,4); >> rref(A) ans = 1.0000 0 0 0.7500 0 1.0000 0 0 0 0 1.0000 0.7500 So a basis for the row space is {x1, x2, x3}; a basis for the column space is {y1, y2, y3}. Notice that [ 0.7500 0 0.7500 1]’ is a solution of Ax=0 and rank(A)=3, then a basis for the null space is [ 0.7500 0 0.7500 1]’. 12. ² >> A10=rand(10); >> b10=rand(10, 1); >> tic; >> x1=inv(A10)*b10; >> toc Elapsed time is 28.611000 seconds. ² >> tic; >> [l,u]=lu(A10); >> y1=inv(l)*b10; >> x2=inv(u)*y1; >> toc Elapsed time is 50.012000 seconds. ² >> tic; >> [q,r]=qr(A10); >> y1=q'*b; >> y1=q'*b10; >> x1=inv(r)*y1; >> toc Elapsed time is 105.983000 seconds