why does 'sum' and 'trapz' function show same result ?
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (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 comentario
Arif Hoq
el 14 de Dic. de 2021
Categorías
Más información sobre Numerical Integration and Differentiation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!