Hiya,
I’m trying to understand how to carry out the gram Schmidt algorithm when you have an unknown number of vectors n.
Any help would be appreciated.

 채택된 답변

David Hill
David Hill 2020년 4월 29일

0 개 추천

V is matrix input where vectors are column vectors. Output U is matrix with replacement vectors as column vectors.
n = size(V,1);
k = size(V,2);
U = zeros(n,k);
U(:,1) = V(:,1)/sqrt(V(:,1)'*V(:,1));
for i = 2:k
U(:,i) = V(:,i);
for j = 1:i-1
U(:,i) = U(:,i) - ( U(:,j)'*U(:,i) )/( U(:,j)'*U(:,j) )*U(:,j);
end
U(:,i) = U(:,i)/sqrt(U(:,i)'*U(:,i));
end

댓글 수: 4

Kai Whelan
Kai Whelan 2020년 4월 29일
When I run this code for the output U I don’t get the correct values for the first column ?
David Hill
David Hill 2020년 4월 29일
I believe it is correct. Do you have an example showing it does not work?
Kai Whelan
Kai Whelan 2020년 4월 29일
All good now thanks.
nice job , thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2020년 4월 29일

댓글:

2021년 3월 18일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by