In MATLAB 2020a, how can I convert symfun to double?

7 次查看(过去 30 天)
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);

采纳的回答

Steven Lord
Steven Lord 2020-9-6
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 个评论
Steven Lord
Steven Lord 2020-9-6
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Symbolic Variables, Expressions, Functions, and Settings 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by