I am trying to understand how WorkingPrecision
works, and in general how very small/large numbers are to be handled.
Let me preface I probably do not have sufficient theoretical knowledge on floating\arbitrary precision numbers: please do not hesitate to suggest a good book to understand the topic from the applications point of view.
Anyhow, I am dealing with the complete elliptic integral of the first kind, EllipticK
, which I believe displays a logarithmic divergence for $k \to 1$.
If I attempt
rooteK2[a_] :=
NSolve[{EllipticK[k] == a, 0 <= k <= 1}, k, WorkingPrecision -> 200]
I get no solutions.
Yet If I try
rootlog[a_] := NSolve[Log[x] == -a, x, WorkingPrecision -> 100]
I get
rootlog[1000]
{{x -> 1.1354838653147360985409388750662484019574316100903188426715526\
5915730430241273915784077651790431*10^-4343}}
which I find surprising, as I believe the divergence is similar (for $x \to 1$ and $x \to 0$ in the elliptic integral and logarithmic function respectively).
Further, If I try
EllipticK[0.9999999999999999]
I obtain
19.7547
but one more digit
EllipticK[0.99999999999999999]
and I get
ComplexInfinity
On the other hand
Log[1 - 0.99999999999999999]
returns
Indeterminate
and not Infinity. Further, in the example above with NSolve
, numbers such $10^-4343$ were seemingly handled, certainly smaller than $1 - 0.99999999999999999$.
I would be really interested to understand the difference and learn more abo about accuracy, thanks a lot, much appreciated.
EDIT Following Bob Hanlon's comments below, I would like to clarify I am using version 11.2. If I issue e.g.
EllipticK[0.9999999999999999999`100]
I do get an answer $\approx 23.26086 \dots$.
Yet, if I try to back-calculate the argument of EllipticK
used just above via rooteK2[23.26086`100]
(as defined at the beginning of the post)
I get no answer (differently from version 12.2).
EllipticK[0.99999999999999999]
The argument is a machine number so the calculation is done with machine precision. Specify a precision to use arbitrary-precision.EllipticK[0.99999999999999999`100]
orEllipticK[SetPrecision[1-10^-17, 100]]
orN[EllipticK[1-10^-17], 100]
$\endgroup$rooteK2[a_] := NSolve[{EllipticK[k] == a, 0 <= k <= 1}, k, WorkingPrecision -> 200]
still do not get a result forrooteK2[50]
norrooteK2[50.`300]
, could you please clarify further, thanks for the patience $\endgroup$rooteK2[50.`200]
works for me with version 12.1. What version are you using? $\endgroup$