I have to find the displacement, power, energy and torque from a data that contains velocity of an object over time. The velocity and time data is in csv format. Could you please take a look and let me know if the results are correct? I'm a bit unsure about the energy one. How to use the 'integral ' command for this?

clc

A=csvread(' data .csv'); %reads csv data (';' prevents this from printing into the screen)

t=A(:,1);

time_hr=A(:,1)*3600; % sec to hr

speed=A(:,2)*1.60934; %miles to km

%Finding average speed:

avg_speed=mean(A(:,2))/10^3

% dist vs. time graph:

displacement=avg_speed.*time;

%plotting accln

dV=gradient(speed/10^3);

dt=0.01;

Accln=dV./dt;

figure(1)

subplot(3,1,1)

plot(t,displacement)

title('displacement')

subplot(3,1,2) % m*n grid, p position

plot(t,speed) %plot speed vs. time

title('speed')

subplot(3,1,3)

plot(A(:,1),Accln)

title('Acceleration')

%——————————————————%

%Power Calculation:

%Step 1: Force Calculation

mass=1257;

Fa=mass*Accln;

% subplot(4,1,4)

% plot(A(:,1),Fa)

% title('Force')

Power=Fa.*speed;

% Torque calculation:

Torque=Fa*0.1778*1.1;

%Energy calculation

%Energy=integral(Power,0,A(:,1));

Energy=cumtrapz(Power);

figure(2)

subplot(3,1,1)

plot(A(:,1),Power) % plot power

title('Power')

subplot(3,1,2)

plot(A(:,1),Torque)

title('Torque')

subplot(3,1,3)

plot(A(:,1),Energy/1000)

title('Energy')

## Best Answer