How to make a symmetric matrix with symbolic elements

6 次查看(过去 30 天)
There's already a similar question for how to make a symmetric matrix with certain values.
But I want to create a symbolic matrix that is symmetric.
I learned how to make a non-symmetric symbolic matrix thus:
>> n=3;
>> Q = sym('q', [n n])
Q =
[ q1_1, q1_2, q1_3]
[ q2_1, q2_2, q2_3]
[ q3_1, q3_2, q3_3]
Now I want to know if there is an easy way to make this:
Q =
[ q1_1, q1_2, q1_3]
[ q1_2, q2_2, q2_3]
[ q1_3, q2_3, q3_3]

回答(1 个)

Bill Tubbs
Bill Tubbs 2020-5-28
编辑:Bill Tubbs 2020-5-28
This seems to work:
>> Q = tril(Q.') + triu(Q,1) % Uses top half of Q to make Q symmetric
Q =
[ q1_1, q1_2, q1_3]
[ q1_2, q2_2, q2_3]
[ q1_3, q2_3, q3_3]

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by