Can I multiply a two different size vectors?

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)

2 comentarios

Kennedy Oparka
Kennedy Oparka el 11 de Feb. de 2018
Editada: Kennedy Oparka el 11 de Feb. de 2018
I have added it I am just trying to multiply a 500x1 by a 499x1 vector
Walter Roberson
Walter Roberson el 11 de Feb. de 2018
What size of output are you expecting?

Iniciar sesión para comentar.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Feb. de 2018

0 votos

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

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 11 de Feb. de 2018

Respondida:

el 11 de Feb. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by