フィルターのクリア

Create the program to return the orthogonal basis and orthonormal basis

91 ビュー (過去 30 日間)
Nguyet Nguyen
Nguyet Nguyen 2022 年 8 月 13 日
編集済み: Torsten 2022 年 8 月 14 日
Write a program to input any number of vectors in R^n and return return the orthogonal basis and orthonormal basis of the subspace spanned by these vectors using Gram Schmidt process. Can someone check if I do right
for j= 1:n
v = A (: , j) ;
for i = 1: j-1
R(i,j) = Q (:, i )' * A ( :, j) ;
v = v - R ( i ,j ) * Q ( :, i);
end
R ( j, j ) = norm ( v );
Q (:, j) = v/R ( j, j ) ;
end

採用された回答

Torsten
Torsten 2022 年 8 月 13 日
編集済み: Torsten 2022 年 8 月 13 日
As far as I can see, you only return the orthonormal basis from the Gram Schmidt process in the matrix Q.
And saving the norms is superfluous if you have to return the orthonormal basis, too.
n = 2;
A = [1 3; 4 -7; -1 -12];
Q = zeros(size(A));
QN = zeros(size(A));
for j= 1:n
v = A (:,j) ;
for i = 1: j-1
rij = Q(:,i).' * A(:,j) / (Q(:,i).' * Q(:,i));
v = v - rij * Q(:,i);
end
Q(:,j) = v;
QN(:,j) = v/norm(v);
end
sqrt(Q.'*Q)
ans = 2×2
4.2426 0 0 13.8784
QN.'*QN
ans = 2×2
1.0000 0 0 1.0000
  2 件のコメント
Nguyet Nguyen
Nguyet Nguyen 2022 年 8 月 14 日
tks u so much
Torsten
Torsten 2022 年 8 月 14 日
編集済み: Torsten 2022 年 8 月 14 日
If the resulting vector v is the zero vector, you shouldn't include it as column in Q. This will happen if vi is already in the span of v1,...,v_i-1. And this will definitely happen if more than n vectors are supplied - as is possible according to the formulation of the assignment.

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2022 年 8 月 13 日
You should just use orth to get the orthonormal basis. And you should use qr instead of Gram-Schmidt.

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by