why does 'sum' and 'trapz' function show same result ?
Ältere Kommentare anzeigen
Just found the same result for "sum" and "trapz" function. is it same for uniform spacing (i think here is1) in trapz ?
if yes, then can use 'sum' function for integration instead of 'trapz', right ?
if no, what can be the possible reason ?
attached the 'mat' file here.
Code:
clear;
A=load('positive_value.mat');
power_positive_value=A.B;
integration=trapz(power_positive_value)
summation=sum(power_positive_value)
Result:
integration =
5.9126e+06
summation =
5.9126e+06
Akzeptierte Antwort
Weitere Antworten (1)
sum() and trapz() do not give the same result, even assuming uniform spacing:
Y = [1 2 3 4 5];
sum(Y)
trapz(Y)
It only seemed to be the same in your case, because of the large numbers involved, but sum(B) and trapz(B) do not give the same value in your case, either. Try subtracting those two values, to see the relatively small difference.
1 Kommentar
Arif Hoq
am 14 Dez. 2021
Kategorien
Mehr zu Numerical Integration and Differentiation 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!