Substitute symbolic expression into matrix

1 vue (au cours des 30 derniers jours)
Jörn Froböse
Jörn Froböse le 17 Juil 2020
Commenté : Jörn Froböse le 17 Juil 2020
I would like to evaluate a symbolic matrix for certain values. Unfortunately, I cannot find a way for Matlab to show the analytically correct solution, instead I get very long fractions as a result.
For example, I have a matrix B and a variable a:
syms a B
B=[sin(a)^2; cos(a)^2]
a=sym(atan(2))
To insert a into the matrix B I use subs:
B=subs(B)
Matlab outputs the following expression as a result:
cos(1246538638225297/1125899906842624)^2
sin(1246538638225297/1125899906842624)^2
Is there a way to output the analytical solution?
For example, the command below will produce the exact result of 1/5:
sym(cos(atan(2))^2)
ans = 1/5
Thanks for the help!

Réponse acceptée

madhan ravi
madhan ravi le 17 Juil 2020
sym(double(subs(B)))
  1 commentaire
Jörn Froböse
Jörn Froböse le 17 Juil 2020
Thank you, that did the trick for me!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by