Matrix symbolic calculation doesn't simplify expressions

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Ohad Shapira
Ohad Shapira il 26 Dic 2020
Modificato: Ohad Shapira il 26 Dic 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)

Accedi per commentare.

Risposta accettata

Stephan
Stephan il 26 Dic 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]

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by