Ask Your Question
1

definite integral and indefinite integral different (~Gaussian)

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

andi gravatar image

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

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)
>9.7000

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

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

Comments

What version of Sage are you using?

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

Thank you for the answers, both of you!

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

2 Answers

Sort by ยป oldest newest most voted
2

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

achrzesz gravatar image

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

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

var('y a N')
assume(N>0)
I1=integrate(exp(-1/2*(y-a)^2/N)*y^2,(y,-oo,oo))
I2=integrate(exp(-1/2*(y+a)^2/N)*y^2,(y,-oo,oo))
I=(I1+I2).factor()
print I
print I(a=3.0,N=0.7).n()
#2*(a^2 + N)*sqrt(pi)*sqrt(2)*sqrt(N)
#40.6855961680184
edit flag offensive delete link more
1

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

calc314 gravatar image

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

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

Comments

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

calc314 gravatar imagecalc314 ( 2012-08-12 17:37:58 +0100 )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 +0100 )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

Stats

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

Seen: 2,042 times

Last updated: Aug 13 '12