How to create a symbolic matrix which is symmetric?

18 ビュー (過去 30 日間)
Will Bolton
Will Bolton 2018 年 3 月 1 日
コメント済み: Walter Roberson 2018 年 3 月 1 日
Hello, I essentially want to create something with the form you would get from doing:
A = sym('A', [6,6])
but additionally I would like A to be symmetric and I'm not sure if there is an easy way to generate this?

採用された回答

John D'Errico
John D'Errico 2018 年 3 月 1 日
編集済み: John D'Errico 2018 年 3 月 1 日
A = sym('A', [6,6]);
A = tril(A,0) + tril(A,-1).'
A =
[ A1_1, A2_1, A3_1, A4_1, A5_1, A6_1]
[ A2_1, A2_2, A3_2, A4_2, A5_2, A6_2]
[ A3_1, A3_2, A3_3, A4_3, A5_3, A6_3]
[ A4_1, A4_2, A4_3, A4_4, A5_4, A6_4]
[ A5_1, A5_2, A5_3, A5_4, A5_5, A6_5]
[ A6_1, A6_2, A6_3, A6_4, A6_5, A6_6]
Looks symmetric to me.
  3 件のコメント
Will Bolton
Will Bolton 2018 年 3 月 1 日
Hmm so now I have the issue with this method that if I want to solve with this matrix, when I plug it back in I get the error:
One or more variables are used multiple times. Cannot distinguish between variables and equations. Use a vector of equations and a vector of variables to avoid ambiguity.
I essentially have a system of equations in the lower triangle of a matrix, with the upper portion all zeroes. I am trying to solve in terms of the elements of the symmetric matrix. There are the same number of variables as there are equations but what I'm trying isn't working. I have tried:
sol = solve(eqn, W)
sol = solve(eqn, tril(W))
The former gets the error above, the latter gets:
The second argument must be a vector of symbolic variables.
Walter Roberson
Walter Roberson 2018 年 3 月 1 日
sol = solve(eqn, unique(W))

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by