round off error in mtimes
古いコメントを表示
I've noticed that mtimes produces a slightly different answer than the answer I would get from multiplying two vectors directly. Does anyone have any insights on why it's the case?
For example: z is a small single-precision floating point array
z =
0.6970215
0.7363197
0.7967772
0.8811227
0.9433413
Using mtimes: z'*z = 3.3291292 Direct method: sum(z.^2) = 3.3291297
Notice how the last decimal place is different? For my problem, I'm computing a bunch of array multiplications in a loop, and this small error gets propagated. The final result using mtimes can be quite different compared to just doing the calculations by hand.
What's causing the difference? Is the small error in mtimes to be expected?
5 件のコメント
You are doing two different calculations using floating point numbers... of course floating-point error will be propagated:
Clare
2016 年 6 月 14 日
Stephen23
2016 年 6 月 14 日
Only in the abstract world of mathematics. Your computation uses floating point numbers, which behave in ways that only bear a passing resemblance to mathematics.
Roger Stafford
2016 年 6 月 14 日
The difference between your two results, 3.3291292 and 3.3291297, for single precision numbers is just two of the least bits in their 24-bit significands. That is perfectly acceptable in such a computation. If you want higher accuracy, you should use double precision.
Clare
2016 年 6 月 15 日
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!