Constructing a symmetric matrix

15 ビュー (過去 30 日間)
A
A 2015 年 3 月 13 日
コメント済み: Andrei Bobrov 2015 年 3 月 13 日
Hello!
I am trying to construct a symmetric matrix, B, from a random matrix, A
My code is as follows:
scale=6;
A = randn(scale,scale);
%for real matrices, unitary is the same as orthogonal
[Q,R]=qr(A);
%Q is a unitary matrix, R is an upper-triangular matrix. A=Q*R
%construct a set of equally spaced values, d, from which a diagonal matrix is made
d=[1:1:scale];
D=diag(d);
%A symmetric matrix can be constructed from Q*D*transpose(Q)
B=Q*D*transpose(Q) %symmetric matrix
tf=issymmetric(B) %but it isn't symmetrical!
I think the problem arises from there being negative values from Q*transpose(Q), it isn't a perfectly unitary matrix. This is the output from the above code for Q*transpose(Q):
1.0000 -0.0000 0.0000 0.0000 0.0000 -0.0000
-0.0000 1.0000 0.0000 -0.0000 -0.0000 0.0000
0.0000 0.0000 1.0000 -0.0000 0.0000 -0.0000
0.0000 -0.0000 -0.0000 1.0000 -0.0000 0.0000
0.0000 -0.0000 0.0000 -0.0000 1.0000 0.0000
-0.0000 0.0000 -0.0000 0.0000 0.0000 1.0000
So, something needs to be fixed in my step to create the symmetric matrix, B, but I'm not exactly sure what. Any advice would be greatly appreciated!

回答 (1 件)

Roger Stafford
Roger Stafford 2015 年 3 月 13 日
編集済み: Roger Stafford 2015 年 3 月 13 日
Very likely your B matrix only lacks symmetry because of round-off errors in the computation process. Do this instead of using 'issymmetric', which demands exact symmetry:
tf = max(max(abs(B-B.')))<tol;
for some very small tolerance value, 'tol' - that is, small relative to the values in the original Q matrix.
[Note added: If you still need exact symmetry after passing the above test, you can write "B = (B+B.')/2;" ]
  1 件のコメント
Andrei Bobrov
Andrei Bobrov 2015 年 3 月 13 日
tf = norm(B-B.',inf)<tol

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by