MATLAB: Can I multiply a two different size vectors

differential equationsvector

I have been using vector indexing to plot derivatives as so: vel=diff(pos); plot(t(1:end-1),vel)
I need to multiply the first derivative vector by the second derivative vector but it wont allow me to use vector indexing. Is there an alternative way? Below is my equation. T=J*vel(1:end-1)*acl;
%Coefficients
p1 = 301.59;
p2 = -376.99;
p3 = 125.66;
p4 = 8.5359e-07;
p5 = -4.9784e-08;
p6 = 8.0277e-10;
J = .0537 %kgm^2;
%Equation
pos = p1*t.^5+p2*t.^4+p3*t.^3+p4*t.^2+p5*t+p6;
%%Position vs Time
f1=figure
plot(t,rad)
title('Postition Graph ')
xlabel('Time (s)')
ylabel('Position (rad)')
%%Velocity
f2=figure
vel=diff(pos);
plot(t(1:end-1),vel)
title('Velocity Graph')
xlabel('Time (sec)')
ylabel('Velocity, (m/s)')
%%Acceleration
f3=figure
acl=diff(vel);
plot(t(1:end-2),acl)
title('Acceleration Graph')
xlabel('Time (sec)')
ylabel('Acceleration, (m/s^2)')
%Torque
T=J*vel(1:end-1)*acl;
plot(t(1:end-1),T)
title('Torque')
xlabel('time (s)')
ylabel('Torque (n*m)')
%Power
pwr=J*vel(1:end-1)*acl
plot(t(1:end-2),pwr)

Best Answer

Use gradient() instead of diff() to get your numeric derivative.