Error using plot Vectors must be the same lengths

1 次查看(过去 30 天)
Hi,,
iam not matlab pro. :)
so i have problem on a very simple program
that's the program >>>>>>>>>>>>>>>>
vo=input('vo=');
vf=input('vf=');
to=input('to=');
tf=input('tf=');
qo=input('qo=');
qf=input('qf=');
ao=qo;
a1=diff(qo);
syms t;
syms dis;
a2=(3*(qf-qo)-(2*diff(qo)+diff(qf))*tf)/((tf)^2);
a3=(-2*(qf-qo)+(diff(qo)+diff(qf))*tf)/(tf)^3;
dis=ao+a1*t+a2*t^2+a3*t^3;
vel=a1+2*a2*t+3*a3*t^2;
acc=2*a2+6*a3*t;
t=0:tf;
plot(dis,t);
when i press play this error shown to me " Error using plot Vectors must be the same lengths "
so please how can i edit this program to playing well

采纳的回答

Walter Roberson
Walter Roberson 2013-4-12
ndis = double( subs(dis, 't', t) );
plot(ndis, t);
  9 个评论
Walter Roberson
Walter Roberson 2013-4-12
diff() of a scalar numeric value is [] the empty list, because diff() of numerics is the subtract-adjacent operation.
If q0 had been assigned the symbolic value 0, sym('0') then diff() of that would likely generate an error because there would not be any variable contained inside it for the symbolic calculus differential operator to choose to take the differential with respect of.
If you had specified a variable, such as diff(sym('0'), sym('t')) then the result would be (symbolic) 0.
Likewise for the other variables you are taking diff() of. It does not seem productive to bother to use diff() to calculate what you know will be 0... unless you are wanting the user to be able to enter NaN in which case the calculus differential would be NaN instead of 0.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by