Question of mean
古いコメントを表示
When I write a program about consumption (C) with 10^5 trajectories, I want to calculate the expectation of them with the command mean(C(:,j)). However, at j=1, all the C are equal to 0.86, but the mean(C(:,1))=0.859999999999891. Would anyone tell me why it happens and how to correct it please? Thank you.
採用された回答
その他の回答 (1 件)
Titus Edelhofer
2012 年 5 月 21 日
Hi,
0.86 is not exactly representable in computers double precision representation:
fprintf('%.20f\n', 0.86)
0.85999999999999999000
Titus
3 件のコメント
Oleg Komarov
2012 年 5 月 21 日
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Tommy
2012 年 5 月 21 日
Walter Roberson
2012 年 5 月 21 日
Recode your test to
if C(i,j) * size(C,1) >= sum(C(:,j))
カテゴリ
ヘルプ センター および File Exchange で Web Services についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!