You are on page 1of 3

1.

YU CU TI
ti 3
Cho ma trn A. Kim tra xem A c vung hay khng. Nu
c, hy tnh nh thc ma trn A bng cch kt hp gia
bin i s cp v khai trin.
Input : Mt ma trn A bt k.

Output :
Ma trn A vung hay khng vung.
Tnh nh thc ca ma trn A trong trng hp ma trn A
vung.
Yu cu : S dng bin i s cp v khai trin.

2. C S L THUYT GII QUYT TI


Gi s ma trn A nhp vo l mt ma trn vung cp n.
Bng cc php bin i s cp theo hng ta a ma trn

vung A v dng bc thang ca n l ma trn B bij . Khi


ta tnh nh thc ca ma trn B bng cch khai trin theo hng
th n thu c : det(B) b11.b22.b33 ...bnn .
Cc php bin i s cp a ma trn A v dng bc
thang bao gm php i ch 2 hng v php kh 1 hng (cng
hng ny vi mt hng khc). Php i ch lm i du nh
thc, cn php kh th khng.
Nu trong qu trnh bin i c n php i ch th :
det(B) (1)n det(A) .

3. THUT TON
Bc 1 : Kim tra tnh vung ca ma trn A nhp vo.
Bc 2 : Nu ma trn A vung, dng phng php kh
theo hng A v dng bc thang.
Bc 3 : Tm s ln i ch 2 hng trong qu trnh bin i
v tch cc phn t trn ng cho ca ma trn bc thang.
Bc 4 : Xut kt qu.
TRANG 1

4. NI DUNG ON CODE
clear all
clc
A=input('Nhap ma tran A = ')
[m,n]=size(A);
if m~=n % Kim tra tnh vung ca ma trn A
disp('Ma tran A nhap vao phai VUONG');
else
r=1;
c=1;
while r<=(m-1) % a A v ma trn bc thang
for i=r:m
if abs(A(i,c))>0.0001
X=A(r,:);
A(r,:)=A(i,:);
A(i,:)=X;
for i=(r+1):m
A(i,:)=A(i,:)-A(i,c)/A(r,c)*A(r,:);
end
break
end
end
r=r+1;
c=c+1;
end
s=0;
for i=1:m % Tm s ln s i ch 2 hng
if all(A(:,i)==0)==1 & all(A(:,i)~=0)==1
s=s+1;
end
end
D=1/(-1)^(s); % nh thc D bng tch cc phn t trn
ng cho chnh chia cho (-1)^s
for i=1:m
D=D*A(i,i);
end
disp(['Dinh thuc cua ma tran A : det(A) =
',num2str(D)]);
end

TRANG 2

5. MT S B TEST
B test 1
>> Nhap ma tran A = [8 6 1 2 ; 22 8 -4 -5 ; 0
15 7 2 ; -2 1 4 9]
A =
8
6
1
2
22
8
-4
-5
0
15
7
2
-2
1
4
9
Dinh thuc cua ma tran A : det(A) = -404

Kim tra kt qu
>> det([8 6 1 2 ; 22 8 -4 -5 ; 0 15 7 2 ; -2 1
4 9])
ans = -404.0000

B test 2
Nhap ma tran A = [0 0 -sqrt(3) ; -1 0 2 ; 0
sqrt(2) -2]
A =
0
0
-1.7321
-1.0000
0
2.0000
0
1.4142
-2.0000
Dinh thuc cua ma tran A : det(A) = 2.4495

Kim tra kt qu
>> det([0 0 -sqrt(3) ; -1 0 2 ; 0 sqrt(2) -2])
ans = 2.4495

B test 3
Nhap ma tran A = [1+2*i -1 ; i 3*i]
A =
1.0000 + 2.0000i -1.0000
0 + 1.0000i
0 + 3.0000i
Dinh thuc cua ma tran A : det(A) = -6+4i

Kim tra kt qu
>> det([1+2*j -1 ; j 3*j])
ans = -6.0000 + 4.0000i
TRANG 3