# Determining if the columns of a matrix are orthogonal

조회 수: 174 (최근 30일)
Gurinder Punni . 2020년 12월 4일
댓글: Torsten . 2023년 7월 10일
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없음 표시없음 숨기기
Gurinder Punni 2020년 12월 4일
I could'nt finish the rest of my thought in the post because the text editor glitched out. So, I was saying that is there some way to not make j what i is currently so there is no dot products done to the same vector.
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
##### 댓글 수: 2없음 표시없음 숨기기
Thota 2023년 7월 10일
what is the value of n
Torsten 2023년 7월 10일
The number of columns of the matrix.

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

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.

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

### 카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

R2020a

### Community Treasure Hunt

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

Start Hunting!