GSL:错误报告
|
我想使用GSL进行集成
http://www.gnu.org/software/gsl/manual/html_node/Numerical-Integration.html
但是,我发现没有便捷的方法如何集成功能
(示例http://www.gnu.org/software/gsl/manual/html_node/Numerical-integration-examples.html中的函数f)
可以向集成商报告错误。我想集成一个功能,该功能本身是由可能失败的集成产生的。这是我的示例程序
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>
double f (double x, void * params) {
GSL_ERROR(\"test error\",GSL_FAILURE);
return 0.0;
}
int main (void)
{
gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
double result, error;
gsl_function F;
F.function = &f;
gsl_set_error_handler_off();
int status = gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
w, &result, &error);
printf (\"status = %d\\n\", status);
status = GSL_FAILURE;
printf (\"status = %d\\n\", status);
gsl_integration_workspace_free (w);
return 0;
}
产生输出
状态= 0
状态= -1
我认为集成商应该宁愿停止并返回我的错误代码。我该如何实现?
非常感谢您的帮助!!!
2011-04-27:在Brian Gough告诉我之后,我也尝试了这种变体,
#include <stdio.h>
#include <math.h>
#include <gsl/gsl_integration.h>
#include <gsl/gsl_errno.h>
double f (double x, void * params) {
GSL_ERROR(\"test error\",GSL_FAILURE);
return GSL_NAN;
}
int main (void)
{
gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000);
double result, error;
gsl_function F;
F.function = &f;
gsl_set_error_handler_off();
int status = gsl_integration_qags (&F, 0, 1, 0, 1e-7, 1000,
w, &result, &error);
printf (\"status = %d\\n\", status);
status = GSL_FAILURE;
printf (\"status = %d\\n\", status);
gsl_integration_workspace_free (w);
return 0;
}
它也没有帮助。我现在将填写一个错误报告。
没有找到相关结果
已邀请:
3 个回复
脖呐
在返回NAN之前,该函数已经返回,因为GSL_ERROR 已被调用。关闭处理程序,仅让第一行执行 没有。默认错误处理程序在打印后中止程序 错误信息。 我不认为这是一个错误。也许您可以编写自己的错误处理程序 解决您的问题。例如,您可以使用\“ goto \”跳出 gsl_integration_qags,或设置一些全局变量以指示 积分结果不正确。 PS:我相信您需要这个宏, 巨集:GSL_ERROR_VAL(原因,gsl_errno,值) 该宏与GSL_ERROR相同,但返回用户定义的值 值而不是错误代码。可用于数学 返回浮点值的函数。 以下示例显示了如何以数学方式返回NaN 使用GSL_ERROR_VAL宏的奇异性
所以我根据
一切都按预期进行...
掏得透垦滩
笛驮型迸