필터 지우기
필터 지우기

Using a variable vector in a loop

조회 수: 1 (최근 30일)
FW
FW 2021년 12월 3일
댓글: FW 2021년 12월 4일
Hello, I am trying to use a large number of vectors (up to 60) for orthogonalization. Say, we have column vectors, v1, v2, v3,..., vk. To orthogonalize them using the standard method, one can proceed with
u1=v1;
u2=v2-[dot(v2,u1)/dot(u1,u1)]*u1;
u3=v3-[dot(v3,u1)/dot(u1,u1)]*u1-[dot(v3,u2)/dot(u2,u2)]*u2;
and so on. However, I want to use the generalized formula when the number of vectors gets large.
What would be best way to implement the above general formula rather? I was wondering if a "for" loop might work, as follows, but how to define vk? I get an error. vk undefined. Thanks.
for k=1:60;
j=1:k-1;
uk=0;
uk=GS+vk-[dot(vk,uj)/dot(uj,uj)]*uj;
end

채택된 답변

James Tursa
James Tursa 2021년 12월 3일
Suppose you store the column vectors in a matrix called V. Then vk would simply be V(:,k). And if the uj are stored in a matrix U as well, then each uj would be U(:,j). So taking your code and replacing these, along with coding the inner part as a loop, would be something like:
V = your matrix of vk column vectors
[m,n] = size(V);
U = zeros(m,n);
for k=1:n
p = zeros(m,1);
for j=1:k-1
p = p + (dot(V(:,k),U(:,j))/dot(U(:,j),U(:,j))) * U(:,j);
end
U(:,k) = V(:,k) - p;
end
  댓글 수: 1
FW
FW 2021년 12월 4일
Thank you. I will try this approach. I gather that the columns of U will be populated in each cycle? We need to generate orthogonal uk vectors from given vk vectors.

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

추가 답변 (1개)

Matt J
Matt J 2021년 12월 4일
You should not use the classical Gram-Schmidt procedure, as it is numerically unstable. Use orth() instead.
  댓글 수: 2
FW
FW 2021년 12월 4일
편집: FW 2021년 12월 4일
Thanks for letting me know about the orth option. I will try both.
FW
FW 2021년 12월 4일
The output of the orth is completely different from the classical GS. However the vectors are orthonormal.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by