Is it a mistake that the function sum?
9 ビュー (過去 30 日間)
古いコメントを表示
Please see the follow code:
N=3;
sum(sum(eye(N)-ones(N,N)/N))
The MATLAB answer is 3.3307e-16, but the right answer is 0.
But it is true if N is 2, 4, 8 as follows:
N=2;
sum(sum(eye(N)-ones(N,N)/N))
N=4;
sum(sum(eye(N)-ones(N,N)/N))
N=8;
sum(sum(eye(N)-ones(N,N)/N))
These right answers are 0, and the MATLAB answer is 0 too.
0 件のコメント
回答 (1 件)
James Tursa
2020 年 2 月 19 日
編集済み: James Tursa
2020 年 2 月 19 日
Welcome to the world of floating point arithmetic.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!