我有以下代码(很抱歉这么长):
double primeValue( const func1D &func,
const double lowerBound, const double upperBound,
const double pole )
{
// check bounds
if( lowerBound >= upperBound )
throw runtime_error( "lowerBound must be smaller than upperBound!" );
// C++0x way of writing: fullFunc(x) = func(x)/(x-a)
func1D fullFunc =
bind( divides<double>(), // division of
bind(func, _1), // f(x), with _1 = x
bind(minus<double>(), _1, pole) ); // by x-a, with _1 = x
// pole not in domain
if( pole<lowerBound || pole>upperBound)
{
cout << "Case 1" << endl;
return integrateSimpson( fullFunc, 1000, lowerBound, upperBound );
}
// pole closer to upper bound
else if( upperBound-pole < pole-lowerBound )
{
cout << "Case 2" << endl;
// C++0x way of writing g(x) := [f(x)-f(2a-x)]/(x-a)
func1D specialFirstFunc =
bind( std::divides<double>(), // division of
bind(minus<double>(), // numerator:
bind(func, _1), // f(x) minus
bind(func, bind(minus<double>(), 2.*pole, _1))), //f(2a-x)
bind(minus<double>(), _1, pole) ); // denominator: x-a
const double trickyPart = integrateSimpson( specialFirstFunc, 1000, pole+.000001, upperBound );
const double normalPart = integrateSimpson( fullFunc, 1000, lowerBound, 2.*pole-upperBound );
cout << "Tricky part: " << trickyPart << endl;
cout << "Normal part: " << normalPart << endl;
return trickyPart + normalPart;
}
else // pole closer to lower bound
{
cout << "Case 3" << endl;
// C++0x way of writing g(x) := [f(x)-f(2a-x)]/(x-a)
func1D specialFirstFunc =
bind( std::divides<double>(), // division of
bind(minus<double>(), // numerator:
bind(func, _1), // f(x) minus
bind(func, bind(minus<double>(), 2.*pole, _1))), //f(2a-x)
bind(minus<double>(), _1, pole) ); // denominator: x-a
const double trickyPart = integrateSimpson( specialFirstFunc, 1000, lowerBound, pole-.00001 );
const double normalPart = integrateSimpson( fullFunc, 1000, 2.*pole-lowerBound, upperBound );
cout << "Tricky part: " << trickyPart << endl;
cout << "Normal part: " << normalPart << endl;
return trickyPart + normalPart;
}
}
它使用复杂分析数学领域的主值概念,在包含奇点(极点)的实轴上集成函数。这个
bind
和
function
零件将原始功能f(x)修改为
(f(x)-f(2*极x))/(x-a)
它甚至为我的简单测试用例函数提供了正确的结果。如有要求,我可以提供其他详细信息:
typedef std::function<double (double)> func1D;
double integrateSimpson( func1D, const size_t nSteps, const double lowerBound, const double upperBound);
后者使用简单的Simpson集成规则进行集成。可以提供代码,但与手头的问题不太相关。
这与GCC 4.4 +(用4.4.5和4.5.2预测试,cFLAGS=“-O2-STD= C++0X-PoANDIC-WALW-WEUT”)进行比较,但在MSVC 2010上产生内部报头错误(C2664)。(如果需要,我可以提供错误输出,完全没有对我的代码的引用!!).
我在MSVC中发现错误了吗?
谢谢!