Calculating displacement, power, energy and torque from velocity data in .csv format.
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Siddhi Kadam
am 30 Sep. 2020
Kommentiert: Siddhi Kadam
am 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 Kommentare
Akzeptierte Antwort
Stefanie Schwarz
am 30 Sep. 2020
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.
Weitere Antworten (1)
Stefanie Schwarz
am 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
5 Kommentare
Stefanie Schwarz
am 30 Sep. 2020
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.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!