why does 'sum' and 'trapz' function show same result ?
古いコメントを表示
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
採用された回答
その他の回答 (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.
カテゴリ
ヘルプ センター および File Exchange で Numerical Integration and Differentiation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!