Different output given equal functions
古いコメントを表示
I encountered a problem given the following two functions:

Writing out both functions, we see that both functions are the same and therefore should reproduce the same output.
However, implementing this in Matlab yields different output. I get the intuation that this is due to the size of the values of:
. I have attached the matlabfile which demonstrates this in the appendix.
. I have attached the matlabfile which demonstrates this in the appendix.Also the following two pictures will show the problem:


As can be seen from the pictures, Matlab would argue that the output of this equation part6 would be equal to zero.
Whereas we see that (part1 + part3) are for sure greater than part4 and (part2+part5) would yield zero. Therefore our part6 could never be equal to zero.
Is there a way to solve this problem or is this just a restriction given the size of the values?
1 件のコメント
Stephen23
2020 年 12 月 21 日
Those (presumably double class) values cannot be added and retain the full precision of the smaller magnitiude values. Basically you are trying something that is beyond the scope of IEEE 754 double precision, and you are getting catastrophic cancelation (or something very similar to it):
There are two basic approaches to resolve this:
- reformulate the problem so that it is numerically stable (no operations involving loss of significance)
- use a toolbox that supports varaible precision or symbolic mathematics.
回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!