与 c++ 的数值积分在具有固定常数离散化的给定网格上

发布于 2024-12-29 08:42:43 字数 386 浏览 1 评论 0原文

我有以下问题:

我的 C++ 代码可以

计算两个函数f1(i1,i2,i3,i4)

f2(j1,j2)

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

集合 {i1,i2,i3,i4} 和 {j1,j2} 在具有某个恒定离散化步骤“h”的固定网格上给出。

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

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

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

非常感谢

I have the following problem:

My c++ code can compute two functions

f1(i1,i2,i3,i4)

f2(j1,j2)

for every set of {i1,i2,i3,i4} I get some value of f1 and for every set of {j1,j2} I get some value of f2.

the sets {i1,i2,i3,i4} and {j1,j2} are given on a FIXED mesh with some constant discretisation step "h".

I need to calculate, in mathematical language, an Integral F3(x1,x3)=Integral[f1(x1,x2,x3,x4)*f2(x3,x4) dx3 dx4]

The the simple summation is not good enough, since f2 has many jumps.

Is there some c++ library which can do this sort of integration? Or some algorhithm which is easy to implement (I am not really good on c++)

many thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

唔猫 2025-01-05 08:42:43

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

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

If you only have the values at the mesh points and no further mathematical knowledge of the form of the curves there's nothing better you can do than the trivial summation.

There's no way else than to change the mesh or use completely other methods like http://en.wikipedia.org/wiki/Monte_Carlo_integration

猫弦 2025-01-05 08:42:43

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

例如,如果您知道函数相当平滑,则不应使用线性插值。如果需要的话,可以做一些更复杂的事情。但如果没有此类规则,积分问题就无法得到很好的定义。

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

Integration is defined for functions of real arguments. Hence if you only know your functions on a fixed mesh, you need to supply an additional rule of how you define your function for arguments in between the mesh points. This really doesn't have much to do with programming, it's just math.

For example, if you know that your function is reasonably smooth, you san use linear interpolation. Of something more complicated, if you need to. But without some rule of this sort, the integration problem is simply not well defined.

Once you have such a rule -- which can only come from an underlying meaning of your functions --- you can start choosing an integration algorithm. For functions of four variables, I'd second the suggestion by Johan Lundberg to look into Monte Carlo integrators.

薔薇婲 2025-01-05 08:42:43

您可以使用辛普森规则( http://en.wikipedia.org/wiki/Simpson%27s_rule< /a>)。但是,正如 Johan 提到的,如果 f2 陡峭且不稳定,则减小步长 h 是唯一的解决方案。您可能需要考虑的另一种方法是网格上的变量 h。即:

  1. 从全局公共 h 开始 将
  2. 空间划分为更小的子空间
  3. 计算每个子空间的积分
  4. 使用步长 h/2 重新计算每个子空间的积分
  5. 仅对于积分(h 和 h/2)之间差异较大的子空间重复上述操作提到的步骤(从步骤 3 开始)

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)
九局 2025-01-05 08:42:43

你已经提到你知道 f2 上的跳转,你不能将 f2 分成 f2 = f2a + f2b,其中; f2a 是一个平滑函数,传统的数值积分方法就足够了,而 f2b 是一个非常简单的跳跃函数,您可以解析计算面积,因为它很简单。然后您只需添加这些值即可,因为积分是线性运算。我认为这完全取决于您对 f2 的了解。

You've mentioned that you know the jumps on f2, can't you separate f2 into f2 = f2a + f2b, where; f2a is a smooth function, on which, the conventional numerical integration methods will be sufficient, and f2b is a very simple function with jumps, which, you can calculate the area analytically since it's simple. Then you can just add the values since integration is a linear operation. It all depends on what you know about f2 really, I think.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文