Tải bản đầy đủ (.pdf) (20 trang)

(Tiểu luận) group assignments given a linear transformation as below, find the f dimension and one basic of im( )

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (979.48 KB, 20 trang )

VIETNAM NATIONAL UNIVERSITY HO CHI MINH CITY
UNIVERSITY OF TECHNOLOGY
FACULTY OF APPLIED SCIENCE
-------------***----------------

Linear Algebra (MT1008)

Group Assignments
Topic: 1
Group: 9
Team members:
1. Trần Quốc Thái - 2153795
2. Bùi Văn Nhật Thanh - 2152280
3. Hà Huy Thành - 2152967
4. Lê Thành - 2052706
5. Trịnh Hoài Thanh - 2053427

Semester: HK212
Lecturer: Phan Thi Huong
Submission date: Saturday, May 14th, 2022

1

0

0

Tieu luan


REQUIREMENTS:


● Students work on your assigned groups.
● Detailed explanations must be provided to get full scores.
● To solve the following questions, please let the constant a be your group ID.
● All given exercises must be done by both methods: manual solving and
using Matlab or Python.
TABLE OF CONTENT
Project details for each question:
I. Theories summary.
II. Solution details.
III. Coding details.
Question 1: Given a linear transformation f as below, find the dimension and one
basic of Im(f):
f(x1,x2,x3) = (x1 + x2;x2 + x3;x1 - ax3), (a = 9).
I. Theory:
The set of all vectors in F that are images under f of at least one vector in E is
called the range of f:
() = {ỵ : ý , ỵ = (ý)} = ()
If f: E ↦ F is a linear transformation, then: Im(f) of f is a subspace of f.
II. Solution details:
1. Manual solving:

2. MATLAB code and explanation:
a. Coding details:
clc;
syms e1 e2 e3
%y=f(x)=x1(e1)+x2(e2)+x3(e3)
%a,b,c are constants
2

0


0

Tieu luan


e1 = input('e1 = [a b c]=');
e2 = input('e2 = [a b c]=');
e3 = input('e3 = [a b c]=');
A = [e1', e2', e3'];
%Find the rank of A
r = rank(A);
%Find basics of Im(f)
if (r == 1)
Basic = [e1];
disp('Basic of Imf = ');disp([e1])
dimImf = 1
elseif (r == 2)
Basic = [e1;e2];
disp('Basic of Imf = ');disp([e1',e2'])
dimImf = 2
elseif (r == 3)
Basic = [e1;e2;e3];
disp('Basic of Imf = ');disp([e1',e2',e3'])
dimImf = 3
end

b. Results:
e1 = [a b c]=[1 0 1]
e2 = [a b c]=[1 1 0]

e3 = [a b c]=[0 1 -9]
Basic of Imf =
1 1 0
0 1 1
1 0 -9
dimImf =

Question 2: Given f : �㕅3 ³ �㕅2 and the matrix representation of f in E = {(1; 1; 1);
3

(1; 0; 1); (1; 1; 0)}, and F = {(1; 1); (2; 1)} is ýỵ =

; find f(1; 2; 9).

I. Theory:

- Every linear transformation from �㕅Ā ³ �㕅 ÿ can be
represented by an m×n matrix. Conversely, every matrix
m×n represents a linear transformation from �㕅Ā ³ �㕅 ÿ ,
i.e, we can always write a linear transformation in the
form
[Ā(ý)]� 㕇 = �㔴ý �㕇
where �㔴ÿ×Ā matrix.
- If we are given vector images of a basis E in �㕅ÿ , that is we
know f(E), then
3

0

0


Tieu luan


Ā(Ā) = �㔴Ā 21
⇔putting
�㔴 =image
Ā(Ā)Ā
where f(E), E are two matrices formed by
vector of basis, vector of basis in column, respectively.
- Let f : �㕅Ā ³ �㕅ÿ be a linear transformation and
Ā = {ÿ1 , ÿ2 , . . . , ÿĀ } be a basis for �㕅Ā , ā = {Ā1 , Ā2 , . . . , ĀĀ } be a
basis for �㕅ÿ . Then

is called the matrix representation of f with respect to E
and F .
ý,ỵ = 21 ()
II. Solution details:

1. Manual solving:

E=
F=
ýỵ =

ý =

*ý,ỵ = 21 () = 21

= ý,ỵ 21 =

[Ā(ý)]�



=

= �㔴ý �㕇 ⇔ f(1;2;9) =

=

2. MATLAB code and explanation:
2.1. MATLAB code:

4

0

0

Tieu luan


2.2. Explanation:
Line 1, 2, 3, 4: Create the matrix E, F, x, AEF respectively.
Line 5: Find the matrix A through the formula A = F × AEF × E-1
Line 6: Find f(1;2;9) by using the formula [f(x)]T = A × xT

Question 3: Let F = {(2; -1; 3); (1; 1; 2); (3; 0; 1); (-1; -4; a)} be a subspace of R3
with the inner product < x; y >= 3x1y1 - x1y2 - x2y1 + 4x2y2 + 4x3y3.
a) Find a basis and the dimension of F⊥.


b) Find the vector projection of w = (3; -2; 1) onto F
I. Theory:
Definition 1:
Two vectors x, y V in an inner product space V is called orthogonal
 <x, y>=0. We denote it by x ⊥ y (x perp y)

Vector x is orthogonal to the set M  V if x is orthogonal to every vector in M.
We denote it by x ⊥ M
5

0

0

Tieu luan


Theorem 1: Vector x is orthogonal to a subspace F if and only if x is orthogonal
with a basic of F.
Definition 2:
A set of two or more vectors in a real inner product space {x1, x2, …, xn} is
called orthogonal  all pairs of distinct vectors in the set are orthogonal.
An orthogonal set in which each vector has norm 1 is said to be orthogonal.
xk = 1, ( k = 1, 2,..., n)

Definition 3: If F is a subspace of a real inner product space V, then the set F⊥ of
all vectors in V that are orthogonal to F is called the orthogonal complement of F.
Theorem 2: Let R be a subspace of a real inner product space V then F⊥ is a
subspace of V, and:

dim F + dim F⊥ = dim V
Scheme of finding F⊥ of a subspace F:
Find a basis of F. Assume that basic of F contains vectors {e1, e2, …, en}
ü
e1 , y = 0 ü
ÿ
ÿ
F = ý( y1 , y2 ,..., y n ) e2 , y = 0 ý

en , y = 0 ỵ



Find the dim and a basic of this null space.
Scheme of finding y = projFx
- Find a basis of F, let it be S = {e1, e2, …, em}.
- Since y  F => y = 1e1 + 2e2 + ...+ mem
- x = y + z, then: y = 1e1 + 2e2 + ...+ mem + z
ü x , e1 = e1 ,e1 1 + e 2 ,e1 2 + ... + e m ,e1 m
ÿ
ÿ x, e2 = e1, e2 1 + e2 , e2 2 + ... + em, e2 m
 y = proj F x = 1e1 + 2e2 +... + mem
ý
ÿ
ÿ x , em = e1 ,em 1 + e2 ,e m 2 + ... + em , em m


II. Solution details:
1. Manual solving:


a) Find a basis and the dimension of F⊥.
ù 3 −1 0 ù
A = úú −1 4 0 úú
úû 0 0 4 úû

Find the rank of the subspace F:
2

0

0

Tieu luan


ù 2 1 3 − 1ù
ù 2 1 3 − 1ù
ù 2 1 3 − 1ù
r2 →2 r2 + r1
r3 → 3 r3 − r2
ú
ú
ú
ú
→ 0 3 3 − 9 ⎯⎯⎯⎯
→ú 0 3 3 − 9ú
F = ú − 1 1 0 − 4ú ⎯⎯⎯⎯
r3 → 2r3 − 3r1
ú
ú

ú
ú
úû 3 2 1 9 úû
úû 0 1 −7 21úû
úû 0 0 − 24 72úû
 r( F ) = 3

 dim F = 3
 dim F ⊥ = 0

A basis of F is S = {(2, -1, 3), (1, 1, 2), (3, 0, 1)}
ư 2 −1 3ư ù 3 − 1 0ù
÷
÷
F = null (SA ) = ÷ 1 1 2 ÷úú − 1 4 0úú  0 = 0
÷ 3 0 1 ÷ ú 0 0 4ú
ø
øû
û

 A basis of F is {(0, 0, 0)}


b) Find the vector projection of w = (3; -2; 1) onto F

Since y  F => y = 1e1 + 2 e2 + ... + m em
ü x, e1 = e1 , e1 1 + e2 , e1 2 + e3 ,e1 3
ÿ
ý x , e2 = e1 ,e2 1 + e2 ,e2 2 + e3 ,e 2 3
ÿ x , e = e ,e  + e ,e + e ,e

3
1 3
1
2
3
2
3 3
3

ử x, e1
ưxư
÷
÷ ÷
e1 ÷
e ,e
T T T
÷

A (e1 e2 e3 ) = ÷ 1 1
÷ e 2 , e1
÷e 2 ÷
÷÷
÷ ÷
øe 3 ø
ø e 3 ,e1

x , e3 ö ö 45 8
÷ ÷
e1 ,e 3 ÷ ÷ 56 25
=

e 2 ,e 3 ÷ ÷ 25 21
÷ ÷
e 3 ,e 3 ÷ø ø 33 14

x , e2
e1 , e 2
e 2 ,e 2
e 3 ,e 2

37 ư
÷
33 ÷
14 ÷
÷
31 ø

5
ü
ÿ 1 = 6
ü 45 = 561 + 25 2 + 33 3 ÿ
−7
ÿ
ÿ
 ý 8 = 251 + 212 + 143 ý2 =
6
37 = 33 +14 + 31


1
2

3

5
3 = 6

y = proj Fx = 1e1 + 2 e2 + 3e3 = (3, −2,1)

2. MATLAB code and explanation:
a. Coding details:
clc;
syms x y z
A =[3 -1 0;-1 4 0; 0 0 4];
%Input the matrix of spanning set of F
e1 = [2 -1 3];
e2 = [1 1 2];
e3 = [3 0 1];
e4 = [-1 -4 9];
F = [e1;e2;e3;e4]'
r = rank(F)
if (r == 1)
S = e1
elseif (r == 2)
3

0

0

Tieu luan



S = [e1;e2]
elseif (r == 3)
S = [e1;e2;e3]
end
%Input the matrix of the inner product
%Fo: Orthogonal F
Fo =(S')*A
kerf=null(Fo);
dimFo = size(ker,2)
% b)Find the vector projection of w = (3; -2; 1) onto F
x = [3;-2;1];
E = [dot(e1,e1) dot(e1,e2) dot(e1,e3); dot(e2,e1) dot(e2,e2) dot(e2,e3); dot(e3,e1)
dot(e3,e2) dot(e3,e3)]
D = [dot(x,e1); dot(x,e2) ; dot(x,e3)];
X = mldivide(sym(E), sym(D)) ;
fprintf('The projection of w onto F: ')
(X(1,1)*e1 + X(2,1)*e2 + X(3,1)*e3)

b. Results:
F=
2
-1
3

1
1
2

3 -1

0 -4
1 9

r=
3
S=
2 -1
1 1
3 0
Fo =
5 2
-4 5
7 5
dimFo =
0
E=
14 7
7 6
9 5

3
2
1
12
0
4

9
5
10


The projection of w onto F:
ans=
[ 3, -2, 1]
4

0

0

Tieu luan


Question 4: Determine the currents I1, I2, I3 and for the given electrical network.

3 2 4�㔼1 2 3�㔼2 = 0
4�㔼1 + 3�㔼2 = 3 ³ (1)
4 2 1�㕅3 2 3�㔼2 = 0
�㕅3 + 3�㔼2 = 4 ³ (2)
3 2 4�㔼1 + 1�㕅3 2 4 = 0
4�㔼1 2 �㕅3 = 1 ³ (3)
Eauation (1), (2) & (3) in matrix form as,
4 3 0 3
[0 3 1 4]
4 0 21 1
´ �㕅3 ³ �㕅3 2 �㕅1
4 3 0 3
[0 3 1
4]
0 3 21 22

´ �㕅3 ³ �㕅3 + �㕅2
4 3 0 3
[ 0 3 1 4]
0 0 0 2
´ �㕅3 ³ �㕅3 × 0
4 3 0 3
[ 0 3 1 4]
0 0 0 0
3�㔼2 + �㔼3 = 4
3�㔼2 = 4 2 �㔼3
4�㔼3
�㔼2 =2
3 3
1. Solution:

Substitute �㔼2 in (1)

4�㔼1 = 3 2 3�㔼2

0

4�㔼01 + 3�㔼2 = 3

Tieu luan

5


4 2 ]�㔼3
4�㔼

=
3
2
3
[
1
4�㔼1 = 3 2 43+ �㔼3
4�㔼1 = 21 + �㔼3
1
4 3
�㔼1 = 2 �㔼
Dependent solution if �㔼3 = 1 ỵ 4 +
1 = 0 ỵ
2 = 1 ỵ
If 3 = 2 amp
1

1 =
4
2
2 =ỵ
3
2. Matlab
a) The code:
function ex3
clc, clear, close all;
disp('Solve the systems AX = B using gaussian elimination');
n = input('Input number of equations n = ');
k = input('Input number of variables k = ');
result = zeros(0,0);

disp('Example for input equation: [1 2 3 4] means x1 + 2*x2 + 3*x3 = 4');
for i = 1:n
T = input([ 'Input equation ' num2str(i) ' : ']);
result = [result; T];
end
disp('The system of equations :'); disp(result);
for i = 1:(n-1)
disp('-----------------------------------------------');
disp(['Step ' num2str(i)]);
for j = (i+1):n
if result(i,i) == 0
6

0

0

Tieu luan


temp = result(j,:);
result(j,:) = result(i,:);
result(i,:) = temp;
else
result(j,:) = result(j,:) -(result(j,i)/result(i,i))*result(i,:);
end
end
disp(result);
disp('Press Enter to continue');
pause;

end
disp('-----------------------------------------------');
A = result(:,1:k);
rresult = 0; rA = 0;
for i = 1:n
for j = 1:(k+1)
if abs(result(i,j)) > 0.0001
rresult = rresult + 1;
break;
end
end
end
for i = 1:n
for j = 1:k
if abs(A(i,j)) > 0.0001
rA = rA + 1;
break;
end
7

0

0

Tieu luan


end
end
if rresult ~= rA

disp('No solution !');
elseif rresult == rA
if rresult == n
disp('Unique Solution');
x = zeros(k,1);
for s = 1:n
i = n+1-s;
sum = 0;
for j = (i+1):k
sum = sum + result(i,j)*x(j);
end
x(i) = (result(i,k+1) - sum)/result(i,i);
end
disp('Solution: ');disp(x);
else
disp('Infinity Solution');
disp([num2str(k - rresult) ' free variable']);
end
end
end

b) On the screen:

8

0

0

Tieu luan



Question 5: Generate a random matrix A which has the size of 4 ×4 and is
diagonalizable.
Then, return its eigenvalues, the corresponding eigenvectors and compute A100.
I.
Theories summary
1. What is a diagonalizable matrix?
A square matrix is said to be diagonalizable if it is similar to a diagonal matrix.

That is, A is diagonalizable if there is an invertible matrix P and a diagonal matrix
D such that A=PDP-1
2. What are eigenvalues and the corresponding eigenvectors of a matrix?
Many problems present themselves in terms of an eigenvalue problem:
�㔴. �㕣 = �㔆. �㕣
In this equation A is an n-by-n matrix, v is a non-zero n-by-1 vector and λ is a
scalar (which may be either real or complex). Any value of λ for which this
equation has a solution is known as an eigenvalue of the matrix A. It is sometimes
also called the characteristic value.
9

0

0

Tieu luan


The vector, v, which corresponds to this value is called an eigenvector. The
eigenvalue problem can be rewritten as:


�㔴. �㕣 2 �㔆. �㕣 = 0
�㔴. �㕣 2 �㔆. �㔼. �㕣 = 0
(�㔴 2 �㔆. �㔼). �㕣 = 0
If v is non-zero, this equation will only have a solution if
|�㔴 2 �㔆. �㔼| = 0
This equation is called the characteristic equation of A, and is an nth order
polynomial in λ with n roots. These roots are called the eigenvalues of A. We will
only deal with the case of n distinct roots, though they may be repeated. For each
eigenvalue there will be an eigenvector for which the eigenvalue equation is true.
This is most easily demonstrated by example:
Find Eigenvalues and Eigenvectors of a 2x2 Matrix
0
1
�㔴 = [
]
22 23
Then the characteristic equation is

1 0
|�㔴 2 �㔆. �㔼| = | []02 [�㔆
]|=0
22 23
0 �㔆
2�㔆
1
]| = �㔆2 + 3�㔆 + 2 = 0
|[
22 23 2 �㔆
�㔆1 = 21

And the two eigenvalues are:
{
�㔆2 = 22
All that's left is to find the two eigenvectors. Let's find the eigenvector, �㕣1 ,
associated with the eigenvalue, λ1=-1, first.
�㔴. �㕣1 = �㔆. �㕣1
(�㔴 2 �㔆1 ). �㕣1 = 0
2�㔆1
1
[
] . �㕣1 = 0
22 23 2 �㔆1
1
1 �㕣1,1
1
1
] . [ �㕣 ] = 0
] . �㕣1 = [
[
22 22
1,2
22 22
so clearly from the top row of the equations we get
�㕣1,1 + �㕣1,2 = 0 ý�㕟 �㕣1,1 = 2�㕣1,2
Note that if we took the second row we would get
(22). �㕣1,1 + (22). �㕣1,2 = 0 ý�㕟 �㕣1,1 = 2�㕣1,2
In either case we find that the first eigenvector is any 2 element column vector in
which the two elements have equal magnitude and opposite sign
+1
�㕣1 = �㕘1]. [

21
where k1 is an arbitrary constant. Note that we didn't have to use +1 and -1, we
could have used any two quantities of equal magnitude and opposite sign.
Going through the same procedure for the second eigenvalue:
�㔴. �㕣2 = �㔆. �㕣2
2�㔆2
1
2
1�㕣2,1
(�㔴 2 �㔆2 ). �㕣2= [
] . �㕣2 = [
] . [ �㕣 ] = 0
22 23 2 �㔆2
2,2
22 21
So
2. �㕣2,1 + 1. �㕣2,2 = 0
2. �㕣2,1 = 2�㕣2,2
If

10

0

0

Tieu luan


+1

Again, the choice of +1 and -2 for�㕣
the eigenvector
was arbitrary; only their ratio is
2 = �㕘2]. [
22
important. This is demonstrated in the MatLab code below.

3. The application of diagonal matrix
Diagonal matrices are relatively easy to compute with, and similar matrices share
many properties, so diagonalizable matrices are well-suited for computation.
In particular, many applications involve computing large powers of a matrix,
which is easy if the matrix is diagonal. But if A=PDP-1, then
�㔴Ā = (�㕃ÿ�㕃21 )Ā = (�㕃ÿ�㕃21 )(�㕃ÿ�㕃21 )(& )(�㕃ÿ�㕃21) = �㕃ÿ
because the �㕃21 �㕃 terms in the middle all collapse.
4. Solution details

1 2 3 4
2 4 5 2
]
Choose the matrix �㔴 = [
4 2 1 4
2 3 4 5
1 0 0 0
0 1 0 0
The unit matrix is �㔼 = [
]
0 0 1 0
0 0 0 1
Then we have
|�㔴 2 �㔆. �㔼| = 0

So that
1 0 0 0
1 2 3 4
|[ 2 4 5 2] 2 �㔆.0[ 1 0 0]| = 0
4 2 1 4
0 0 1 0
2 3 4 5
0 0 0 1

11

0

0

Tieu luan


1 22
4�

|[
Solve this equation we have:

4㔆
2�
2


122 �


5
3


2
4
4
]| = 0

�㔆31 = 12.2111
4
5 2 �㔆
�㔆2 = 22.2111
�㔆3 = 1.0000
�㔆4 = 0.0000
1 2 3 4
2 4 5 2]
,which are the eigenvalues of the matrix �㔴 = [
4 2 1 4
2 3 4 5
20.4234
20.5217
]
With �㔆1 = 12.2111 the eigenvector is [
20.4531
20.5858
2

20.2156

20.5249
With �㔆2 = 22.2111 the eigenvector is [
]
20.8059
20.1688
20.3455
0.7775
With �㔆3 = 1.0000 the eigenvector is [
]
20.5183
0.0864
0.2641
20.8805
]
With �㔆4 = 0.0000 the eigenvector is [
0.3522
0.1761

20.4234 20.2156 20.3455 0.2641
20.5217 20.5249 0.7775 20.8805
So we have �㕃 = [
] and
20.4531 20.8059 20.5183 0.3522
20.5858 20.1688 0.0864
0.1761
12.2111
0
0
0
0

22.2111
0
0
]
ÿ=[
0
0
0.0000
0
0
0
0
1.0000
Then �㔴100 = �㕃ÿ100 �㕃21 =
20.4234 20.2156 20.3455 0.2641
12.2111
0
0
22.2111
20.5217 20.5249 0.7775 20.8805
[
][
0
0
20.4531 20.8059 20.5183 0.3522
0
0
20.5858 20.1688 0.0864
0.1761


0
0
0.0000
0

10
0
0
]
0
1.0000

12

0

0

Tieu luan


20.4234
5217 20.2156
5249 0.7775 20.8805
20.
20.4531 20.
20.8059 20.3455
20.5183 0.2641
0.3522 21
[

]
0.9375 0.9008
1.1102 1.0535
1.2984
0.7607
0.8142 0.9642 1.1276
108
20.5858 20.
1688
0.1761
= 10
. [ 0.0864
1.0526 1.2466 1.4578
5. Coding details
a. Full MATLAB code:

1.5481
1.
2562
1.3446
]
1.7383

%Clear all text from the Command Window
clear all;
clc;
%Input the matrix 4x4 that we need to use in this problem
A=input('Enter the matrix A: ')
%Check the matrix if it is already diagonal?
check=isdiag(A);

if check==true
disp('The matrix is already diagonal');
%Calculate A power 100.
fprintf('A power of 100 = A^100:')
A100 = A^100;
ANSWER = real(A100)
else
F=size(A,1);
%Check the matrix whether it is diagonalizable or not?
syms lambda
I = eye(F);
lambda1 = solve(det(A - I*lambda)==0);
numrows=size(lambda1,1);
V=[];
for i = 1:numrows
v = null(A-lambda1(i,1)*I);
V=[V,v];
end
13

0

0

Tieu luan


B=transpose(V);
C=rank(B);
E=size(B,1);


if C==F
disp("The matrix is diagonalizable")
p =poly(A);
eigs = roots(p);
M=[];
for i=1:4
m= eigs(i);
M=[M,m];
end
disp("The eigenvalues are:")
disp(M)
%Show the output of the problem: V is the matrix concluding all
%eigenvectors and D is a diagonal matrix with eigenvalues located on the
%main diagonal.
fprintf('Eigenvectors are:\n')
[V,D] = eig(A)
%Calculate A power 100.
fprintf('A power of 100 = V*D^100*inv(V):')
A100 = V*D^100*inv(V);
ANSWER = real(A100)
else
%Ask the user to input another matrix
disp("The matrix is not diagonalizable. Let's try another matrix")
end
end

b. Results and explanation:
If we input a diagonal matrix, this code will help us to find �㔴100 directly:


14

0

0

Tieu luan


c.
Note: The result is strange because it is too big to display in decimal
number

1 2 3 4
2 4 5 2
], we will get eigenvalues:
When we input a vector �㔴 = [
4 2 1 4
2 3 4 5
�㔆1 = 12.2111
�㔆2 = 22.2111
�㔆3 = 1.0000
�㔆4 = 0.0000
Also, the eigenvectors are concluded in vector
20.4234 20.2156 20.3455 0.2641
20.5217 20.5249 0.7775 20.8805
�㕉 = [
]
20.4531 20.8059 20.5183 0.3522
20.5858 20.1688 0.0864

0.1761
The result of �㔴100 is shown in Figure 1

15

0

0

Tieu luan


1
2 2
However, if we input a matrix that is not diagonalizable �㔴 = [
3 8
6 9
The result will be:
FIGURE 1

2
6
4
4

3 6
2
]
6
1


16

0

0

Tieu luan



×