Matrix symbolic calculation doesn't simplify expressions

1 view (last 30 days)
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 Comments
Ohad Shapira
Ohad Shapira on 26 Dec 2020
Edited: Ohad Shapira on 26 Dec 2020
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)

Sign in to comment.

Accepted Answer

Stephan
Stephan on 26 Dec 2020
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]

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!