Why I get different values when I integrate a function (by my hand-Displacement Positive & Negative, cumtrapz-Displacement Positive)?
Show older comments
Why I get different values when I integrate a function (by my hand, cumtrapz)?
As you can see below, there is a very big difference when I integrate the function with cumtrapz.
%% Simple
t = 0:1:5; % Time (s)
a = 10*cos(20*t); % Acceleration (m/s^2)
VALUES:
10
4,08082061813392
-6,66938061652262
-9,52412980415156
-1,10387243839048
8,62318872287684
v = sin(20*t)/2; % Velocity (m/s)
VALUES:
0
0,456472625363814
0,372556580239674
-0,152405310551108
-0,496944326961688
-0,253182820554879
x = -cos(20*t)/40; % Displacement (m)
VALUES:
-0,0250000000000000
-0,0102020515453348
0,0166734515413065
0,0238103245103789
0,00275968109597619
-0,0215579718071921

%% Cumtrapz
t = 0:1:5; % Time (s)
a_cumtrapz = 10*cos(20*t); % Acceleration (m/s^2) with Cumtrapz
VALUES:
10
4,08082061813392
-6,66938061652262
-9,52412980415156
-1,10387243839048
8,62318872287684
v_cumtrapz = cumtrapz(t,a_cumtrapz); % Velocity (m/s) with Cumtrapz
VALUES:
0
7,04041030906696
5,74613030987261
-2,35062490046448
-7,66462602173550
-3,90496787949232
x_cumtrapz = cumtrapz(t,v_cumtrapz); % Displacement (m) with Cumtrapz
VALUES:
0
3,52020515453348
9,91347546400327
11,6112281687073
6,60360270760734
0,818805756993430

Accepted Answer
More Answers (0)
Categories
Find more on Profile and Improve Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!