Finding the Velocity at Different intervals
Ältere Kommentare anzeigen
tryng to write a code to display the velocity and displacement given a time interval and acceleration at those intervals using integration. getting an error in my for loop what might be the reason
clear all
close all
% Acceleration Vector
a = [0 2 4 7 11 17 24 32 41 48 51];
% define time interval
k =1;
%define time vector
t = 0:k:10;
%initialize velocity
for ii = 1:11
v(ii) = trapz(a(1:ii),k);
end
% calculate the displacement d at each time interval
for jj = 1:11
d(jj) = trapz(v(1:jj),k);
end
% display a table of the velocity values
v = table(t,v,'VariableNames',{'Time(Sec)' 'Velocity(m/s)'})
% display a table of the displacement values
d = table(t',d','VariableNames',{'Time(Sec)' 'Displacement(m)'})
Akzeptierte Antwort
Weitere Antworten (1)
Kudzanai Sekerere
am 25 Aug. 2019
3 Kommentare
Star Strider
am 25 Aug. 2019
I don’t understand the need for a loop with trapz, since (if I understand what you are doing), cumtrapz should do what you want, without any loops.
Kudzanai Sekerere
am 26 Aug. 2019
Star Strider
am 26 Aug. 2019
The cumtrapz function is more efficient. I would use it and eliminate the loops.
Kategorien
Mehr zu Time and Frequency Domain Analysis finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!