Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/142.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用boost库工具/root进行编译时出错_C++_Boost_Compilation_Compiler Errors - Fatal编程技术网

C++ 使用boost库工具/root进行编译时出错

C++ 使用boost库工具/root进行编译时出错,c++,boost,compilation,compiler-errors,C++,Boost,Compilation,Compiler Errors,我最近用apt-get在ubuntu上下载了boost库 我已经编写了以下代码,它定义了一个一元函子,然后尝试使用boost库查找它的根(我现在把它全部放在main.cpp中,稍后将其拆分): 但是,我得到以下错误: In file included from /usr/include/boost/math/tools/roots.hpp:32:0, from /usr/include/boost/math/special_functions/detail/ig

我最近用apt-get在ubuntu上下载了boost库

我已经编写了以下代码,它定义了一个一元函子,然后尝试使用boost库查找它的根(我现在把它全部放在main.cpp中,稍后将其拆分):

但是,我得到以下错误:

In file included from /usr/include/boost/math/tools/roots.hpp:32:0,
                 from /usr/include/boost/math/special_functions/detail/igamma_inverse.hpp:16,
                 from /usr/include/boost/math/special_functions/gamma.hpp:1528,
                 from /usr/include/boost/math/special_functions/beta.hpp:15,
                 from /usr/include/boost/math/distributions/binomial.hpp:83,
                 from main.cpp:2:
/usr/include/boost/math/tools/toms748_solve.hpp: In function 'std::pair<T, T> boost::math::tools::toms748_solve(F, const T&, const T&, Tol, uintmax_t&, const Policy&) [with F = MyBinom, T = int, Tol = boost::math::tools::eps_tolerance<double>, Policy = boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>, uintmax_t = long unsigned int]':
/usr/include/boost/math/tools/toms748_solve.hpp:475:71:   instantiated from 'std::pair<T, T> boost::math::tools::toms748_solve(F, const T&, const T&, Tol, uintmax_t&) [with F = MyBinom, T = int, Tol = boost::math::tools::eps_tolerance<double>, uintmax_t = long unsigned int]'
main.cpp:37:81:   instantiated from here
/usr/include/boost/math/tools/toms748_solve.hpp:467:81: error: no matching function for call to 'toms748_solve(MyBinom&, const int&, const int&, double, double, boost::math::tools::eps_tolerance<double>&, uintmax_t&, const boost::math::policies::policy<boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy, boost::math::policies::default_policy>&)'
/usr/include/boost/math/tools/toms748_solve.hpp:467:81: note: candidates are:
/usr/include/boost/math/tools/toms748_solve.hpp:283:17: note: template<class F, class T, class Tol, class Policy> std::pair<T, T> boost::math::tools::toms748_solve(F, const T&, const T&, const T&, const T&, Tol, uintmax_t&, const Policy&)
/usr/include/boost/math/tools/toms748_solve.hpp:458:24: note: template<class F, class T, class Tol> std::pair<T, T> boost::math::tools::toms748_solve(F, const T&, const T&, const T&, const T&, Tol, uintmax_t&)
/usr/include/boost/math/tools/toms748_solve.hpp:464:24: note: template<class F, class T, class Tol, class Policy> std::pair<T, T> boost::math::tools::toms748_solve(F, const T&, const T&, Tol, uintmax_t&, const Policy&)
/usr/include/boost/math/tools/toms748_solve.hpp:473:24: note: template<class F, class T, class Tol> std::pair<T, T> boost::math::tools::toms748_solve(F, const T&, const T&, Tol, uintmax_t&)
但是,这与我在尝试用C++完成之前使用的原型R代码的计算不一致:

> binomcalc <- function(p, p0, N, B){pbinom(B,N,p)-p0}
> uniroot(binomcalc, c(0,1), p0=0.05, B=75, N=4167)
$root
[1] 0.02178983

$f.root
[1] -0.0009172035

$iter
[1] 12

$estim.prec
[1] 6.103516e-05
>binomcalc单根(binomcalc,c(0,1),p0=0.05,B=75,N=4167)
$root
[1] 0.02178983
$f.root
[1] -0.0009172035
$iter
[1] 12
$estim.prec
[1] 6.103516e-05
我想知道他们为什么不同?我需要调整公差或精度之类的东西吗

谢谢, 本。

我的编译器提到

\usr\include\boost\math\tools\toms748_solve.hpp|283 col 17| note:   template argument deduction/substitution failed:
\usr\include\boost\math\tools\toms748_solve.hpp|468 col 81| note:   deduced conflicting types for parameter 'const T' ('int' and 'double')
所以。。。这很清楚:)解决它:

输出:

Let's take a look at the root
root bracketed: [ 1 , 1 ]
f(1)=0
f(1)=0
max_iter=2

查看

谢谢,有没有办法提高准确性?我已经用工作版本更新了原始问题。是的。但是,你应该将新的问题作为单独的问题发布。非常正确,我可以改变这一点-我想知道是这样还是boost邮件列表会更好我会在这里说/但我有偏见:)
> binomcalc <- function(p, p0, N, B){pbinom(B,N,p)-p0}
> uniroot(binomcalc, c(0,1), p0=0.05, B=75, N=4167)
$root
[1] 0.02178983

$f.root
[1] -0.0009172035

$iter
[1] 12

$estim.prec
[1] 6.103516e-05
\usr\include\boost\math\tools\toms748_solve.hpp|283 col 17| note:   template argument deduction/substitution failed:
\usr\include\boost\math\tools\toms748_solve.hpp|468 col 81| note:   deduced conflicting types for parameter 'const T' ('int' and 'double')
Result r1 = boost::math::tools::toms748_solve(myBinom95, 0., 1., tol, max_iter); // use the toms solve algorithm.
Let's take a look at the root
root bracketed: [ 1 , 1 ]
f(1)=0
f(1)=0
max_iter=2