Write a function integralToInfinity that uses integration by substitution to transform an infinite integral to one the function integral can compute.
class RealFunction {
public:
/* A virtual destructor */
virtual ~RealFunction() {};
/* This method is abstract, there is
no definition */
virtual double evaluate(double x) = 0;
};
double integralToInfinity(RealFunction& f,double x,int nPoints) {
class Integrand : public RealFunction {
public:
double x;
RealFunction& f;
double evaluate(double s) {
return 1 / (s*s)*f.evaluate(1 / s + x - 1);
}
Integrand(double x, RealFunction& f) : x(x), f(f)
{}
};
Integrand i(x, f);
return integral(i, 0, 1, nPoints);
}对于高数学的不好的童鞋,这个题目的难点在于定积分换元法的转换方法,下面是推导方法

系统当前共有 481 篇文章