2010-05-09 65 views
1

我試圖找出矩陣是正交的。我開始通過檢查向量是正常做在matlab中無法比較矢量的常量與1

for j=1:2; 
    if norm(S:,j) ~= 1; 
     return; % Not normal vector 
    end 
end 

但當規範返回1.0000是比較1是真實的,函數返回時,這不是我想要的。有任何想法嗎?

Thx

回答

4

正交矩陣具有當您乘以轉置時獲得單位矩陣的屬性。因此,可以簡單地寫

%# multiply by the transpose and subtract identity 
test = S*S'-eye(size(S)); %#  ' (SO formatting) 

%# check whether the result is not too different from zero 
isOrthonormal = all(abs(test(:)) < 1E-10);