MATLAB Answers

# How to make a symmetric matrix with symbolic elements

12 views (last 30 days)
Bill Tubbs on 28 May 2020
Commented: Bill Tubbs on 31 May 2020
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 CommentShowHide None
Bill Tubbs on 31 May 2020
Just realized this question has already been asked and answered here.

Sign in to comment.

### Answers (1)

Bill Tubbs on 28 May 2020
Edited: Bill Tubbs on 28 May 2020
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]
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

R2019b

### Community Treasure Hunt

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

Start Hunting!