# Matrix symbolic calculation doesn't simplify expressions

1 view (last 30 days)
Ohad Shapira on 26 Dec 2020
Commented: Ohad Shapira on 26 Dec 2020
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 CommentsShowHide 1 older comment
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)

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]
Ohad Shapira on 26 Dec 2020
Worked! thanks!