Why does cumtrapz return negative values?
8 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi!
I am trying to calculate the area underneath a small piece of line using cumtrapz. The line has a positive slope and has positive x and y value. However, cumtrapz returns negative values for the area:
area = 0 -0.0145 -0.0290 -0.0435 -0.0580
I think it has something to do with the stepsize of the X-vector. How can I accurately calculate the area underneath the line?
Thanks!
Bas
% Example of data
X=[0.5056 0.5048 0.5040 0.5032 0.5024];
Y=[18.1277 18.1241 18.1205 18.1170 18.1134];
% Calculating the area under the data
area=cumtrapz(X,Y);
% Plotting data
figure
plot(X,Y)
grid on
1 commentaire
Tom
le 18 Fév 2023
I have a similar issue, does anyone have any ideas? I have 2 csv files with one column increasing and the other decreasing in each file. i have created a code to calculate the midpoint and plot the csv files with the mid point (1 csv file is a minimum and the other is a maximum). it does this fine but when using cumtrapz it outputs a negative integral
Réponses (1)
Stijn Haenen
le 30 Déc 2019
Your X and Y are from high value to low values, resulting in negative areas.
use fliplr() to mirror arrays X and Y.
X=[0.5056 0.5048 0.5040 0.5032 0.5024];
Y=[18.1277 18.1241 18.1205 18.1170 18.1134];
% Calculating the area under the data
X=fliplr(X);
Y=fliplr(Y);
area=cumtrapz(X,Y);
% Plotting data
figure
plot(X,Y)
grid on
0 commentaires
Voir également
Catégories
En savoir plus sur Directed Graphs dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!