31 lines
654 B
Matlab
Executable file
31 lines
654 B
Matlab
Executable file
%--------------------------------------------------------------------------
|
|
% ENSEEIHT - 1SN - Calcul scientifique
|
|
% TP1 - Orthogonalisation de Gram-Schmidt
|
|
% mgs.m
|
|
%--------------------------------------------------------------------------
|
|
|
|
function Q = mgs(A)
|
|
|
|
% Recuperation du nombre de colonnes de A
|
|
[~, m] = size(A);
|
|
|
|
% Initialisation de la matrice Q avec la matrice A
|
|
Q = A;
|
|
|
|
% Algo
|
|
|
|
for j = 1:m
|
|
|
|
for k = 1:j-1
|
|
|
|
proj = Q(:,k).'*Q(:,j)*Q(:,k);
|
|
|
|
Q(:,j) = Q(:,j) - proj;
|
|
|
|
end
|
|
|
|
Q(:,j) = Q(:,j) / norm(Q(:,j));
|
|
|
|
end
|
|
|
|
end |