I am trying to solve for \[Epsilon]
, given three input paramters n
, x
and eps
. Only FindInstance
provides a solution for me whereas NSolve
and NSolveValues
fail.
Why does this happen?
$PreRead = (# /.
s_String /;
StringMatchQ[s, NumberString] &&
Precision@ToExpression@s == MachinePrecision :> s <> "`50." &);
kldFunc[x_, y_] := x Log[x/y] + (1 - x) Log[(1 - x)/(1 - y)];
n = 10.^13.; x = 6. 10.^9.; eps = 10.^-20.;
Clear[\[Epsilon], \[Mu], p];
\[Mu] = x + n \[Epsilon];
p = \[Mu]/n;
\[Epsilon] = \[Epsilon] /.
Flatten[FindInstance[
Exp[-kldFunc[p - \[Epsilon], p] n] == eps &&
1. > \[Epsilon] > 0., \[Epsilon], Reals] ]
Clear[\[Epsilon], \[Mu], p];
\[Mu] = x + n \[Epsilon];
p = \[Mu]/n;
\[Epsilon] =
NSolveValues[
Exp[-kldFunc[p - \[Epsilon], p] n] == eps &&
1. > \[Epsilon] > 0., \[Epsilon], Reals]
Clear[\[Epsilon], \[Mu], p];
\[Mu] = x + n \[Epsilon];
p = \[Mu]/n;
\[Epsilon] =
NSolve[Exp[-kldFunc[p - \[Epsilon], p] n] == eps &&
1. > \[Epsilon] > 0., \[Epsilon], Reals]
EDIT
I tried plotting the two function to find the intersection
$PreRead = (# /.
s_String /;
StringMatchQ[s, NumberString] &&
Precision@ToExpression@s == MachinePrecision :>
s <> "`100." &);
kldFunc[x_, y_] := x Log[x/y] + (1 - x) Log[(1 - x)/(1 - y)];
n = 10.^13.; x = 6. 10.^9.; eps = 10.^-20.;
Clear[\[Epsilon], \[Mu], p];
\[Mu] = x + n \[Epsilon];
p = \[Mu]/n;
Plot[{10^-20, Exp[-kldFunc[p - \[Epsilon], p] n]}, {\[Epsilon],
7 10^-8, 8 10^-8}, WorkingPrecision -> 50]
I tried to extract the intersection point using
plot1 = Plot[
Exp[-kldFunc[p - \[Epsilon], p] n], {\[Epsilon], 7 10^-8,
8 10^-8}, WorkingPrecision -> 50];
plot2 = Plot[10^-20, {\[Epsilon], 7 10^-8, 8 10^-8},
WorkingPrecision -> 50];
intersections = Graphics`Mesh`FindIntersections[{plot2, plot1}]
but it does'nt give an output.(I'm running on 13.3. See related)
NSolve
, Details and Options bullet item: "NSolve
deals primarily with linear and polynomial equations.` It has only limited capabilities for handling transcendental equations. $\endgroup$FindInstance
works most of the time but sometimes it runs for a couple of minutes without being able to find a solution. $\endgroup$E^(1.0...00*10^13 (-((1 +\[Epsilon] - 1.0...00*10^-13 (6.00...0*10^9 + 1.000...000*10^13\[Epsilon])) Log[( 1 + \[Epsilon] - 1.0000..0000*10^-13 (6.0000...00*10^9 + 1.0000...000*10^13 \[Epsilon]))/( 1 - 1.0000..000*10^-13 (6.00...0*10^9 + 1.000...0000*10^13 \[Epsilon]))]) - (-\[Epsilon] + 1.0000..0000*10^-13 (6.0000...0000*10^9 + 1.00...000*10^13 \[Epsilon])) Log[( 1.000...000*10^13 (-\[Epsilon] + 1.0000...0000*10^-13 (6.00...000*10^9 + 1.00...00000*10^13 \[Epsilon])))/( 6.00000...0000*10^9 + 1.000..000000*10^13 \[Epsilon])])) == 1.0..0000000*10^-20
. $\endgroup$FindRoot
would be my go-to for this.kldFunc[x_, y_] := x Log[x/y] + (1 - x) Log[(1 - x)/(1 - y)]; n = 10^13; x = 6 *10^9; eps = 10^-20; \[Mu] = x + n \[Epsilon]; p = \[Mu]/n; In[59]:= FindRoot[ N[Exp[-kldFunc[p - \[Epsilon], p] n] - eps, 50] == 0, {\[Epsilon], 0, 1}, WorkingPrecision -> 30] Out[59]= {\[Epsilon] -> 7.43192053584110156413007451123*10^-8}
$\endgroup$