j*c 发帖数: 97 | 1 can anyone help me out of this problem: I need to integrate x^n e^[-x]
for 0
the error tolerence can be as large as 0.01, but I need a really fast
method.
thanks |
g***i 发帖数: 90 | 2 hehe, i just heard of this problem too. also interested
【在 j*c 的大作中提到】 : can anyone help me out of this problem: I need to integrate x^n e^[-x] : for 0: the error tolerence can be as large as 0.01, but I need a really fast : method. : thanks
|
h***o 发帖数: 539 | 3 oh yeah, 想出个好办法
分步积分,每分步一次x^n降一次方,既然n < 5, 顶多4次,就可以让
x^n的n > 0 and < 1,这个时候的积分值一定是在积分x*exp[-x]和积分exp[-x]
之间,linear interpolate(normal scale or log scale)一下,应该差不
多了吧
【在 j*c 的大作中提到】 : can anyone help me out of this problem: I need to integrate x^n e^[-x] : for 0: the error tolerence can be as large as 0.01, but I need a really fast : method. : thanks
|
c*******e 发帖数: 8624 | 4 对n积分还是对x积分?
对x积分的话是不是(a,b)
0.05<=a
【在 j*c 的大作中提到】 : can anyone help me out of this problem: I need to integrate x^n e^[-x] : for 0: the error tolerence can be as large as 0.01, but I need a really fast : method. : thanks
|
c*******e 发帖数: 8624 | 5 gaussian quadrature
每个sub interval上点如果能多取一点的话
不知道能不能到需要的精度,tolerance可以这样取
两个不同精度,高的当作真值,点怎么取反正(-1,1)上
都可以查到,然后把每个sub interval map到(-1,1)
上面就可以了
不过恐怕不会很快
【在 c*******e 的大作中提到】 : 对n积分还是对x积分? : 对x积分的话是不是(a,b) : 0.05<=a
|
j*c 发帖数: 97 | 6 you will failed if you try. That's what I'm doing now. for x~0.1, the error
will be about 10%(signle precision), and for x<0.1 single precision will fail.
I can't use double precision for executing time requirement.
btw: the job is pretty simple: n is integer and 0
actually I use table interpolation for n=-1 in a x=i^2 x0 scale
【在 h***o 的大作中提到】 : oh yeah, 想出个好办法 : 分步积分,每分步一次x^n降一次方,既然n < 5, 顶多4次,就可以让 : x^n的n > 0 and < 1,这个时候的积分值一定是在积分x*exp[-x]和积分exp[-x] : 之间,linear interpolate(normal scale or log scale)一下,应该差不 : 多了吧
|
j*c 发帖数: 97 | 7 I didn't try this method, but I think it will take as much time as Simpson
does for that error tolerance.
correct, this is exactly what I mean. typically b/a<1.2
【在 c*******e 的大作中提到】 : gaussian quadrature : 每个sub interval上点如果能多取一点的话 : 不知道能不能到需要的精度,tolerance可以这样取 : 两个不同精度,高的当作真值,点怎么取反正(-1,1)上 : 都可以查到,然后把每个sub interval map到(-1,1) : 上面就可以了 : 不过恐怕不会很快
|
c*******e 发帖数: 8624 | 8 simpson's rule误差我记得好象是O(h^4),gaussian至少能到O(h^5)
(同样是3个点),数值积分里面一般最花时间的是function evaluation
这两种方法都在3个点上evaluate,应该花的时间不会差很多
【在 j*c 的大作中提到】 : I didn't try this method, but I think it will take as much time as Simpson : does for that error tolerance. : : correct, this is exactly what I mean. typically b/a<1.2
|
h***o 发帖数: 539 | 9 what? n is an integer?
if it's not a typo...you can get the exact result without much
computing
【在 j*c 的大作中提到】 : you will failed if you try. That's what I'm doing now. for x~0.1, the error : will be about 10%(signle precision), and for x<0.1 single precision will fail. : I can't use double precision for executing time requirement. : btw: the job is pretty simple: n is integer and 0: actually I use table interpolation for n=-1 in a x=i^2 x0 scale
|
c*******e 发帖数: 8624 | 10 n is a integer and 0
then n=1,2,3,4
then you should be able to do it analytically yah
for n=1: -x*exp(-x)-exp(-x)
n=2: -x^2*exp(-x)-2*x*exp(-x)-2*exp(-x)
n=3: -x^3*exp(-x)-3*x^2*exp(-x)-6*x*exp(-x)-6*exp(-x)
n=4: -x^4*exp(-x)-4*x^3*exp(-x)-12*x^2*exp(-x)-24*x*exp(-x)-24*exp(-x)
【在 j*c 的大作中提到】 : you will failed if you try. That's what I'm doing now. for x~0.1, the error : will be about 10%(signle precision), and for x<0.1 single precision will fail. : I can't use double precision for executing time requirement. : btw: the job is pretty simple: n is integer and 0: actually I use table interpolation for n=-1 in a x=i^2 x0 scale
|
|
|
c*******e 发帖数: 8624 | 11 even not, here is the solution given by maple:
1/(1+n)*x^(1/2*n)*exp(-1/2*x)*WhittakerM(1/2*n,1/2*n+1/2,x)
WhittakerM() is a whatever function, you should
be able to find tables to evaluate, hehe
【在 h***o 的大作中提到】 : what? n is an integer? : if it's not a typo...you can get the exact result without much : computing
|
h***o 发帖数: 539 | 12 it could be a huge table...hiahia
【在 c*******e 的大作中提到】 : even not, here is the solution given by maple: : 1/(1+n)*x^(1/2*n)*exp(-1/2*x)*WhittakerM(1/2*n,1/2*n+1/2,x) : WhittakerM() is a whatever function, you should : be able to find tables to evaluate, hehe
|
c*******e 发帖数: 8624 | 13 呵呵,这种东西我估计计算软件里面肯定都有了
找个现成的用上就可以了
【在 h***o 的大作中提到】 : it could be a huge table...hiahia
|
j*c 发帖数: 97 | 14 this is the best method, but , my integration interval is very small, hence
a^n e^(-a)-b^n e(-b) will get large error. so it's not useful for me.
【在 c*******e 的大作中提到】 : n is a integer and 0: then n=1,2,3,4 : then you should be able to do it analytically yah : for n=1: -x*exp(-x)-exp(-x) : n=2: -x^2*exp(-x)-2*x*exp(-x)-2*exp(-x) : n=3: -x^3*exp(-x)-3*x^2*exp(-x)-6*x*exp(-x)-6*exp(-x) : n=4: -x^4*exp(-x)-4*x^3*exp(-x)-12*x^2*exp(-x)-24*x*exp(-x)-24*exp(-x)
|
j*c 发帖数: 97 | 15 that's a part of a big simulation code.
【在 h***o 的大作中提到】 : what? n is an integer? : if it's not a typo...you can get the exact result without much : computing
|
h***o 发帖数: 539 | 16 ffdt...can't understand you le
that's the analytical result of your integration,
it's exact solution, no error at all ya
【在 j*c 的大作中提到】 : this is the best method, but , my integration interval is very small, hence : a^n e^(-a)-b^n e(-b) will get large error. so it's not useful for me.
|
c*******e 发帖数: 8624 | 17 泥就要0.01的abs err.,顶多来个long精度的难道还不够?
况且这个函数最大也就20左右,应该没问题的
【在 j*c 的大作中提到】 : this is the best method, but , my integration interval is very small, hence : a^n e^(-a)-b^n e(-b) will get large error. so it's not useful for me.
|
j*c 发帖数: 97 | 18 if you do that there will be no error, but I need computer to do that :)
【在 h***o 的大作中提到】 : ffdt...can't understand you le : that's the analytical result of your integration, : it's exact solution, no error at all ya
|
j*c 发帖数: 97 | 19 the error is from trancate error, it ocurs when need to compute 1.000000001-1.0
, I need a 1e-9 here, but computer gives 0. Actually I can get about 0.1
precision for x~0.1, but that's too bad for our purpose.
【在 c*******e 的大作中提到】 : 泥就要0.01的abs err.,顶多来个long精度的难道还不够? : 况且这个函数最大也就20左右,应该没问题的
|
h***o 发帖数: 539 | 20 see cheungche's post....he gave the results of n = 1, 2, 3, 4
anyway, it's not hard at all to work out a general analytical
formula parameterized by n.
【在 j*c 的大作中提到】 : if you do that there will be no error, but I need computer to do that :)
|
|
|
h***o 发帖数: 539 | 21 then double precision
【在 j*c 的大作中提到】 : the error is from trancate error, it ocurs when need to compute 1.000000001-1.0 : , I need a 1e-9 here, but computer gives 0. Actually I can get about 0.1 : precision for x~0.1, but that's too bad for our purpose.
|
j*c 发帖数: 97 | 22 computing time has the first prority :)
double precision will take four times more time :(
anyway, thanks all for your help
【在 h***o 的大作中提到】 : then double precision
|
c*******e 发帖数: 8624 | 23 sigh,没见过泥怎么喜欢否定别人的人
泥不是说就要0.01的精度么?在泥给的
N和X的范围里面,最大的值也就20左右
单精度就足够了,如果泥要够高,我想
双精度一般总没有问题乐吧,泥先试试
怎么样?说实在,这个问题再简单不过了
不明白泥怎么才能得到0.1的精度?是从x积分到x+dx?
【在 j*c 的大作中提到】 : the error is from trancate error, it ocurs when need to compute 1.000000001-1.0 : , I need a 1e-9 here, but computer gives 0. Actually I can get about 0.1 : precision for x~0.1, but that's too bad for our purpose.
|
j*c 发帖数: 97 | 24 I'm not simply deny your idea. What you said is exactly what I have done,
so I know it can't meet my needs :(
Thanks anyway
【在 c*******e 的大作中提到】 : sigh,没见过泥怎么喜欢否定别人的人 : 泥不是说就要0.01的精度么?在泥给的 : N和X的范围里面,最大的值也就20左右 : 单精度就足够了,如果泥要够高,我想 : 双精度一般总没有问题乐吧,泥先试试 : 怎么样?说实在,这个问题再简单不过了 : : 不明白泥怎么才能得到0.1的精度?是从x积分到x+dx?
|
c*******e 发帖数: 8624 | 25 泥再把问题说具体一点,我来试试看怎么样?
【在 j*c 的大作中提到】 : I'm not simply deny your idea. What you said is exactly what I have done, : so I know it can't meet my needs :( : Thanks anyway
|
h***o 发帖数: 539 | 26 you are free, huh?
【在 c*******e 的大作中提到】 : 泥再把问题说具体一点,我来试试看怎么样?
|
j*c 发帖数: 97 | 27 integration of x^n exp[-x] (actually my problem is to integration
x^n exp[-(x-x0)/a],however, it can be rewrite as the sum of several
x^n exp[-x]).0<=n<=4, x is any region (xi,xf) between 1e-6 and 1e8, with
xf/xi~1.2. Since we have large error tolerance (0.01), we can use
approximations for x<0.05 and x>20. The remain problem is for 0.05
The most important issue here is that we can't use double precision for
the executing time limitation.
So the problem is: to find a fast method to solve t
【在 j*c 的大作中提到】 : I'm not simply deny your idea. What you said is exactly what I have done, : so I know it can't meet my needs :( : Thanks anyway
|
j*c 发帖数: 97 | 28
~~~~~~~~~~~~~~~~~~~~~~
just thought that the large (0.1) error of the final results may occur
when sum these integrations together. this implies a more accuracy
integration of x^n exp[-x], maybe 0.001 or 0.0001
【在 j*c 的大作中提到】 : integration of x^n exp[-x] (actually my problem is to integration : x^n exp[-(x-x0)/a],however, it can be rewrite as the sum of several : x^n exp[-x]).0<=n<=4, x is any region (xi,xf) between 1e-6 and 1e8, with : xf/xi~1.2. Since we have large error tolerance (0.01), we can use : approximations for x<0.05 and x>20. The remain problem is for 0.05: The most important issue here is that we can't use double precision for : the executing time limitation. : So the problem is: to find a fast method to solve t
|