数值积分的GSL值不正确

时间:2022-09-25 20:22:25

I have an Integrand which reads

我有一个被积函数

static double Integrand(double k , void * params)
{
 long double *p = (long double *)params;
  long double MassSquared = p[0];
  long double Temp = p[1];
  long double sign = p[2];

  long double EXP = std::exp(-std::sqrt(k*k+MassSquared/(Temp*Temp)));
  double res = 0;
  if(sign == -1)
  {
    res = k*k*std::log(1-exp(-std::sqrt(k*k+MassSquared/(Temp*Temp))));
  }
  else if(sign == +1)
  {
    res = k*k*std::log(1+exp(-std::sqrt(k*k+MassSquared/(Temp*Temp))));
  }
  return res;
};

This one is in a Class called VEffClass.

这是一个叫做VEffClass的类。

My Integration Routine would then be

我的集成例程将会是

long double VEffClass::NumIntInf(long double low, double sign, long double
MassSquared, long double Temp)
{
//long double  res = 0;
double up =
std::sqrt(std::log(C_threshold)*std::log(C_threshold)- MassSquared/(Temp*Temp));
long double StepSize = (up-low)/C_IntSteps;
long double par[3] = {MassSquared, Temp, sign};


 if(Temp == 0) return 0;

gsl_integration_workspace *w = gsl_integration_workspace_alloc(5e+5);
double result, error;
gsl_function F;
F.function = &VEffClass::Integrand;
F.params = ∥

gsl_integration_qags(&F, C_threshold, up, 1e-07, 0, 5e+5, w, &result,
&error);
gsl_integration_workspace_free(w);

return result;

}

with C_threshold = 1e-3;

C_threshold = 1 e - 3;

If I run NumIntInf(10^-3, +1 , 100, 500) the result is 1.83038. The Result given by Maple is ~ 6*10^9 . If I use a simple Simpsons 1/3 Method it differes about 1% from the Maple result.

如果我运行NumIntInf(10 ^ 3 + 1,100年,500年)的结果是1.83038。结果由枫~ 6 * 10 ^ 9。如果我使用简单的Simpsons 1/3方法,它与Maple结果的差异约为1%。

Can anyone point me to the Error?

有人能指出我的错误吗?

Thanks for any suggestions

谢谢你有什么建议

1 个解决方案

#1


0  

Whenever you ask a question that involves numerical results (and also bugs) you need to provide a concise code that we can analyze and run to reproduce your original problem. So yes, information is missing. We need

每当您提出一个涉及数值结果(以及bug)的问题时,您都需要提供一个简明的代码,我们可以对其进行分析和运行,以重现您的原始问题。是的,信息缺失了。我们需要

(1) concise code (we don't need the VEffClass!) with the GSL integration (you partially provided that - but your code is still quite complicated for stack overflow purposes).

(1)使用GSL集成(我们不需要VEffClass!)和GSL集成(您在一定程度上提供了这一点——但您的代码仍然非常复杂,用于堆栈溢出目的)。

(2) concise code with your implementation of the Simpson-rule.

(2)使用简单的代码实现辛普森规则。

(3) Snapshot of your maple calculation.

(3)枫木计算的快照。

(2) and (3) are quite important because your question arises due to the fact that methods (2) and (3) disagree with (1), which you assumed is the incorrect answer. Why did you assume that (1) is incorrect and not the other way around? Do you have an analytical solution to check the numbers?

(2)和(3)是非常重要的,因为你的问题是由于方法(2)和(3)不同意(1)这一事实而产生的,你假设这是错误的答案。为什么你认为(1)是不正确的,而不是相反?你有分析方法来检验这些数字吗?

When I analyzed, in Wolfram Mathematica, the integrand with the parameters values you provided in a comment, I got an answer that is consistent with the GSL calculation. So I can't reproduce your problem and without (2) + (3) I can only guess what went wrong...

当我分析,在Wolfram Mathematica,被集成和你提供的参数值,我得到一个与GSL计算一致的答案。所以我无法重现你的问题,没有(2)+(3)我只能猜测出哪里出错了……

I attached a snapshot of my Mathematica notebook.

我附上了我的Mathematica笔记本的快照。

数值积分的GSL值不正确

#1


0  

Whenever you ask a question that involves numerical results (and also bugs) you need to provide a concise code that we can analyze and run to reproduce your original problem. So yes, information is missing. We need

每当您提出一个涉及数值结果(以及bug)的问题时,您都需要提供一个简明的代码,我们可以对其进行分析和运行,以重现您的原始问题。是的,信息缺失了。我们需要

(1) concise code (we don't need the VEffClass!) with the GSL integration (you partially provided that - but your code is still quite complicated for stack overflow purposes).

(1)使用GSL集成(我们不需要VEffClass!)和GSL集成(您在一定程度上提供了这一点——但您的代码仍然非常复杂,用于堆栈溢出目的)。

(2) concise code with your implementation of the Simpson-rule.

(2)使用简单的代码实现辛普森规则。

(3) Snapshot of your maple calculation.

(3)枫木计算的快照。

(2) and (3) are quite important because your question arises due to the fact that methods (2) and (3) disagree with (1), which you assumed is the incorrect answer. Why did you assume that (1) is incorrect and not the other way around? Do you have an analytical solution to check the numbers?

(2)和(3)是非常重要的,因为你的问题是由于方法(2)和(3)不同意(1)这一事实而产生的,你假设这是错误的答案。为什么你认为(1)是不正确的,而不是相反?你有分析方法来检验这些数字吗?

When I analyzed, in Wolfram Mathematica, the integrand with the parameters values you provided in a comment, I got an answer that is consistent with the GSL calculation. So I can't reproduce your problem and without (2) + (3) I can only guess what went wrong...

当我分析,在Wolfram Mathematica,被集成和你提供的参数值,我得到一个与GSL计算一致的答案。所以我无法重现你的问题,没有(2)+(3)我只能猜测出哪里出错了……

I attached a snapshot of my Mathematica notebook.

我附上了我的Mathematica笔记本的快照。

数值积分的GSL值不正确