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

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

 Réponse acceptée

The cumtrapz function uses the trapezoidal method. I don't know what this method does but I think it doesn't integrade the function you need. I'm sorry but I think I cannot help you futher because of my leak of knowledge in physics. I think it is the best if you look into a physics book and see how the power and energie is defined with an integral.

Plus de réponses (1)

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

5 commentaires

Hello Stefanie. Thank you for responding. When i use the integral function, I get an error saying that first inout argument must be a function handle. Can you help with this?
Hi Siddhi,
Matlab needs to know in which variable 0 and A(end,1) are be used.
You need to implement you function like f = @(x) your function
@(x) tells matlab that x is the variable. Which stands later for 0 and A(end,1) or other values.
If you write "help integral" in the command window and press enter. You get an explanation of the integral function. I think the examples can help you.
Make sure you know how the function of the energie should look like. I am not really good at physics so I can not help you with that.
Greetings Steffi
SSK
SSK le 30 Sep 2020
Modifié(e) : SSK le 30 Sep 2020
Thank you for your reply. However, I do know that using the cumtrapz command as well we can integrate the power. But I'm not able to track where I'm missing something.
I think the problem is that in cumtrapz the function which describes the course is defined. To use the integral function you need to define the function which describes the course of the energie yourself. When you call integral(Power,0,A(end,1)) you don't give a function but a array instead. Power is an array which holds the value of power for each time step.
Okay but using cumtrapz command I'm getting a plot of energy that is not correct. The energy should be rising instead I'm getting the following graph. How to do this using cumtrapz? Also how can I define a function of power if at all to use integral command.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by