Re: Calculate n in binomial distribution
- To: mathgroup at smc.vnet.net
- Subject: [mg101638] Re: Calculate n in binomial distribution
- From: Ray Koopman <koopman at sfu.ca>
- Date: Sun, 12 Jul 2009 05:49:42 -0400 (EDT)
- References: <h229dp$i0v$1@smc.vnet.net> <h27fe4$cmb$1@smc.vnet.net>
Further to my previous post, here is a better binomsearch: binomsearch2[p_,k_,test_] := Module[{lo = k, mid, hi = k+1, c}, While[cf[hi,p,k] > test, lo = hi; hi *= 2]; While[lo <= hi, If[(c = cf[mid = Quotient[lo+hi,2],p,k]) === test, Return[mid]]; If[c < test, hi = mid - 1, lo = mid + 1]]; lo]