Not sure best way to code orthogonal diagonalization
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos

Just having an issue with highlighted part, will attach rest of code below.
function []=symmetric(A)
if size(A,1)~=size(A,2)
disp('Matrix is not symmetric')
return
else
if all(abs(A-A')<.000001)
[P,D]=eig(A);
if all(abs(inv(P)-P')<.00001)
disp('P:')
disp(P)
disp('D:')
disp(D)
disp('P is orthogonal matrix')
else
disp('P:')
disp(P)
disp('D:')
disp(D)
disp('P is orthogonal matrix')
end
else
disp('Matrix is not symmetric')
end
end
end
5 comentarios
David Goodmanson
el 9 de Abr. de 2020
Hi Thomas,
That's a good point. Because of your other question I had a feeling that the stuff here was not really helping.
Since the entries of A in this case are integers you can do a check for exact equality, A - A' == 0. The other tests are going to take tolerance checks, such as all(A*P-P*D < tolerance). As far as the acceptable tolerance, it looks like the instructor has provided that with closetozeroroundoff (although I have no idea how it works). For orthogonality, you can have all(inv(P) -P' < tolerance) as you are doing. Probably better, especially for large matrices, is not doing the inverse. For an orthogonal matrix P*P' = eye(size(P)) so you can check all(P*P'-eye(size(P))< tolerance).
Respuestas (1)
David Hill
el 9 de Abr. de 2020
For homework, we like to help you figure it out yourself. The code below might help and you could likely find a better way.
function a=symmetric(A)
if issymmetric(A)
[P,D]=eig(A);
if closetozeroroundoff(P*D,A*P)&&closetozeroroundoff(inv(P),P')
a='orthogonal diagonal';
else
a='symmetric';
end
else
a='nonsymmetric';
end
end
function yn=closetozeroroundoff(a,b)
yn=0;
if norm(a-b)<1e-14
yn=1;
end
end
0 comentarios
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!