我遇到了问题this https://stackoverflow.com/questions/8245909/how-to-use-boost-bisection以前但现在它在某种程度上起作用了。
现在我有以下问题。在使用相同的函数调用 boost::bisect 之前,我需要将值绑定到成员函数中。我发现还不错tutorial http://www.radmangames.com/programming/how-to-use-boost-bind我已经遵循了,但似乎我仍然做错了什么。
首先,我创建了测试类,我在其中进行了以下工作:
std::pair<double, double> result = bisect(&Func, 0.0, 1.0, TerminationCondition());
double root = (result.first + result.second) / 2;
之后,我“即时添加了绑定,因为我认为它可以工作”
std::pair<double, double> result = bisect(boost::bind(&CLASS::Function,this, _1), 0.0, 1.000000, TerminationCondition());
结果是一个错误。错误:抛出 'boost::exception_detail::clone_impl >' What() 实例后终止调用:函数 boost::math::tools::bisect 中出现错误:boost::math::tools 中的符号没有变化: :bisect,要么没有根可求,要么区间内有多个根(f(min) = -0.0032916729090909091)。
无论如何,这里的 class::function 由于某种原因不能作为具有绑定的成员函数。我以非会员身份测试过,可以用
double CLASS::Function(double c)
{
/* values: m_a, m_b, m_c, m_d, and m_minus are located in .h file */
normal norm;
double temp = m_d*sqrt(c);
double total = ((1-boost::math::pdf(norm,(m_a*c+m_b)/temp))-(1 - m_c)+boost::math::pdf(norm,(m_a*c+m_b)/temp));
return (total - m_minus);
}