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

조회 수: 8 (최근 30일)
a a
a a 2020년 9월 6일
댓글: Steven Lord 2020년 9월 6일
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
a a
a a 2020년 9월 6일
Great answer! Thanks a lot!
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