Topic 2 Report Class Cc06 - Group 8

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

VIETNAM NATIONAL UNIVERSITY HO CHI MINH CITY

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY


FACULTY OF APPLIED SCIENCE


TOPIC 2 REPORT
CLASS CC06 – GROUP 8

SUBJECT:
LINEAR ALGEBRA
Instructor: Đậu Thế Phiệt
Student ID
Nguyễn Quang Khởi 2153485
Nguyễn Tấn Huy 2252258
Lê Bửu Khang 2053626
Phan Minh Quân 2150007

1
TABLE OF CONTENTS

QUESTION 1: ………………………………………………………………………………3

QUESTION 2: ………………………………………………………………………………7

QUESTION 3: ………………………………………………………………………………11

2
Question 1:
a) The theory and algorithm

-The cryptogram encrypted by a 2x2 matrix is:

5 2 25 11 -2 -7 -15 -15 32 14 -8 -13 38 19 -19 -19 37 16

-Let the decoding matrix be:

𝑎 𝑏
𝐴=[ ]
𝑐 𝑑

-It is given that _ S U E = 0 19 21 5

𝑎 𝑏
=>[−19 − 19] [ ] = [0 19]
𝑐 𝑑
[37 16] [𝑎 𝑏 ] = [21 5]
𝑐 𝑑

-Performing matrix multiplication on these matrices, we can find a system of equations:

-19a – 19c = 0
-19b – 19d = 19
37a +16c = 21
37b + 16d = 5

-The augmented matrix for this system:

-The reduced row-echelon form:

3
-We can see that this is in reduced row-echelon form with the solution;

-Grouping the message into twos:

[5 2][25 11][-2 -7][-15 -15][32 14][-8 -13][38 19][-19 -19][37 16]

-Use the matrix A to decode the message:

4
-The decoded message is:

=>CANCEL_ORDERS_SUE

b) The Matlab or Python commands

clc; %clear screen


X =[5 2; 25 11; -2 -7; -15 -15; 32 14; -8 -13; 38 19; -19 -19; 37 16]; %encrypted message
SUE =[0 19; 21 5]; %decrypted _SUE
key =zeros(2,2); %2x2 key matrix variable
encryptSUE = X(8:9,:); %encrypted _SUE
key =inv(encryptSUE)*SUE; %find the key matrix
message =X*key; %decrypt the message with key
disp(message); %display message, answer: CANCEL_ORDERS_SUE

c) The results and conclusion

- The message is “CANCEL_ORDERS_SUE”

5
Question 2:
a) The theory and algorithm

- Gram–Schmidt_process:

In mathematics, particularly linear algebra and numerical analysis, the Gram–Schmidt process is a method for
orthonormalizing a set of vectors in an inner product space, most commonly the Euclidean space Rn equipped
with the standard inner product. The Gram–Schmidt process takes a finite, linearly independent set of vectors S
= {v1, …, vk} for k ≤ n and generates an orthogonal set S′ = {u1, …, uk} that spans the same k-dimensional
subspace of Rn as S.

The method is named after Jørgen Pedersen Gram and Erhard Schmidt, but Pierre-Simon Laplace had been
familiar with it before Gram and Schmidt. In the theory of Lie group decompositions it is generalized by the
Iwasawa decomposition.

The application of the Gram–Schmidt process to the column vectors of a full column rank matrix yields the QR
decomposition (it is decomposed into an orthogonal and a triangular matrix).

- Orthogonal basis:

In mathematics, particularly linear algebra, an orthogonal basis for an inner product space V is a basis for V
whose vectors are mutually orthogonal. If the vectors of an orthogonal basis are normalized, the resulting basis
is an orthonormal basis.

- Orthonormal basis:

an orthonormal basis for an inner product space V with finite dimension is a basis for V whose vectors are
orthonormal, that is, they are all unit vectors and orthogonal to each other.[1][2][3] For example, the standard
basis for a Euclidean space Rn is an orthonormal basis, where the relevant inner product is the dot product of
vectors. The image of the standard basis under a rotation or reflection (or any orthogonal transformation) is also
orthonormal, and every orthonormal basis for Rn arises in this fashion.

b) The Matlab or Python commands

clear all Creat a square


disp('Each row is a vector, each column is the matrix
element of the vector')
x=input('Enter the number of vectors ');
y=input('Enter the number of elements : ');
for r=1:x
for c=1:y
fprintf('Enter the value in row %d
column %d\n',r,c);
M(r,c)=input('');
end
end

6
if rank(M)<x
error('your span must be LI');
end
V=M'
matrix_size=size(V); Apply Gram-
m=matrix_size(1,1); Schmidt process’s
n=matrix_size(1,2); formula
u=zeros(m,n);
u(:,1)=V(:,1);
for k=2:n
S=V(:,k);
for j=1:(k-1)
S=S-
(dot(V(:,k),u(:,j))/dot(u(:,j),u(:,j)))*u(:,j);
end
u(:,k)=S
end
t=zeros(m,n);
for j=1:n
normalized_factor= norm(u(:,j))
for i=1:m
s=u(i,j)/normalized_factor
t(i,j)=s
end
end

disp('Orthogonal') Display the result


disp (u);
disp('Orthonormal')
disp (t)

c) The results and conclusion.

-Conclusion: the codes have one biggest con that is it is unable to generate a set of orthogonal or orthonormal
vectors if the matrix has LD vectors. Therefore, the user has to choose a matrix that its rank equals to the
number of vectors

- The example: matrix 2x2

7
8
9
Question 3:
a) The theory and algorithm

-We can define the given weighted inner product in matrix form as:
〈𝑥, 𝑦〉 = (𝑥1 𝑥2 ) (𝑎 0) (𝑦1 𝑦2 )𝑇 = 𝑥𝑀𝑦 𝑇
0 𝑏
-From the given weighted inner product, we have:
‖𝑢‖ = 〈𝑢, 𝑢〉 = 𝑎𝑢12 + 𝑏𝑢12 with 𝑢 = (𝑢1 𝑢2 )
𝑎 0 𝑢1
or in the matrix form ‖𝑢‖ = 〈𝑢, 𝑢〉 = (𝑢1 𝑢2 ) ( ) ( ) = 𝑢𝑀𝑢𝑇
0 𝑏 𝑢2
-Find out a and b:
𝑎 0 0 𝑎 0 0
(7 0) ( ) ( ) = 1 and (6 0) ( )( ) = 1
0 𝑏 7 0 𝑏 7
or ‖(7, 0)‖ = 𝑎 × (7)2 + 𝑏 × (0)2 and ‖(0, 6)‖ = 𝑎 × (0)2 + 𝑏 × (6)2
′ ′
-Find the reflection of the unit circle about a plane. Assume that we want to find the reflection 𝑥 ′(𝑥1 ,𝑥2) of point
𝑥(𝑥1 , 𝑥2 ) about plane (d): 𝑎𝑥 + 𝑏𝑦 + 𝑐 = 0.
We determine basis 𝐸 = {𝑒1 , 𝑒2 } of 𝑅 2, where e1 is the vector that goes along (d) and e2 is perpendicular to (d)
𝑒1 𝑀𝑒2 = 0 ⟺ 𝑒2 = 𝑛𝑢𝑙𝑙(𝑒1 𝑀) = (𝑚, 𝑛)
-Let (x0, y0) be the orthogonal projection of x on (d). This is equivalent to:
𝑎𝑥0 + 𝑏𝑦0 + 𝑐 = 0
(𝑥0 , 𝑦0 ) ∈ (𝑑)
{ ⇔ { 𝑥0 − 𝑥 − 𝑘𝑚 = 0
(𝑥0 , 𝑦0 ) − (𝑥, 𝑦) = 𝑘𝑒2
𝑦0 − 𝑦 − 𝑘𝑚 = 0
-From the above system, we may find x0 , y0 and k with respect to x, y. In general:
𝑥0 𝑜 𝑜 𝑥 𝑜
(𝑦 ) = ( )( ) +( )
0 𝑜 𝑜 𝑦 𝑜
This means that:
𝑥 𝑥0
(𝑦) = 𝐴−1 ((𝑦 ) − 𝑏) (2)
0
-Express x and y via x0 and y0. In order to find the reflection of the unit circle, we replace x and y by the
equivalent expressions of x0 and y0.

b) The Matlab or Python commands

syms a b k x y x0 y0 xr yr;
syms C(x,y) C_reflection(x,y);
syms A B [1 2] matrix;
syms X Y [1 2] matrix;
M = [a 0; 0 b];
f = symfunmatrix(X*M*transpose(Y), {X,Y});
A = input("The coordinate of A = ");
B = input("The coordinate of B = ");
Z = input("Input the plane (d): ax + by + c = 0 => [a b c] = ");
eqns = [symmatrix2sym(f(A,A))==1, symmatrix2sym(f(B,B))==1];
S = solve(eqns, [a b]);
fprintf("a = %.4f \n", S.a)

10
fprintf("b = %.4f \n", S.b)
M = subs(M , [a, b], [S.a, S.b]);
fimplicit(S.a*(x^2) + S.b*(y^2) == 1, [-10 10 -10 10], ':','LineWidth', 3)
hold on
if (Z(1,1)==0)
syms yG(x);
yG(x) = -Z(1,3)/Z(1,2);
fplot(yG(x))
else
fimplicit(Z(1,1)*x + Z(1,2)*y + Z(1,3) == 0, '--')
end
C = S.a*(x^2) + S.b*(y^2);
e1 = transpose(null([Z(1,1) Z(1,2)],'rational'));
e2 = transpose(null(e1*M));
eqns=[Z(1,1)*x0 + Z(1,2)*y0 + Z(1,3) == 0, x0 - x - k*e2(1,1) == 0, y0 - y - k*e2(1,2) ==
0];
S = solve(eqns, [x0 y0 k]);
eqn = [S.x0 S.y0] - [xr yr] == [x y] - [S.x0 S.y0];
R = solve(eqn, [xr yr]);
[A,b] = equationsToMatrix([R.xr==0, R.yr==0], [x,y]);
T = inv(A)*([x;y]+b);
C_reflection = subs(C, [x,y], [T(1,1), T(2,1)]);
fimplicit(C_reflection == 1)

c) The results and conclusion.

-The generated results are shown in these figures, with the unit circle is plotted with the dotted style, line (d) is
dotted with the dashed style and the reflection of the unit circle is plotted with the regular style A B (d).

- The example: [9 0] [0 16] [2 4 5]

- The example: [5 0] [0 2] [2 7 8]

11
- The example: [36 0] [0 25] [1 1 0]

12

You might also like