5

我有以下问题:

我的 C++ 代码可以计算两个函数

f1(i1,i2,i3,i4)

f2(j1,j2)

对于每组 {i1,i2,i3,i4},我得到一些 f1 的值,对于每组 {j1,j2},我得到一些 f2 的值。

集合 {i1,i2,i3,i4} 和 {j1,j2} 在 FIXED 网格上给出,具有一些恒定离散化步长“h”。

我需要用数学语言计算积分 F3(x1,x3)=Integral[f1(x1,x2,x3,x4)*f2(x3,x4) dx3 dx4]

简单的求和不够好,因为 f2 有很多跳跃。

是否有一些可以进行这种集成的 c++ 库?或者一些易于实现的算法(我不太擅长c++)

非常感谢

4

4 回答 4

3

如果您只有网格点处的值并且没有关于曲线形式的进一步数学知识,那么没有什么比简单的求和更好的了。

除了更改网格或完全使用其他方法之外别无他法,例如http://en.wikipedia.org/wiki/Monte_Carlo_integration

于 2012-01-25T19:42:29.450 回答
1

You can use Simpson's rule ( http://en.wikipedia.org/wiki/Simpson%27s_rule ). But, as Johan mentioned, if f2 is steep and erratic decreasing step size h is the only solution. Another approach you might want to consider is variable h across the mesh. That is:

1. Start with a global common h
2. Divide the space into smaller subspaces
3. Calculate integral for each subspace
4. Recalculate integral for each subspace using step size h/2
5. For only subspaces where difference between integrals (h and h/2) is substantial repeat the above mentioned steps (From step 3)
于 2012-01-25T19:51:48.323 回答
1

积分是为实参函数定义的。因此,如果您只知道固定网格上的函数,则需要提供一条附加规则,说明如何为网格点之间的参数定义函数。这真的与编程没有太大关系,它只是数学。

例如,如果您知道您的函数相当平滑,则可以使用线性插值。更复杂的事情,如果你需要的话。但是如果没有这种规则,集成问题就没有很好地定义。

一旦你有了这样的规则——它只能来自你函数的潜在含义——你就可以开始选择一个集成算法。对于四个变量的函数,我会赞同 Johan Lundberg 的建议,即研究蒙特卡洛积分器。

于 2012-01-25T20:05:23.163 回答
0

您提到您知道 f2 上的跳跃,您不能将 f2 分成 f2 = f2a + f2b,其中;f2a 是一个光滑函数,在其上,常规的数值积分方法就足够了,而 f2b 是一个非常简单的带有跳跃的函数,因为它简单,所以可以解析地计算面积。然后您可以添加值,因为积分是线性运算。我认为这完全取决于你对 f2 的了解。

于 2012-01-26T13:44:56.047 回答