# Error using plot Vectors must be the same lengths

1 view (last 30 days)
koke on 12 Apr 2013
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 on 12 Apr 2013
ndis = double( subs(dis, 't', t) );
plot(ndis, t);

Walter Roberson on 12 Apr 2013
if q0 is 10, then what are you expecting the result of diff(q0) to be ?
koke on 12 Apr 2013
the diff of qo = 0
Walter Roberson on 12 Apr 2013
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.