Last active
January 31, 2021 01:19
-
-
Save hoang-himself/d73c555de9873f1d3f8bf604d6e0b930 to your computer and use it in GitHub Desktop.
Assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear; clc; | |
n_dim = input('Nhap so chieu: '); | |
n_vector = input('Nhap so vecto: '); | |
if n_dim == 0 || n_vector == 0 | |
clc; | |
disp('Ma tran khong hop le'); | |
return; | |
end | |
F = zeros(n_dim, n_vector); | |
for i = 1:n_vector | |
clc; | |
disp(['Vecto ' num2str(i) ': ']); | |
for j = 1:n_dim | |
F(j,i) = input(['Nhap toa do ' num2str(j) ': ']); | |
end | |
end | |
clc; | |
F = F(:, 1:rank(F)); | |
B = null(F'); | |
ort_dim = rank(B); | |
[m, n] = size(B); | |
length = zeros(1, n); | |
if ort_dim == 0 | |
disp('Orthogonal basis: {(0, 0, 0)}'); | |
disp('Orthonormal basis: {(0, 0, 0)}'); | |
return; | |
end | |
for i = 1:n | |
for j = 1:n_dim | |
length(i) = length(i) + B(j,i) * B(j,i); | |
end | |
length(i) = sqrt(length(i)); | |
end | |
prompt1 = "Orthogonal basis: {("; | |
prompt1 = prompt1 + num2str(B(1,1)); | |
for j = 2:n_dim | |
prompt1 = prompt1 + [', ' num2str(B(j,1))]; | |
end | |
prompt1 = prompt1 + ')'; | |
for i = 2:ort_dim | |
prompt1 = prompt1 + [', (' num2str(B(1, i))]; | |
for j = 2:n_dim | |
prompt1 = prompt1 + [', ' num2str(B(j,i))]; | |
end | |
prompt1 = prompt1 + ')'; | |
end | |
prompt1 = prompt1 + '}'; | |
prompt2 = "Orthonormal basis: {("; | |
prompt2 = prompt2 + num2str(B(1,1) / length(1)); | |
for j = 2:n_dim | |
prompt2 = prompt2 + [', ' num2str(B(j,1) / length(1))]; | |
end | |
prompt2 = prompt2 + ')'; | |
for i = 2:ort_dim | |
prompt2 = prompt2 + [', (' num2str(B(1, i) / length(i))]; | |
for j = 2:n_dim | |
prompt2 = prompt2 + [', ' num2str(B(j,i) / length(i))]; | |
end | |
prompt2 = prompt2 + ')'; | |
end | |
prompt2 = prompt2 + '}'; | |
disp(prompt1); | |
disp(prompt2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment