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.
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
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:
  1. reformulate the problem so that it is numerically stable (no operations involving loss of significance)
  2. use a toolbox that supports varaible precision or symbolic mathematics.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2020년 12월 21일

댓글:

2020년 12월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by