《quantitative finance with cpp》阅读笔记11---用数值积分法计算从x到无穷大的定积分函数
作者:yunjinqi   类别:    日期:2023-12-27 13:26:24    阅读:124 次   消耗积分:0 分    

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);
}

对于高数学的不好的童鞋,这个题目的难点在于定积分换元法的转换方法,下面是推导方法

image.png



版权所有,转载本站文章请注明出处:云子量化, http://www.woniunote.com/article/376
上一篇:《quantitative finance with cpp》阅读笔记10---计算标准正太分布的概率密度及-1.96到1.96的累计分布
下一篇:《quantitative finance with cpp》阅读笔记12---正态分布累积分布函数的两种计算方法并对比结果