Ask Your Question

definite integral and indefinite integral different (~Gaussian)

asked 2012-08-12 11:03:51 +0200

andi gravatar image

updated 2012-08-12 15:05:38 +0200

calc314 gravatar image

Hello, I get strange behaviour on the following function. It persists when changing constants, but is not present for very simple functions, so any hint for a limit would be appreciated.

f1 = exp(-1/2*(y-a)^2/N)+exp(-1/2*(y+a)^2/N); f1

f2 = f1*y^2; f2

f4 = f2(a=3,N=0.7); f4
>(e^(-0.714285714285714*(y - 3)^2) + e^(-0.714285714285714*(y + 3)^2))*y^2

Z = integral(f4,y,-100,100); Z.n(digits=5)

F = integrate(f4,y); H = F(y=100) - F(y=-100); H.n(digits=5)

As you see, I get right results when using the definite integral, while calculation the indefinite integral and manually evaluating it gains wrong results.

By the way, when integrating from -inf to inf, I should get N+a^2. Is there any way to see this?

edit retag flag offensive close merge delete


What version of Sage are you using?

benjaminfjones gravatar imagebenjaminfjones ( 2012-08-12 15:49:49 +0200 )edit

Thank you for the answers, both of you!

andi gravatar imageandi ( 2012-08-12 17:39:25 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2012-08-12 16:41:10 +0200

achrzesz gravatar image

updated 2012-08-13 09:17:38 +0200

One can obtain an exact value of the integral (with factor a^2+N):

var('y a N')
print I
print I(a=3.0,N=0.7).n()
#2*(a^2 + N)*sqrt(pi)*sqrt(2)*sqrt(N)
edit flag offensive delete link more

answered 2012-08-12 15:15:16 +0200

calc314 gravatar image

updated 2012-08-12 17:38:11 +0200

I'm getting 40.686 for Z here.

Your integrals depend on the error function, and I know there are some issues with erf() in Sage. You can see some of the anomalies in the post here.

This could be the issue.

edit flag offensive delete link more


`numerical_integral(f4,-oo,oo)` gives: `(40.685596168018435, 5.067965214014384e-06)`

calc314 gravatar imagecalc314 ( 2012-08-12 17:37:58 +0200 )edit

Oh: you are correct, I also get 40.686. The 9.7 is when I have a different step f3 between f2 and f4.

I had written this straight after your post, but forgotten to press "send", sorry I had you wonder about this...

andi gravatar imageandi ( 2012-08-12 19:07:36 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2012-08-12 11:03:51 +0200

Seen: 1,872 times

Last updated: Aug 13 '12