# Determining if the columns of a matrix are orthogonal

조회 수: 154(최근 30일)
Gurinder Punni 2020년 12월 4일
편집: James Tursa 2020년 12월 4일
I have to determine if the columns of any given matrix are orthogonal or not. But, I am not sure how to generalize that correctly. I am thinking of doing a for loop with i = 1:n(# of columns of matrix) but I don't know how I would accomplish that successfully because I have to dot each column with all the other columns without dotting themselves in the for loop. Let's say my code is
A = magic(4)
for i = 1:n
for j = 1:n
value = dot(A(:,i),A(:,j))
if value~=0
break;
end
end
end
##### 댓글 수: 2표시숨기기 이전 댓글 수: 1
if i==j then the dot product should not be zero. So, you need to check if i~=j then check the dot product

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

### 답변(2개)

Regarding the case i==j, you can start j from numbers greather than i:
A = magic(4)
orth = 1;
for i = 1:n
for j = i+1:n
value = dot(A(:,i),A(:,j))
if value~=0
orth=0;
break;
end
end
end
% check orth, if it is 0 it means that it is not orthogonal
if orth
disp('orthogonal')
else
disp('not orthogonal')
end
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

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

James Tursa 2020년 12월 4일
편집: James Tursa 2020년 12월 4일
Using the dot product and comparing it to 0 is a mathematical concept that does not translate well to floating point arithmetic. If you are going to use this method, unless you know for sure you are dealing with integers only and that the calculations will not overflow the precision, it is better to use a tolerance for floating point comparisons. And unless you know the range of numbers you are dealing with for picking a tolerance, you should normalize the columns before comparing the dot product result to the tolerance.
All that being said, what you could simply do to generate the dot products is do a matrix multiply with its transpose. E.g., A'*A will generate all of the column dot products as elements of the result. Just examine the upper or lower triangle part of this.

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

### 범주

Find more on Linear Algebra in Help Center and File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by