why my cdf does not match cumsum(pdf)
古いコメントを表示
x=1D array of 100 discrete values that I calculate Rayleigh pdf and cdf as below
pdfrayl = 2 * x .* exp(-x .^ 2);
cdfrayl = 1 - exp(-x .^ 2);
Now I plot following two lines:
plot(x, cdfrayl)
hold on;
plot(x, cumsum(pdfrayl )/ sum(pdfrayl))
I expected them to match exactly, but they don't. Can anybody please explain why they don't match?
採用された回答
その他の回答 (1 件)
Russ Adheaux
2012 年 9 月 15 日
0 投票
3 件のコメント
Wayne King
2012 年 9 月 15 日
The dx is coming the length of the interval max(x)-min(x) divided by the number of points. Yes, you would have to sort the x. Do you know the ecdf function?
Star Strider
2012 年 9 月 15 日
For unevenly spaced, monotonically-increasing x-data, I suggest trapz or cumtrapz, specifying both x and y data as arguments. It then allows you to integrate with respect to any x-variable spacing, and is more accurate than cumsum.
Russ Adheaux
2012 年 9 月 19 日
カテゴリ
ヘルプ センター および 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!