【发布时间】:2014-06-10 17:01:14
【问题描述】:
我在 c++ 中将这个 wrapper 函数用于我在其他解决方案中看到的 gsl
gsl_function_pp Fp( std::bind(&Class::member_function, &(*this), std::placeholders::_1) );
gsl_function *F = static_cast<gsl_function*>(&Fp);
在 GSL 的文档中, https://www.gnu.org/software/gsl/manual/html_node/Error-Reporting-Examples.html#Error-Reporting-Examples
它说 int status = gsl_function..。 将给出错误代码。但是我不知道如何使用上面的包装函数获取状态。
******************************更新1
所以我用这个函数来解决 fzero 问题
double gsl_root(gsl_function *F, double x_lo, double x_hi) {
const gsl_root_fsolver_type *T;
gsl_root_fsolver *s;
T = gsl_root_fsolver_brent;
s = gsl_root_fsolver_alloc (T);
gsl_root_fsolver_set (s, F, x_lo, x_hi);
int status;
do {
status = gsl_root_fsolver_iterate(s);
x_lo = gsl_root_fsolver_x_lower (s);
x_hi = gsl_root_fsolver_x_upper (s);
status = gsl_root_test_interval (x_lo, x_hi, 0, 1e-12);
} while(status == GSL_CONTINUE);
gsl_root_fsolver_free(s);
return 0.5*(x_lo + x_hi);
}
如何获得上述函数的状态输出,我尝试了迭代和区间函数但没有奏效,我已经不知道为什么和如何。
例如,当 GSl 没有解决方案时,我会收到如下错误:
gsl: brent.c:74: ERROR: endpoints do not straddle y=0
Default GSL error handler invoked.
所以这就是我真正想要的。我只想处理这种情况。很抱歉造成混淆,希望现在问题更清楚。
【问题讨论】:
-
你好。首先:我已经写了一些我使用这个包装器的答案,但我不是它的原始创建者。这是一个相对众所周知的解决方案。因此,来自“Vinicius Miranda”的包装是不公平的(也无助于引用)。您能否说“我在这些解决方案上看到的包装器”并实际指定您在哪里看到它以及如何在代码中使用它..
-
第二:gsl 中有返回错误状态的函数,例如:“int gsl_integration_qag(...)”。 gsl_function 不是其中之一。实际上 gsl_function 只是一个包含函数和 void 指针的 c-struct。请参阅源代码行 123-130 中的 gsl_math.h
-
:( 不,我没有理解或以错误的方式问。现在让我再说一遍;在我上面的例子中,我正在调用一个带有包装器的成员函数。哪个变量将基本上保持状态? 没关系 gsl_func 是一个结构,但在我的情况下我如何使用那个 gsl_inteegration_qag()?
-
更新了问题!更新 1 是最近的
-
更新 2...我真的希望这个问题现在已经结束了!
标签: c++ exception wrapper handle gsl