TP-calcul-scientifique/TP1/cgs.m
2023-06-10 21:24:30 +02:00

30 lines
666 B
Matlab
Executable file

%--------------------------------------------------------------------------
% ENSEEIHT - 1SN - Calcul scientifique
% TP1 - Orthogonalisation de Gram-Schmidt
% cgs.m
%--------------------------------------------------------------------------
function Q = cgs(A)
% Recuperation du nombre de colonnes de A
[~, m] = size(A);
% Initialisation de la matrice Q avec la matrice A
Q = A;
% algo
Q(:,1) = Q(:,1) / norm(Q(:,1));
for j = 2:m
%projs = A(:,1:j-1)*A(:,1:j-1).'*A(:,j);
projs = Q(:,1:j-1)*Q(:,1:j-1).'*A(:,j);
Q(:,j) = Q(:,j) - projs;
Q(:,j) = Q(:,j) / norm(Q(:,j));
end
end