R中的发散积分在Wolfram中可解决 [英] Divergent Integral in R is solvable in Wolfram

查看:126
本文介绍了R中的发散积分在Wolfram中可解决的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我之前也问过同样的问题,但是由于我很陌生,所以这个问题被问得很差并且无法重现.因此,我尝试在这里做得更好. (如果我只编辑旧的,可能没人会读)

I know that I asked the same question before, but as I am pretty new here the question was asked poorly and not reproducible. Therefore I try to do it better here. (If I only edit the old one probably nobody will read it)

我有一个要积分的双重积分:这是一张图片

I have this double integral that I would like to integrate:Here is a picture

ff<-function(g,t) exp((16)*g)*exp(-8*t-(-t-0.01458757)^2/(0.0001126501))

integrate(Vectorize(function(t) integrate(function(g) 
                                          ff(g,t), -2.5,0)$value), -2, 2)

在R中运行它会给我错误:

Running this in R gives me the error:

  the integral is probably divergent

当我尝试在Wolfram中运行sam函数时,它给了我一个适当的值:(我必须切换g = x和t = y)

When I try to run the sam function in Wolfram it gives me a proper value: (i had to switch g=x and t=y)

链接:

如您所见,它得到了有限的结果,有人可以在这里帮助我吗?

As you can see it gets a finite result, can somebody help me out here?

我在定义的区域上绘制了函数,但是找不到奇异性问题.参见:

I plotted the function on the defined area and couldn't find a singularity issue. see:

library('Plot3D')
x <- seq(-2.5,0, by = 0.01) #to see the peak change to: seq(-0.2,0, by = 0.001)
y <- seq(-2,2, by = 0.01) #"": seq(-0.1,0.1, by = 0.001)
grid <- mesh(x,y) 
z <- with(grid,exp((16)*x)*
  exp(-8*y-(-0.013615734-y-0.001+0.5*0.007505^2*1)^2/(2*0.007505^2)))
persp3D(z = z, x = x, y = y)

感谢您的帮助,我希望这个问题比以前的问题更好.

Thanks for your help and I hope the question is better structured then the old one.

推荐答案

It's also worth noting that in the integrate.c source file, the description for the error message is

error messages
...
ier = 5 the integral is probably divergent, or
    slowly convergent. it must be noted that
    divergence can occur with any other value of ier.

因此,尽管该消息显示可能存在分歧",但似乎在您的代码中它却趋于缓慢收敛.

so despite the fact the message says "probably-divergent" it seems with your code it is more likely to be slowly convergent.

此外,如果设置了stop.on.error=FALSE

r <- integrate(Vectorize(function(t) 
    integrate(function(g) ff(g,t), -2.5,0)$value
), -2, 2, stop.on.error=FALSE); 
r$value

R并不像Mathematica之类的Wolfram产品那样声称自己是花哨的数学求解器.它没有对积分进行任何符号简化,而这正是Wolfram多年来不断完善的东西.如果您只是想数值地求解一堆双重积分,那么Mathematica或Maple之类的程序可能是更好的选择. R似乎并没有在其中花费大量开发资源.

R doesn't claim to be a fancy mathematical solver like the Wolfram products such as Mathematica. It doesn't do any symbolic simplifications of integrals and that's the kind of stuff that Wolfram's been perfecting over the years. if you're just looking to numerically solve a bunch of double integrals, programs like Mathematica or Maple are probably better choices. That just doesn't seem to be where R spends as much of its development resources.

这篇关于R中的发散积分在Wolfram中可解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆