# Calculating displacement, power, energy and torque from velocity data in .csv format.

14 views (last 30 days)

Show older comments

Siddhi Kadam
on 30 Sep 2020

Commented: Siddhi Kadam
on 30 Sep 2020

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')

##### 0 Comments

### Accepted Answer

Stefanie Schwarz
on 30 Sep 2020

### More Answers (1)

Stefanie Schwarz
on 30 Sep 2020

Hello Siddhi,

I found one mistake and one optional thing.

First the mistake. If you want to go from seconds to hours you don't multiply with 3600. You need to divided it with 3600.

Remember: 3600 seconds are 1 hour. So 1 seconds equals a 1/3600 hour.

The optional thing is: You don't need a dot before the operator if you have a calculate between a vektor and a skalar. The dot before the operator tells Matlab that you want him to calculate the element of position x in A with the element of the same position in B. But this is optional.

About the intgral function. I only read the help text of the integral function quickly but I think the second and third arguments are needed to be scalars. Second argument = starting point of the integral and thrid argument = end point of the integral. So it should be Energy=integral(Power,0,A(end,1)); <- end = last elemt of A(:,1) = last time point.

I hop I could help you a little.

Grettings Steffi

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!