# Determining if the columns of a matrix are orthogonal

85 views (last 30 days)

Show older comments

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 Comments

Asad (Mehrzad) Khoddam
on 4 Dec 2020

### Answers (2)

Asad (Mehrzad) Khoddam
on 4 Dec 2020

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 Comments

James Tursa
on 4 Dec 2020

Edited: James Tursa
on 4 Dec 2020

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.

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!