MATLAB ĐẠI SỐ TUYẾN TÍNH PAGE MATLAB ĐẠI SỐ TUYẾN TÍNH 3 Các câu hỏi làm trên Command Window 3 1 Nhóm câu 1 điểm Câu 1 a) >>z=(1+i*sqrt(3))/(1+i) z = 1 3660 + 0 3660i >> argument=angle(z) argument = 0[.]
MATLAB ĐẠI SỐ TUYẾN TÍNH Các câu hỏi làm Command Window 3.1 Nhóm câu điểm Câu 1: a) >>z=(1+i*sqrt(3))/(1+i) z= 1.3660 + 0.3660i >> argument=angle(z) argument = 0.2618 >> modul=abs(z) modul = 1.4142 >> splh=z' splh = 1.3660 - 0.3660i b) >> z=(1+i*sqrt(3))*(1-i); >> argument=angle(z) argument = 0.2618 >> modul=abs(z) modul = 2.8284 >> splh=z' splh = 2.7321 - 0.7321i c) >> z=(-1+i*sqrt(3))/(1-i); >> argument=angle(z) argument = 2.8798 >> modul=abs(z) modul = 1.4142 >> splh=z' splh = -1.3660 - 0.3660i Câu 2: a) >>syms x y >> ezplot((x+1)^2+(y-1)^2==1) >> hold on >> ezplot((x-1)^2+(y+2)^2==4) b) >>syms x y >> ezplot((2*x)^2+(2*y-1)^2==1) >> hold on >> ezplot((3*x-3)^2+(3*y+2)^2==4) Câu 3: a) >> syms x y >> [x y]=solve('x^2-y^2-x=0','2*x*y+y=0') x= -1/2 -1/2 y= 0 3^(1/2)/2 -3^(1/2)/2 b) >> syms x y >> [x y]=solve('x^2-y^2=0','2*x*y-2*y=0') x= 1 y= -1 Câu 5: >> A=[2 -1 5]; >> b=[1 -1]; >> C=b*A’ C= >> vet=trace(C) vet = -5 >> hang=rank(C) hang = -5 >> dinhthuc=det(C) dinhthuc = -5 Câu 6: >> A=[0 -4;-1 -4 5;3 7;0 10]; >> rank(A) ans = >> rank(A*A') ans = >> rank(A'*A) ans = 3 Câu 7: >> A=[1 1;-1 -2]; >> B=[-1 2;0 2;-1 1]; >> C=[2 0;-1 1;0 -1]; >> 2*A*C-(C*B)' ans = 10 -12 -9 Câu 8: >> A=[-2 1;-3 2;-2 1]; >> A^2 ans = -1 -1 -1 >> ans*A ans = 0 0 0 0 Câu 9: >> A=[3 6;2 7;-2 3]; >> frobenius=sqrt(trace(A*A')) frobenius = 12.3693 Câu 10: >> syms m >> A=[1 1 1;2 -1 4;-1 2;2 m]; >> m~=solve(det(A)) ans = m~=13/7 Câu 11: >>inv([1 2;0 0]*[1 0;1 1;0 1]) ans = -1 -1 Câu 12: >> A=[2 1;3 2;1 -1 0]; >> A^2-2*A-3*eye(3) ans = -3 -3 -4 Câu 15: >> A=[3 -2 6;5 4;3 1]; >> B=[1 -1;0 5;1 -2 7]; >> det(2*A*B) ans = -2.7280e+03 Câu 16: >> A=[-1 2;2 0;4 1]; >> det(A^2) ans = 9.0000 Câu 17: >> syms m >> A=[1 1;2 m;3 -1]; >> B=[1 1;2 2;5 5]; >> det(B) ans = Câu 18: >> A=[2 1;3 2;5 -1]; >> PA=det(A)*inv(A) PA = -10.0000 6.0000 2.0000 13.0000 -7.0000 -1.0000 -11.0000 9.0000 -1.0000 Câu 20: >> A=[1 4;2 3;3 2;4 1] >> B=[7;6;7;18]; >> rank(A) ans=4 >>rank([A B]) ans=4 Câu 21: >> A=[1 -3 5;1 -13 22;3 -2;2 -7]; >> B=[1;-1;5;4]; >> rank(A) ans = >> rank([A B]) ans = Câu 22: >> A=[1 -2 -4;3 -5 1;-2 -3;3 -10]; >> B=[2;-3;5;8]; >> rank(A) ans = >> rank([A B]) ans = Câu 24: >> syms m >> A=[1 1 1;2 -1;3 0;-2 -1 m]; >> B=[1;2;6;m-1]; >> det(A) ans = -18 Câu 25: >> A=[1 3 4;1 7;2 5;1 10]; >> rank(A) ans = >> A=rref(A) A= -3 0 0 0 0 0 >> A(4,:)=[] A= -3 0 0 0 >> syms t1 t2 >> B=-t1*A(:,3)-t2*A(:,5) B= 3*t1 + 5*t2 - 2*t1 - 3*t2 >> A(:,5)=[] A= -3 0 0 0 >> A(:,3)=[] A= 0 0 >> kq=inv(A)*B kq = 3*t1 + 5*t2 - 2*t1 - 3*t2 Câu 26: -5 0 -5 %Đặt t1=x3 t2=x5 >> syms m >> M=[1 1 0;1 1;2 -1]; >> rank(M) ans = Câu 27: >> V=[1 -1;3 5;0 -8]; >> ndims(V) ans = >> rref(V) ans = 1.0000 -0.2000 2.2000 1.0000 0.6000 -1.6000 0 0 >> coso=ans(1:2,:) 1.0000 -0.2000 2.2000 1.0000 0.6000 -1.6000 Câu 28: >> syms m >> V=[1 1;2 -1 3;5 m]; >> V(2,:)=V(2,:)-2*V(1,:) V= [ 1, 2, 1, 1] [ 0, -5, -1, 1] [ 5, 5, 4, m] >> V(3,:)=V(3,:)-5*V(1,:) V= [ 1, 2, 1, 1] [ 0, -5, -1, 1] [ 0, -5, -1, m - 5] >> V(3,:)=V(3,:)-V(2,:) V= [ 1, 2, 1, 1] [ 0, -5, -1, 1] [ 0, 0, 0, m - 6] >> subs(V,m,6) ans = [ 1, 2, 1, 1] [ 0, -5, -1, 1] [ 0, 0, 0, 0] Câu 31: >> m1=[1 1;1 0]; >> m2=[2 1;1 -1]; >> m3=[5 2;2 -3]; >> syms a b c >> M=a*m1+b*m2+c*m3 M= [ a + 2*b + 5*c, a + b + 2*c] [ a + b + 2*c, - b - 3*c] >> A=[1 5;1 2;1 2;0 -1 -3]; >> null(A,'r') ans = -3 >> %Vay ho vecto M PTTT Câu 32: >> E=[1 1;1 2;1 1]; >> xE=[1 -3 2]; >> x=E'*xE' x= -3 Câu 33: >> E=[1 1;1 0;1 1]; >> x=[1 -1]; >> xE=inv(E')*x' xE = -1 Câu 34: >> syms m >> M=[1 -1;2 3;-1 m]; >> m~=solve(det(M)) ans = m ~= -17/3 Câu 35: >> syms m >> M=[1 -2 1;3 -1;m 1]; >> m~=solve(det(M)) ans = m ~= -7 Câu 36: >> M=[1 1;2 1;1 2]; >> det(M) ans = Câu 37: >> E=[1 1;1 1;1 0]; >> F=[1 2;1 1;1 1]; >> MT_chuyen_co_so_E_sang_F=inv(E)*F MT_chuyen_co_so_E_sang_F = 0 -1 0 Câu 38: >> syms m >> M=[1 1;2 1]' M= 1 >> x=[1 m]' x= conj(m) >> inv(M(1:2,1:2))*x(1:2) ans = -1 >> m=[1 1]*ans m= Câu 39: >> F=[1 -1 -1;1 -1 -1]; >> syms m >> G=[2 -1 m]'; >> A=null(F,'r') A= -1 0 >> rank(A(1:3,:)) ans = >> rank([A(1:3,:) G(1:3)]) ans = %Khong ton tai m Câu 40: >> V=[1 -1 0;0 1 1]; >> coso=null(V,'r') coso = -2 -1 -1 -1 0 Câu 41: >> V1=[8 -6 0;-7 1]; >> V2=[1 -8 7;0 -5]; >> V1(1,:)*V2' ans = 0 >> V1(2,:)*V2' ans = 0 Câu 42: >> V1=[-2 -6 5;1 -1 0]; >> syms m >> V2=[2 -1 2;-1 m]; >> V2(1,:)*V1' ans = [ 0, 0] >> V2(2,:)*V1(2,:)' ans = >> m=solve(V2(2,:)*V1(1,:)') m= Câu 43: >> u=[1 2]; >> v=[2 -1]; >> cos_u_v=dot(u,v)/(norm(u)*norm(v)) cos_u_v = 0.1667 Câu 44: >> u=[1 2]; >> v=[2 -1]; >> d=norm(u-v) d= 3.1623 >> w=cross(u,v) w= -3 -1 Câu 45, 46, 47: >> A=[2 -3 0;-3 -1;0 -1 4]; >> u=[1 1]; >> v=[-1 2]; >> w=u-v; >> cau45=sqrt(w*A*w') cau45 = 2.6458 >> cau46=(u*A*v')/(norm(u)*norm(v)) cau46 = 2.3333 >> F=[1 1]; >> cau47=null([F*A],'r') cau47 = 1.5000 0.5000 1.0000 0 1.0000 Câu 46: >> f=[2 -3;1 -4 0]; >> coso=null(f,'r') coso = 1.3333 0.3333 1.0000 >> chieu=size(coso',1) chieu = Câu 48: >> f=[1 0;0 1;1 -1]; >> imf=rref(f') imf = 1 -1 0 >> chieu=ndims(imf) chieu = >> coso=imf(1:2,:) coso = 1 -1 Câu 49: >> f1=[1 1;1 0;1 1]; >> f2=[1 2;2 -1;-1 1]; >> f=[2 3]'; >> kq=(inv(f1')*f)'*f2 kq = -3 Câu 50: >> E=[1 1;1 1;1 0]; >> F=[1 1;2 1]; >> A=[2 -3;0 4]; >> f=[1;2;3]; >> kq=F'*A*inv(E)*f kq = -9 Câu 51: >> E=[1 0;0 1;1 1]; >> f=[1;2;3]; >> x=E\f x= Câu 52: 10 >> >> >> >> A=[1 6;5 2]; u=[6;-5]; v=[3;-2]; tr_u=unique((A*u)./u) tr_u = -4 % u la VTR cua A >> tr_v=unique((A*v)./v) tr_v = -5.5000 -3.0000 % v khong la VTR cua A Câu 54: >> A=[3 4;6 5]; >> null(A+eye(2),'r') ans = -1 % -1 la TR cua A >> null(A-3*eye(2),'r') ans = Empty matrix: 2-by-0 % khong la TR cua A Câu 54: >> A=[3 1;2 2;1 3]; >> syms a >> tr=unique(solve(det(A-a*eye(3)))) tr = >> vtr1=null(A-2*eye(3),'r') vtr1 = -1 -1 0 >> vtr2=null(A-6*eye(3),'r') vtr2 = Câu 55: >> syms a m >> A=[0 -8 6;-1 -8 7;1 -14 m]; >> m=solve(det(A-2*eye(3))) m =11 >> A=[0 -8 6;-1 -8 7;1 -14 11]; >> tr=unique(solve(det(A-a*eye(3)))) tr = 11 -2 >> vtr1=null(A-2*eye(3),'r') vtr1 = 0.3333 0.6667 1.0000 >> vtr2=null(A+2*eye(3),'r') vtr2 = 1 >> vtr3=null(A-3*eye(3),'r') vtr3 = 0.4000 0.6000 1.0000 PHẦN ĐIỂM Câu 1: >> A=[1 3;2 4;3 8]; >> rref([A eye(3)]) ans = 0 12 -7 -4 -1 0 -1 -1 >> MTND=ans(:,4:6) MTND = 12 -7 -4 -1 -1 -1 Câu 2: >> M=[1 -1;3 -1;0 -1]; >> syms m >> u=[3;8;m]; >> M=(rref(M))' M= 1.0000 0 1.0000 0 -0.5000 >> x=M(1:2,1:2)\u(1:2) x= >> m=M(3,1:2)*x m= -4 Câu 3: >> V=[1 -1;3 -1;0 -1]; 12 >> syms m >> u=[-3;5;m]; >> V=(rref(V))' V= 1.0000 0 1.0000 0 -0.5000 >> x=V(1:2,1:2)\u(1:2) x= -3 >> m=V(3,1:2)*x m= -2.5 Câu 4: >> U=[1 1;2 -2]; >> syms m >> V=[1 5;3 -1 m]; >> A=[U;V]; >> A(2,:)=A(2,:)-2*A(1,:) A= [ 1, 2, 1, 1] [ 0, -3, -2, -4] [ 1, 5, 3, 5] [ 3, 0, -1, m] >> A(3,:)=A(3,:)-A(1,:) A= [ 1, 2, 1, 1] [ 0, -3, -2, -4] [ 0, 3, 2, 4] [ 3, 0, -1, m] >> A(4,:)=A(4,:)-3*A(1,:) A= [ 1, 2, 1, 1] [ 0, -3, -2, -4] [ 0, 3, 2, 4] [ 0, -6, -4, m - 3] >> A(3,:)=A(3,:)+A(2,:) A= [ 1, 2, 1, 1] [ 0, -3, -2, -4] [ 0, 0, 0, 0] [ 0, -6, -4, m - 3] >> A(4,:)=A(4,:)-2*A(2,:) A= [ 1, 2, 1, 1] [ 0, -3, -2, -4] [ 0, 0, 0, 0] [ 0, 0, 0, m + 5] 13 >> %m=-5 thi U trung V Câu 5: >> syms m >> V=[1 -1 0;2 1;1 m]; >> V(2,:)=V(2,:)-2*V(1,:) V= [ 1, 1, -1, 0] [ 0, 0, 3, 1] [ 1, 1, 2, m] >> V(3,:)=V(3,:)-V(1,:) V= [ 1, 1, -1, 0] [ 0, 0, 3, 1] [ 0, 0, 3, m] >> V(3,:)=V(3,:)-V(2,:) V= [ 1, 1, -1, 0] [ 0, 0, 3, 1] [ 0, 0, 0, m - 1] % m~=1 thi dim(V) max >> V=subs(V,m,1) >> coso=V(1:2,:) coso = [ 1, 1, -1, 0] [ 0, 0, 3, 1] >> sochieu=size(coso,1) sochieu = Câu 6: >> U=[1 0;2 -1 1]; >> syms m >> V=[1 -2 1;2 m]; >> solve(det([U;V])) ans = >> W=rref(subs([U;V],m,0)) W= [ 1, 0, 0, 4/7] [ 0, 1, 0, -1/7] [ 0, 0, 1, -2/7] [ 0, 0, 0, 0] >> coso=W(1:3,:) coso = [ 1, 0, 0, 4/7] [ 0, 1, 0, -1/7] [ 0, 0, 1, -2/7] >> sochieu=size(coso,1) sochieu = Câu 7: >> U=[1 0;-1 -1 2]; 14 >> >> >> >> syms m V=[1 2 2;-1 -1 m]; A=[U;V]; A(2,:)=A(2,:)+A(1,:) A= [ 1, 1, 2, 0] [ 0, 2, 1, 2] [ 1, 2, 2, 2] [ -1, 0, -1, m] >> A(3,:)=A(3,:)-A(1,:) A= [ 1, 1, 2, 0] [ 0, 2, 1, 2] [ 0, 1, 0, 2] [ -1, 0, -1, m] >> A(4,:)=A(4,:)+A(1,:) A= [ 1, 1, 2, 0] [ 0, 2, 1, 2] [ 0, 1, 0, 2] [ 0, 1, 1, m] >> A(3,:)=2*A(3,:)-A(2,:) A= [ 1, 1, 2, 0] [ 0, 2, 1, 2] [ 0, 0, -1, 2] [ 0, 1, 1, m] >> A(4,:)=2*A(4,:)-A(2,:) A= [ 1, 1, 2, 0] [ 0, 2, 1, 2] [ 0, 0, -1, 2] [ 0, 0, 1, 2*m - 2] >> A(4,:)=A(4,:)+A(3,:) A= [ 1, 1, 2, 0] [ 0, 2, 1, 2] [ 0, 0, -1, 2] [ 0, 0, 0, 2*m] >> %dim U giao V la voi moi m >> A=[1 0;0 2;0 -1 2]; >> coso=(null(A,'r'))' coso = -2 -2 Câu 8: >> V=[1 -1 0;0 1 1]; >> coso=null(V,'r') coso = -2 -1 15 -1 -1 0 Câu 9: >> V=[1 1 0;-1 1]; >> coso_phanbuvuonggoc=rref(V) coso_phanbuvuonggoc = 1.0000 0.5000 -0.5000 1.0000 0.5000 0.5000 >> coso_phanbuvuonggoc=2*rref(V) coso_phanbuvuonggoc = 1 -1 Câu 10: >> V=[2 -1 0;-2 1]'; >> x=[1 1]'; >> PrVx=V*inv(V'*V)*V'*x PrVx = 0.1818 -0.0909 0.5455 0.4545 Câu 11: >> V1=[1 1;-1 1]; >> syms m >> V2=[1 -1 m]'; >> V1=(rref(V1))' V1 = 0 -1 >> m=V1(3,:)*inv(V1(1:2,:))*V2(1:2,1) m= -2 Câu 12: >> F=[1 2;2 -1]'; >> x=[1 3]'; >> PrFx=F*inv(F'*F)*F'*x PrFx = 1.3429 1.4286 3.1143 Câu 13: >> A=[1 -1;0 0;-1 3]; >> u=[1 2]; >> v=[2 -1]; >> w=u-v; >> goc_giua_u_v=acos((u*A*v')/(norm(u)*norm(v))) goc_giua_u_v = 16 2.5559 >> khoangcach=sqrt(w*A*w') khoangcach = 5.8310 Câu 14: >> A=[1 -2;0 0;-2 5]; f=[1 3]; >> cs_kgb=null(f*A,'r') cs_kgb = 0.8000 2.6000 1.0000 0 1.0000 Câu 15: >> R3=[1 0;1 1;1 1]; >> R2=[2 -1;1 2;-1 1]; >> A=rref([R3 R2]) A= 0 -2 0 -1 >> syms x1 x2 x3 >> kq=x1*A(1,4:5)+x2*A(2,4:5)+x3*A(3,4:5) kq = [ 2*x2 - x3, x2 - 2*x1 + 3*x3] Câu 16: >> f=[1 -3;2 1]; >> E=[1 1;1 1;1 0]; >> F=[1 3;2 5]; >> A=E\f'; >> P=E\E; >> Q=F\F; >> AEF=P\A*Q AEF = -2 -1 -1 Câu 17: >> A=[1 1;1 2;1 1]; >> B=[1 1;2 -1;5 -1]; >> E=[1 0;0 1;1 1]; >> fE=(A\E)*B*(A\E) fE = -15 -6 12 11 -7 10 -8 Câu 18: >> E=[1 1;1 1;1 0]; >> F=[1 1;2 1]; >> A=[2 -3;0 4]; >> Act=(E'*A'*inv(F'))' 17 Act = -7 -6 Câu 19: >> E=[1 1;1 2;1 1]; >> A=[1 1;2 4;1 3]; >> Act=E'*A*inv(E') Act = 18.0000 -4.0000 -6.0000 20.0000 -4.0000 -7.0000 27.0000 -6.0000 -9.0000 Câu 20: >> E=[1 1;1 2;1 1]; >> A=[1 1;2 4;1 3]; >> F=[1 3;2 5;5 4]; >> P=inv(E')*F'; >> AF=P\A*P AF = 6.5556 4.4444 -24.5556 -5.8889 -4.1111 22.8889 -0.5556 -0.4444 2.5556 Câu 21: >> E=[1 1;1 1;1 0]; >> A=[1 -1;2 3;1 4]; >> Act=E'*A*inv(E') Act = -2 -2 -1 -1 -1 >> imf =rref(Act') imf = 1.0000 0.5000 0 1.0000 0 >> coso=imf(1:2,:) 1.0000 0.5000 0 1.0000 >> chieu=ndims(imf) chieu = Câu 22: >> E=[1 1;1 1;1 0]; >> A=[1 -1;2 3;1 4]; >> Act=E'*A*inv(E') Act = -2 -2 -1 -1 -1 >> ker=(null(Act,'r'))' 18 ker = >> chieu=size(ker,1) chieu = Câu 79: A=input('Nhap vao ma tran A: A='); GTLN=max(max(A)); disp('Phan tu lon nhat cua ma tran A la:'); disp(GTLN); Câu 80: A=input('Nhap vao ma tran A: A='); GTNN=min(min(A)); disp('Phan tu nho nhat cua ma tran A la:'); disp(GTNN); Câu 81: A=input('Nhap vao ma tran A: A='); Tong=sum(sum(A)); disp('Tong cac phan tu cua ma tran A la:'); disp(Tong); Câu 82: A=input('Nhap vao ma tran A: A='); Tich=1; for i=1:size(A,1) for j=1:size(A,2) Tich=Tich*A(i,j); end end disp('Tich cac phan tu cua A la:'); disp(Tich); Câu 83: A=input('Nhap vao ma tran A: A='); Tich=1; for i=1:size(A,1) for j=1:size(A,2) if A(i,j)~=0 Tich=Tich*A(i,j); end end end disp('Tich cac phan tu khac cua A la:'); disp(Tich); Câu 84: A=input('Nhap vao ma tran A: A='); Dem=0; for i=1:size(A,1) for j=1:size(A,2) if A(i,j)~=0 Dem=Dem+1; 19 end end end disp('So phan tu khac cua A:'); disp(Dem); Câu 85: A=input('Nhap vao ma tran A: A='); Dem=0; for i=1:size(A,1) for j=1:size(A,2) if A(i,j)=0 Dem=Dem+1; end end end disp('So phan tu bang cua A:'); disp(Dem); Câu 86: A=input('Nhap vao ma tran A: A='); if size(A,1)~=size(A,2) disp(' Ma tran A khong vuong, khong doi xung'); else disp('A la ma tran vuong'); if A==A' disp('A doi xung'); else disp('A khong doi xung'); end end 20