필터 지우기
필터 지우기

difference between trapz and just summing

조회 수: 25 (최근 30일)
jenka
jenka 2013년 4월 16일
Dear everybody, I was wondering what is the difference between the function trapz and the sum as used below. It appears to be about the same. I am just trying to find the intersection between two histograms:
h = [16, 45, 23, 1]
g = [18, 38, 27, 5]
hn = h./sum(h);
gn = g./sum(g);
intersection = trapz(min([hn;gn]);
intersection = sum(min([hn;gn]));
Which one would be favorable over the other. It appears trapz should be better approximation.

답변 (1개)

Matt J
Matt J 2013년 4월 16일
If the function you've sampled and are integrating is piece-wise constant, then summing its samples will be ideal. If instead, it is piece-wise linear, the trapezoidal approximation will be ideal. You have to decide which situation more accurately describes your function.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by