Determining if the columns of a matrix are orthogonal

101 vues (au cours des 30 derniers jours)
Gurinder Punni
Gurinder Punni le 4 Déc 2020
Commenté : Torsten le 10 Juil 2023
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 commentaires
Gurinder Punni
Gurinder Punni le 4 Déc 2020
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.
Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam le 4 Déc 2020
if i==j then the dot product should not be zero. So, you need to check if i~=j then check the dot product

Connectez-vous pour commenter.

Réponses (2)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam le 4 Déc 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 commentaires
Thota
Thota le 10 Juil 2023
what is the value of n
Torsten
Torsten le 10 Juil 2023
The number of columns of the matrix.

Connectez-vous pour commenter.


James Tursa
James Tursa le 4 Déc 2020
Modifié(e) : James Tursa le 4 Déc 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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Tags

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by