Message Boards Message Boards

0
|
2489 Views
|
3 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Different results when using different representations of the same number?

Using Mathematica 10.1, depending on whether I write a numerical constant as 0.6x10^-15, or 6x10^-16, I get very different answers from the following code to solve a cubic equation. The first form leads to a presumed, nonphysical, imaginary root, and the second to a physical real root. When printed, the numbers are not different.

I know now to avoid the first form, but why?

P0 = 2*10^-6; E0 = 1*10^-5; Z0 = 3*10^-6;
KdP = 8*10^-16; (* assumed protein Kd *)
KdE = 0.6*10^-15;  
N[KdE]
a := KdP + KdE + P0 + E0 - Z0;
b := KdE*(P0 - Z0) + KdP*(E0 - Z0) + KdP*KdE;
c := -KdP*KdE*Z0;
theta := ArcCos[(-2*a^3 + 9*a*b - 27*c)/(2 Sqrt[(a^2 - 3*b)^3])];
Z := -a/3 + (2/3)*Cos[theta/3]*Sqrt[a^2 - 3 b];
PZ := P0*Z/(Z + KdP);
EZ := E0*Z/(Z + KdE);
N[Z + EZ + PZ, 3] (* Zn conserved? *)
N[PZ/P0, 6] (*fraction Zn bound to P *)
N[EZ/E0, 6] (*same for EDTA *)

Presumed Incorrect result from above:

6.*10^-16 
0.0000119979 + 2.08196*10^-7 I 
0.999686 + 0.0219132 I 
0.999855 + 0.016437 I 

Correct result if I write KdE = 6*10^-16

6.*10^-16
3.00*10^-6
0.207304
0.258539
POSTED BY: Jim Remington
3 Replies
Posted 4 years ago

That all makes sense. It is great (and very useful) that the approach works for exact rational numbers.

Thanks very much for your help!

POSTED BY: Updating Name

You define

theta := ArcCos[(-2*a^3 + 9*a*b - 27*c)/(2 Sqrt[(a^2 - 3*b)^3])];

The argument of the ArcCos is a function of KdE, which is very close to -1 when Kde=0:

In[101]:= Block[{KdE = 0},
 N[1 + (-2*a^3 + 9*a*b - 27*c)/(2 Sqrt[(a^2 - 3*b)^3]), 20]]

Out[101]= 1.6131687242639028603*10^-20

This means that you are walking awfully close to a singular point in ArcCos. Good luck.

POSTED BY: Gianluca Gorni
Posted 4 years ago

Hi Jim,

It is due to the difference between using exact and approximate numbers.

0.6*10^-15 // FullForm
(* 6.`*^-16 *)

6*10^-16 // FullForm
(* Rational[3, 5000000000000000] *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract