Boost logo

Boost Users :

Subject: [Boost-users] Newbie math question - roots of a distribution
From: Benjamin Ward (ENV) (B.Ward_at_[hidden])
Date: 2014-02-06 15:18:23


Hi Boost list,

I've just installed and started to use boost for various problems and I've hit on a math problem I'd like to solve with it but I'm unsure on how to achieve it.

I've gone through the documentation and have worked out how to easily compute the value from a cdf of a binomial distribution:

#include <boost/math/distributions/binomial.hpp>
#include <iostream>
int main(){
    int numbertrials = 4164;
    double successprob = 10e-6;
    int numbersuccesses = 75
    boost::math::binomial mydistribution(numbertrials, successprob);
    double ans = cdf(mydistribution, numbersuccesses);
    std::cout << "The answer is " << ans << std::endl;
return 0;
}

But now I'd like to find the root of the cdf, in other words, I want to find the value of successprob, from numbertrials and numbersuccesses and ans.

Let's define ans as 0.95, by finding the root of cdf(mydistribution, numbersuccesses) - 1, using a root finding algorithm, I should be able to get the value of successprob. I've tried reading the roots documentation and looking at some examples but they use simple functions like x * sin(x) - there is only one variable and it is x, the binomial cdf has quite a few variables - number of trials, number of successes, probability of a single success. How can I define a function with boost::math::binomial that could be used with boosts root libraries to find the probability of success from the cdf, given I know ans, the number of successes, and the number of trials?

Thanks,
Ben W.



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net