In MATLAB 2020a, how can I convert symfun to double?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a symfun like this:
>> p
p(t) =
[ 0, -(800*pi^2*exp(10*log((489*pi)/50 + 5*sin((11*pi)/250)) - 10*log(10*pi))*(9*cos((11*pi)/250) + (489*pi*sin((11*pi)/250))/500 - 5*cos((11*pi)/250)^2 - 4))/((489*pi)/50 + 5*sin((11*pi)/250))^2, -(800*pi^2*exp(10*log((239*pi)/25 + 5*sin((11*pi)/125)) - 10*log(10*pi))*(9*cos((11*pi)/125) + (239*pi*sin((11*pi)/125))/250 - 5*cos((11*pi)/125)^2 - 4))/((239*pi)/25 + 5*sin((11*pi)/125))^2, -(800*pi^2*exp(10*log((467*pi)/50 + 5*sin((33*pi)/250)) - 10*log(10*pi))*(9*cos((33*pi)/250) + (467*pi*sin((33*pi)/250))/500 - 5*cos((33*pi)/250)^2 - 4))/((467*pi)/50 + 5*sin((33*pi)/250))^2, -(800*pi^2*exp(10*log((228*pi)/25 + 5*sin((22*pi)/125)) - 10*log(10*pi))*(9*cos((22*pi)/125) + (114*pi*sin((22*pi)/125))/125 - 5*cos((22*pi)/125)^2 - 4))/((228*pi)/25 + 5*sin((22*pi)/125))^2, -(800*pi^2*exp(10*log((89*pi)/10 + 5*sin((11*pi)/50)) - 10*log(10*pi))*(9*cos((11*pi)/50) + (89*pi*sin((11*pi)/50))/100 - 5*cos((11*pi)/50)^2 - 4))/((89*pi)/10 + 5*sin((11*pi)/50))^2, -(800*pi^2*exp(10*log((217*pi)/25 + 5*sin((33*pi)/125)) - 10*log(10*pi))*(9*cos((33*pi)/125) + (217*pi*sin((33*pi)/125))/250 - 5*cos((33*pi)/125)^2 - 4))/((217*pi)/25 + 5*sin((33*pi)/125))^2, ............
but when I try to convert it to doule I get(this used to work fine in MATLAB 2018b)
>> pp=double(p)
Error using symengine
Unable to convert expression into double array.
Error in sym/double (line 698)
Xstr = mupadmex('symobj::double', S.s, 0);
0 commentaires
Réponse acceptée
Steven Lord
le 6 Sep 2020
You're not specifying a value for t. If any of the elements of the vector p returns when evaluated are functions of t, there's no way to convert that component to a double without specifying a value for t.
syms t p(t)
p(t) = sin(t);
double(p) % this will throw the error you received
p(pi/2) % this will return a sym that contains no symbolic variable
double(p(pi/2)) % this will return a double
4 commentaires
Steven Lord
le 6 Sep 2020
One other thing I forgot to mention. If you're working symbolically because sin(pi) is not exactly 0 and you need to avoid the roundoff error:
>> y = sin(pi)
y =
1.22464679914735e-16
you may be able to avoid the need to work symbolically by using the sinpi function.
>> y = sinpi(1) % sin(1*pi)
y =
0
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Symbolic Variables, Expressions, Functions, and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!