First time here? Check out the FAQ!

Ask Your Question
1

definite integral and indefinite integral different (~Gaussian)

asked 12 years ago

andi gravatar image

updated 12 years ago

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?

Preview: (hide)

Comments

What version of Sage are you using?

benjaminfjones gravatar imagebenjaminfjones ( 12 years ago )

Thank you for the answers, both of you!

andi gravatar imageandi ( 12 years ago )

2 Answers

Sort by » oldest newest most voted
2

answered 12 years ago

achrzesz gravatar image

updated 12 years ago

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
Preview: (hide)
link
1

answered 12 years ago

calc314 gravatar image

updated 12 years ago

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.

Preview: (hide)
link

Comments

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

calc314 gravatar imagecalc314 ( 12 years ago )

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 ( 12 years ago )

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: 12 years ago

Seen: 2,055 times

Last updated: Aug 13 '12