Error conversion to double from sym is not possible

i am encountering this error trying to plot these functions :
syms t A OA omg si
r=A*t+OA;
theta=omg*t;
phi=si*t;
rd=diff(r,t);
thetad=diff(theta,t);
phid=diff(phi,t);
omg=10*(pi/180);
si=7*(pi/180);
A=0.5;
tn=90/si;
a_r=-(r*phid^2)-(r*thetad^2*(cos(phi))^2)
a_theta=(cos(phi)/r)*diff(((r^2)*thetad),t)-(2*r*thetad*phid*sin(phi))
a_phi=(1/r)*diff((r^2*phid),t)+r*thetad^2*sin(phi)*cos(phi)
td=0:1:tn;
a_r=-(r*phid^2)-(r*thetad^2*(cos(phi))^2)
a_theta=(cos(phi)/r)*diff(((r^2)*thetad),t)-(2*r*thetad*phid*sin(phi))
a_phi=(1/r)*diff((r^2*phid),t)+r*thetad^2*sin(phi)*cos(phi)
a_r1=subs(a_r,t,td);
plot(td,a_r1)
this is the error :
Error using plot
Conversion to double from sym
is not possible.
Error in p6 (line 23)
plot(t,a_r1)
what should i have done ?

回答 (1 件)

Marc Jakobi
Marc Jakobi 2016 年 10 月 7 日

1 投票

The line
td = 0:1:tn
creates a double. So the line
a_r1=subs(a_r,t,td);
also creates a double. With
plot(t,a_r1)
you are using a double and a sym together, which Matlab can't handle.

5 件のコメント

Erfan Hamdi
Erfan Hamdi 2016 年 10 月 7 日
so what should i do ?
Marc Jakobi
Marc Jakobi 2016 年 10 月 7 日
Sorry, my answer was not quite correct. a_r1 and t are both symbolic variables.
However, you should use fplot() for symbolic variables, instead of plot().
This won't work either, though because your results are functions of multiple variables.
Please describe what exactly you are trying to compute. Maybe I can help you then.
Erfan Hamdi
Erfan Hamdi 2016 年 10 月 7 日
well i just need to plot those functions a_r , a_theta , a_phi having omg , si , and A as constants and just t as a variable of time and i dont want to substitute the exact numbers for omg , si and A so i could change their value some other time
Marc Jakobi
Marc Jakobi 2016 年 10 月 7 日
Matlab recognizes any sym you declare with "syms" as a variable and not as a constant. So if you want to be able to plot it, you will have not choice but to declare omg, si and A as constants with fixed values if you want to plot them. You can still change the values at other times.
Walter Roberson
Walter Roberson 2016 年 10 月 9 日
You can subs() in particular numeric values for the variables in order to plot.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2016 年 10 月 7 日

コメント済み:

2016 年 10 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by