why does 'sum' and 'trapz' function show same result ?
Mostra commenti meno recenti
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
Risposta accettata
Più risposte (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 Commento
Arif Hoq
il 14 Dic 2021
Categorie
Scopri di più su Numerical Integration and Differentiation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!