Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen University httplgdipke.xmuedu Key to matLaB Exercise 2- Solving Linear Systems of Equations > A-round(10 rand(5)) > B=round(20 rand(5))-10 ans=5972 > det(A') ans=5972 b)>>det(A+B ns=36495 >>det(A)det(B) ans=26384 No c)>>det(A"B) ans=121900464 >>det(A)°det(B) ans=121900464 d)>>det(a")*det(B) ans=121900464 > det(a* ans=121900464 e)>> det(inv(A)) ans=1.6745e-004 > inv(det(A)) ans=1.6745e-004 f>>det(A"inv(B) ans=0.2926 >>det(A)inv(det( B)) ans=0.2926 Yes 2. >>A=round(10*rand(6)) a)>>A= round(10*rand(6),B=A;B(2,)=A(1)B(1,)=A(2-) 36 ans=-4636 nterchanging two rows of a matrix changes the sign of the determinant b)>>C=A;C(3,)=4*A(3,) >>det(C ans=18544 >>det(A)*4 ans=18544 Multiplying a single row of a matrix by a scalar has the effect of multiplying the value of the determinant by that scalar c)>>D=A,D(5,)=A(5,:)+2*A(4,) > det(A) ans=4636 ans=4636 Adding a multiple of one row to another does not change the value of the determinant a)>>A=[12;2-2l;b=42;x=Ab A >> det(A) ans=-6 >>A=[12;2-2:b=42l;x=invA)*b
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex21 Key to MATLAB Exercise 2 Solving Linear Systems of Equations 1. >> A=round(10*rand(5)) >> B=round(20*rand(5))10 a) >> det(A) ans =5972 >> det(A') ans = 5972 Yes b) >> det(A+B) ans = 36495 >> det(A)+det(B) ans = 26384 No c) >> det(A*B) ans = 121900464 >> det(A)*det(B) ans = 121900464 Yes d) >> det(A')*det(B') ans = 121900464 >> det(A'*B') ans = 121900464 Yes e) >> det(inv(A)) ans = 1.6745e004 >> inv(det(A)) ans = 1.6745e004 Yes f) >> det(A*inv(B)) ans = 0.2926 >> det(A)*inv(det(B)) ans = 0.2926 Yes 2. >> A=round(10*rand(6)). a) >> A=round(10*rand(6)); B=A;B(2,:)=A(1,:);B(1,:)=A(2,:); >> det(A) ans = 4636 >> det(B) ans = 4636 Interchanging two rows of a matrix changes the sign of the determinant. b) >> C=A; C(3, :)=4*A(3, :) >> det(C) ans = 18544 >> det(A)*4 ans = 18544 Multiplying a single row of a matrix by a scalar has the effect of multiplying the value of the determinant by that scalar. c) >> D=A; D(5, :)=A(5, :)+2*A(4, :) >> det(A) ans =4636 >> det(D) ans=4636 Adding a multiple of one row to another does not change the value of the determinant. 3. a) >> A=[1 2; 2 2]; b=[4;2]; x=A\b x = 2 1 >> A*x ans = 4 2 >> det(A) ans =6 Or >> A=[1 2; 2 2]; b=[4;2]; x=inv(A)*b Or
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen Univer httplgdipke.xmuedu >>A=[12;2-2b=42];c=Ab];d=ref(c);x=d(;,end) Same does below. omited b)>>A=[23:51;b=-1;4];x=Ab c)>>A=42-1:3-12;1130];b=[2;10,8};x=Ab Warning: Matrix is close to singular or badly scaled Results may be inaccurate. rCoNd=5.13992le-018 1.0e+016* 148 1.3511 >>A*x It isn't the solution, because det(a=0 d)>>A=[131;211;-22-1];b=1;5-8},x=Ab A*x >>A=[123;234:546,b=00;1]
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex22 >> A=[1 2; 2 2]; b=[4;2]; c=[A b]; d=rref(c); x=d(:, end) Same does below. Omited. b) >> A=[2 3; 5 1]; b=[1;4]; x=A\b x = 1 1 >> A*x ans = 1 4 >> det(a) ans = 13 c) >> A=[4 2 1;3 1 2;11 3 0]; b=[2;10;8]; x=A\b Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 5.139921e018. x = 1.0e+016 * 0.4053 1.4862 1.3511 >> A*x ans = 0 8 8 >> det(a) ans = 0 It isn’t the solution, because det(a)=0。 d) >> A=[1 3 1; 2 1 1; 2 2 1]; b=[1;5;8]; x=A\b x = 2 1 2 >> A*x ans = 1 5 8 >> det(A) ans = 3 4. >> A=[1 2 3; 2 3 4; 5 4 6]; b=[0;0;1]; >> format rational
Key to MATLAB Exercise 2 School of Mathematical Science n Unive httplgdipke.xmuedu >>Al=det(bA(:,2:3)),A2=det(A(:,1)bA(,3));A3=det(A(;1:2)b]); ADet=de(A) >>X[Al/ADet; A2/ADet; A3/ADet > AdjofA-=det(A)inv(A) AdjOfA= 2 0 9 a)>>A=[21-3:451;-2-14}b=08:2} >>xA\b 2 2 -null(A, r) Empty matrix: 3-by-0 So x is the solution >>d=rref(A bD) 004 0 0 001 >>x=d(, end) 2 b)>>A=[21-3;451;244},b=[0:8:8 >>c=null(A, r) >>XO=Ab Warning: Matrix is singular to working precision Ex2-3
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex23 >> A1=det([b A(:, 2:3)]); A2=det([A(:, 1) b A(:, 3)]); A3=det([A(:, 1:2) b]); ADet=det(A); >> x=[A1/ADet; A2/ADet; A3/ADet] x = 1/3 2/3 1/3 5. >> AdjOfA=det(A)*inv(A) AdjOfA = 2 0 1 8 9 2 7 6 1 6. a) >> A=[2 1 3; 4 5 1; 2 1 4]; b=[0;8;2]; >> x=A\b x = 4 2 2 >> c=null(A,'r') c = Empty matrix: 3by0 So x is the solution. or >> d=rref([A b]) d = 1 0 0 4 0 1 0 2 0 0 1 2 >> x=d(:,end) x = 4 2 2 b) >> A=[2 1 3; 4 5 1; 2 4 4]; b=[0;8;8]; >> c=null(A,'r') c = 8/3 7/3 1 >> x0=A\b Warning: Matrix is singular to working precision. x0 =
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen Univer httplgdipke.xmuedu 4/3 8/3 0 > syms k >>X=x0+c*k X 4/3+8/3*k1 8/3-7/3*k1 > d=rrefA b) 73 > syms k >>xd( end)+[-d(1: end-1, end-1); 1*k -4/3+8/3*k] 8/3-734k] >> format short >>A=[21-3;,451;2-2-10},d=ref(A 1.0000 0 2.6667 1.00002.3333 0 >>X=-d(1:+1),1 2.6667 2.3333 10000 10e-014* -0.0444 -0.1776 8. Omitted 9. Omitted
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex24 4/3 8/3 0 >> syms k >> x=x0+c*k x = 4/3+8/3*k1 8/37/3*k1 k1 or >> d=rref([A b]) d= 1 0 8/3 4/3 0 1 7/3 8/3 0 0 0 0 >> syms k >> x=d(:,end)+[d(1:end1,end1);1]*k x = [ 4/3+8/3*k] [ 8/37/3*k] [ k] 7. >> format short >> A=[2 1 3; 4 5 1; 2 2 10]; d=rref(A) d = 1.0000 0 2.6667 0 1.0000 2.3333 0 0 0 >> i=rank(A) i= 2 >> x=[d(1:i,i+1);1] x = 2.6667 2.3333 1.0000 >> A*x ans = 1.0e014 * 0.0444 0.1776 0 8. Omitted 9. Omitted
Key to mAtLaB Exercise 2 School of Mathematical Sciences Xiamen University httplgdipke.xmuedu >>A=[121;242;211},B=[312;122,314:C=A+iB 1).C= 1.0000+3.0000i +1.000011.0000+2.00001 2.0000+1.00001 +2.000012.0000+2.0000i 2.0000+3.0000i +1.000011.0000+4.0000 1.00003.000012.0000-1.0000120000-3.0000i 2.0000-1.000014.0000-2000011.0000-1.0000i 1.0000-20000120000-20000110000-400001 ans 1.0000+3.00002.0000+1.0000120000+3.0000i 2.0000+1.0000140000+2.000011.0000+10000 1.0000+2.000012.0000+2000011.0000+4.0000i The first matrix is the complex conjugate transpose of C while the second one is the transpose of C. Because the elements of C are complex, the results are different >>A ans The first matrix is equal to the second one 3).>inv(A) Warning: Matrix is singular to working precision. ans InfInf In -0.0727-0.14550.6364 0.12730.2545-0.3636
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex25 10. >> A=[1 2 1; 2 4 2; 2 1 1]; B=[3 1 2; 1 2 2; 3 1 4]; C=A+i*B 1).C = 1.0000 + 3.0000i 2.0000 + 1.0000i 1.0000 + 2.0000i 2.0000 + 1.0000i 4.0000 + 2.0000i 2.0000 + 2.0000i 2.0000 + 3.0000i 1.0000 + 1.0000i 1.0000 + 4.0000i >> C' ans = 1.0000 3.0000i 2.0000 1.0000i 2.0000 3.0000i 2.0000 1.0000i 4.0000 2.0000i 1.0000 1.0000i 1.0000 2.0000i 2.0000 2.0000i 1.0000 4.0000i >> C.' ans = 1.0000 + 3.0000i 2.0000 + 1.0000i 2.0000 + 3.0000i 2.0000 + 1.0000i 4.0000 + 2.0000i 1.0000 + 1.0000i 1.0000 + 2.0000i 2.0000 + 2.0000i 1.0000 + 4.0000i The first matrix is the complex conjugate transpose of C while the second one is the transpose of C. Because the elements of C are complex, the results are different. 2). >> A A = 1 2 1 2 4 2 2 1 1 >> A' ans = 1 2 2 2 4 1 1 2 1 >> A.' ans = 1 2 2 2 4 1 1 2 1 The first matrix is equal to the second one. 3). >> inv(A) Warning: Matrix is singular to working precision. ans = Inf Inf Inf Inf Inf Inf Inf Inf Inf >> pinv(A) ans = 0.0727 0.1455 0.6364 0.1273 0.2545 0.3636
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen Univer httplgdipke.xmuedu 0.01820.03640.0909 The first matrix is not equal to the second one 4).>>inv(B) 0.6000-0.2000-0.2000 0.20000.6000-04000 00.5000 > pinv(B) 0.6000-0.2000-0.2000 0.20000.6000-0.4000 -0.5000-0.0000 5000 Because B is not singular, inv(B)is equal to pinv(B) 11. Omitted Ex2-6
Key to MATLAB Exercise 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu. Key to Ex26 0.0182 0.0364 0.0909 The first matrix is not equal to the second one. 4). >> inv(B) ans = 0.6000 0.2000 0.2000 0.2000 0.6000 0.4000 0.5000 0 0.5000 >> pinv(B) ans = 0.6000 0.2000 0.2000 0.2000 0.6000 0.4000 0.5000 0.0000 0.5000 Because B is not singular, inv(B) is equal to pinv(B). 11. Omitted