Determining if the columns of a matrix are orthogonal

109 visualizaciones (últimos 30 días)
Gurinder Punni
Gurinder Punni el 4 de Dic. de 2020
Comentada: Torsten el 10 de Jul. de 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 comentarios
Gurinder Punni
Gurinder Punni el 4 de Dic. de 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 el 4 de Dic. de 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

Iniciar sesión para comentar.

Respuestas (2)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam el 4 de Dic. de 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 comentarios
Thota
Thota el 10 de Jul. de 2023
what is the value of n
Torsten
Torsten el 10 de Jul. de 2023
The number of columns of the matrix.

Iniciar sesión para comentar.


James Tursa
James Tursa el 4 de Dic. de 2020
Editada: James Tursa el 4 de Dic. de 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.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by