0
$\begingroup$

In my calculations I have a variable (say z) which can be an argument of Log, say, z Log[z].

Under some conditions, z = x-y, where:

x = a + c; 
y = b + c;
a = 4.24835*10^-18;
b = -4.24835*10^-18;
c = 1.3956*10^18;

By default Mathematica considers both

4.24835*10^-18 == -4.24835*10^-18 == 0 

and this leads to x = y = 1.3956*10^18 and, hence, z = 0 and z Log[z] = Indeterminate.

How can I prevent this and make sure it does not happen elsewhere?

$\endgroup$
  • $\begingroup$ show your code please $\endgroup$ – Alrubaie Oct 5 '19 at 15:45
  • $\begingroup$ Use extended precision numbers instead of machine numbers. $\endgroup$ – Carl Woll Oct 5 '19 at 16:01
  • $\begingroup$ please see the edit $\endgroup$ – Ragab Zidan Oct 5 '19 at 16:21
1
$\begingroup$

Use extended precision numbers instead of machine numbers. Machine numbers have a precision of about 16, so subtracting a number 36 orders of magnitude smaller will not cause a change. For example:

b = 4.24835`10*^-18 - 1.3956`50*^18;
c = -4.24835`10*^-18 - 1.3956`50*^18;

b-c

8.496700000*10^-18

The back ticks ` are used to specify the precision to use. Also, it's simpler to use *^-18 instead of * 10^-18, as this creates the desired number directly without having to multiply the mantissa by a power of 10.

| improve this answer | |
$\endgroup$
  • $\begingroup$ please see the edit $\endgroup$ – Ragab Zidan Oct 5 '19 at 16:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.