Matrix symbolic calculation doesn't simplify expressions

2 ビュー (過去 30 日間)
Ohad Shapira
Ohad Shapira 2020 年 12 月 26 日
コメント済み: Ohad Shapira 2020 年 12 月 26 日
When using syms in matrix, after matrix multipication I get expressions like that:
>> A5(3,3)
ans =
- (2^(1/2)*((2^(1/2)*w*1i)/2 - 2^(1/2)/8))/2 + (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2
(w is symbolic var)
While this entire cell is equal to 1/8
Is there any configuration I can change to make it more readable?
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2020 年 12 月 26 日
Have you tried with vpa?
Ohad Shapira
Ohad Shapira 2020 年 12 月 26 日
編集済み: Ohad Shapira 2020 年 12 月 26 日
Yes I did, the problem is that some times I get 1/sqrt(2) and vpa gives me a long decimal number.
(The results from this code will be used for manual calculations in furter steps)

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

採用された回答

Stephan
Stephan 2020 年 12 月 26 日
try simplify - here is an example with your expression:
syms w
E = eye(3) * - (2^(1/2)*((2^(1/2)*w*1i)/2 - 2^(1/2)/8))/2 + (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2
Simple_E = simplify(E)
gives:
E =
[ - (2^(1/2)*((2^(1/2)*w*1i)/2 - 2^(1/2)/8))/2 + (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2, (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2, (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2]
[ (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2, - (2^(1/2)*((2^(1/2)*w*1i)/2 - 2^(1/2)/8))/2 + (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2, (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2]
[ (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2, (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2, - (2^(1/2)*((2^(1/2)*w*1i)/2 - 2^(1/2)/8))/2 + (2^(1/2)*((2^(1/2)*w*1i)/2 + 2^(1/2)/8))/2]
Simple_E =
[ 1/4, (w*1i)/2 + 1/8, (w*1i)/2 + 1/8]
[ (w*1i)/2 + 1/8, 1/4, (w*1i)/2 + 1/8]
[ (w*1i)/2 + 1/8, (w*1i)/2 + 1/8, 1/4]

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConversion Between Symbolic and Numeric についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by