# Why doesn't NSolve work for this equality? Wildly incorrect solutions are given in certain cases

I am trying to write a function that solves for p in the following equation:

PDF[BinomialDistribution[n, p], x] == op


The variables 'n', 'x', and 'op' are known. Generally using NSolve like so works fine:

NSolve[PDF[BinomialDistribution[10, p], 0] == 0.95 && 0 < p < 1, p, Reals]

(* {{p -> 0.0051162}} *)

N[PDF[BinomialDistribution[10, 0.005116196891823705], 0]]

(* 0.95 *)


But for certain 'n', NSolve gives wildly inaccurate solutions:

NSolve[PDF[BinomialDistribution[80, p], 0] == 0.95 && 0 < p < 1, p, Reals]

(* {{p -> 0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p ->
0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p ->
0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p ->
0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p ->
0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p ->
0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p -> 0.999834}, {p ->
0.999834}, {p -> 0.999834}} *)


Here we just have 23 duplicate solutions, each of which are very inaccurate. Oddly this seems to be a problem only for certain values of 'n' without an obvious pattern; for example, it seems to affect 51 <= n <= 98 but not 'n' immediately outside that range.

Any Mathematica pros out there that might know how I can fix this?

• It may be a numerical precision problem. Try using $95/100$ instead of $0.95$ in your equation. Aug 26 '15 at 22:29
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Aug 26 '15 at 23:00

Increase WorkingPrecision:
NSolve[PDF[BinomialDistribution[80, p], 0] == 0.95200 && 0 < p < 1,