我有以下代码用于通过 boost 库进行集成。我试图将 double 运算符更改为 cpp_dec_float_50 运算符。
#include <iostream>
#include <boost/numeric/quadrature/adaptive.hpp>
#include <boost/numeric/quadrature/kronrodgauss.hpp>
#include <boost/numeric/quadrature/epsilon.hpp>
#include <boost/math/constants/constants.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
using boost::multiprecision::cpp_dec_float_50;
namespace quadrature = boost::numeric::quadrature;
double polynomial(int k , int n);
struct f
{
vector<double> poly;
double polysum(double x) const {
double s = 0;
double p = 1;
for (int i = 1; i < poly.size(); i++) {
p = p * x;
s += p * poly[i];
}
return s;
}
double operator()(double x)const {
return polysum(x) * log(x) / (1 + x);
}
};
int main()
{
int n = 2;
f fun;
double p = 0;
for (int i = 0; i <= n; i++)
{
p = polynomial(i, n);
fun.poly.push_back(p);
}
double answer, error_estimate;
quadrature::adaptive().relative_accuracy(1e-5).absolute_accuracy(1e-7)
(fun, 0., 1., answer, error_estimate);
cout << "ans" << answer << endl;
return 0;
}
double polynomial(int k , int n)
{
return k;
}
如果更改为:
cpp_dec_float_50 operator()(cpp_dec_float_50 x) const {
并将所有相关内容更改为 cpp_dec_float_50,然后出现错误列表,请参见此处
任何人都可以解决这个问题吗?
对于没有 Boost Quadrature 库的用户,您可以从这里下载它https://github.com/coolfluid/coolfluid3/tree/master/include/boost/numeric