# Real Results from NSolve

I have the following equation that I am solving with NSolve, but Mathematica is giving unusual results when I use the Reals option with the function.

Here is the equation:

Pr[n_, c_, p_] := CDF[BinomialDistribution[n, p], c]


Here is the result (sans Reals) containing real and imaginary solutions:

In[31]:= AQL=NSolve[Pr[52,0,p]==0.05 ,p]
Out[31]= {{p->0. -0.703608 I},{p->0. +0.707855 I},{p->0.0559822},{p->0.0628651 +0.113789 I},{p->0.0628651 -0.113789 I},{p->0.0834136 -0.225918 I},{p->0.0834136 +0.225918 I},{p->0.117328 -0.334753 I},{p->0.117328 +0.334753 I},{p->0.164114 -0.438707 I},{p->0.164114 +0.438707 I},{p->0.223089 -0.536263 I},{p->0.22309 +0.536263 I},{p->0.29335 -0.626051 I},{p->0.293392 +0.626008 I},{p->0.468801},{p->0.475677},{p->0.492169},{p->0.495198},{p->0.543052},{p->0.556686},{p->0.55761},{p->0.612101},{p->0.617682},{p->0.663548},{p->0.704702},{p->0.746556},{p->0.761696},{p->0.811269},{p->0.828215},{p->0.856825},{p->0.864034},{p->0.887535},{p->0.909784},{p->1.01007},{p->1.0245},{p->1.05859},{p->1.15054},{p->1.25355},{p->1.40169},{p->1.47447},{p->1.5849},{p->1.84392},{p->1.93027},{p->2.3004},{p->2.30967},{p->2.36224},{p->2.3929},{p->2.69307},{p->2.73103},{p->2.82902},{p->2.87612}}


Now, when Reals is added to the function, I get this result:

In[32]:= AQL=NSolve[Pr[52,0,p]==0.05 ,p,Reals]
Out[32]= {{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.},{p->1.}}


Is it possible that I am missing a numerical precision argument somewhere? If it is of any value to this discussion, the result that I need to extract is the first real solution, or p->0.0559822.

• NSolve[Pr[52, 0, p] == 1/20, p, Reals]
– Moo
Dec 21, 2019 at 13:49

Better use exact values, because they have infinite precision. Try:

NSolve[Pr[52, 0, p] == 5/100, p, Reals]
(* {{p -> 0.0559822}, {p -> 1.94402}} *)


Or:

(* exact numbers *)
Solve[Pr[52, 0, p] == 5/100, p, Reals]

(* specifying 30-digit precision *)
NSolve[Pr[52, 0, p] == 0.0530, p, Reals]

(* machine precision returns error message *)
FindRoot[Pr[52, 0, p] == 0.05, {p, 1/2}]

(* it works when higher precision is requested *)
FindRoot[Pr[52, 0, p] == 5/100, {p, 1/2}, WorkingPrecision -> 20]

• To be a valid distribution requires DistributionParameterAssumptions[BinomialDistribution[n, p]], i.e., 0 <= p <= 1. Consequently, use NSolve[Pr[52, 0, p] == 0.0520 && 0 <= p <= 1, p] and similar. Dec 21, 2019 at 16:40