integrating a rapidly decaying function strange results

26 views
Skip to first unread message

J. Friedman

unread,
Oct 30, 2018, 3:33:06 PM10/30/18
to mpmath
According to my calculations g(t) (below) should be very rapidly decaying as t \rightarrow \infty, but the integral (quad) seems to give me strange results. Any suggestions on what is going on?

G = lambda s: exp(-(s-s**2)**2)
g = lambda t: re(G(2+j*t))
for l in range(1,10):
    print(quad(g,[0,l*2]))

-929368047261.93620154083404308518186452893823837753
0.73030807681355697617926688010183740605274248154493
0.73030807681355697617926682956789024942627475882531
0.73084346535653543017375370300762616576048495881376
6506.1108968477591798125903527040968078450818858557
-10497334.097217461344387940173023804897764062383082
199049954.0344803451280316219162110047797808274189
10165944034.061867509342219271383876244817897781579
-90252651558.490101003579618384469577487140317126004




Kris Kuhlman

unread,
Oct 31, 2018, 4:23:50 AM10/31/18
to mpmath
That function is only rapidly decaying for real s. It is oscillatory for complex arguments, as you show here.

Try plotting the function.

Kris

On Tuesday, October 30, 2018 at 1:33:06 PM UTC-6, J. Friedman wrote:
> According to my calculations g(t) (below) should be very rapidly decaying as t \rightarrow \infty, but the integral (quad) seems to give me strange results. Any suggestions on what is going on?
>
>
>
> G = lambda s: exp(-(s-s**2)**2)g = lambda t: re(G(2+j*t))

J. Friedman

unread,
Oct 31, 2018, 9:43:49 PM10/31/18
to mpmath
Kris
Thanks for responding
Let  s = x+ iy

so -(s-s**2)**2 =

-( (x+iy) - (x+iy)^2 )^2 = -x^4 - 4 i x^3 y + 2 x^3 + 6 x^2 y^2 + 6 i x^2 y - x^2 + 4 i x y^3 - 6 x y^2 - 2 i x y - y^4 - 2 i y^3 + y^2
(symbolic calculator)

Suppose that  -M < Re(s) < M, so above -y^4 is the leading real term for |y| large

so |exp(-(s-s**2)**2)| = O(exp(-y^4))  for -M < Re(s) < M

I need to do some contour integrals for Re(s) fixed, and over vertical lines of the form a + it.


G = lambda s: exp(-(s-s**2)**2)

I define g = lambda t: abs(G(2+j*t))

as t --> infty, the function does oscillate a little, but then it really decays fast

Here are the pointwise evaluations (below). When t = 3.8, g becomes


for l in range(1,100):
    print(l*0.1,g(l*0.1))
      

3.3000000000000003 174581109.062865493774906
3.4000000000000004 310643.1174726955073363975
3.5 179.0204419216566700758697
3.6 0.03075815858756175907739449
3.7 0.000001446881510477273510161705
3.8000000000000003 1.707168282855990568833741e-11
3.9000000000000004 4.617468360109395918682982e-17


Now if I integrate the absolute value, it converges as it should


for l in range(1,50):
    print('Integral from 0 to ', l*10, ' = ', quad(g,[0,l*10]))
   
Integral from 0 to  320  =  14283267314937294.78568836
Integral from 0 to  330  =  14283267221372905.29080994
Integral from 0 to  340  =  14283267263072427.82687573
Integral from 0 to  350  =  14283267349244040.12717721
Integral from 0 to  360  =  14283267186104994.47301923
Integral from 0 to  370  =  14283267319097570.887649
Integral from 0 to  380  =  14283267295148934.49766176
Integral from 0 to  390  =  14283267187229046.93666943

clearly it converges absolutely from the theory and the experimental evidence. But if I try to integrate the real or imaginary part, I get nonsense answers

redefine g = lambda t: re(G(2+j*t))

for l in range(1,50):
    print('Integral from 0 to ', l*10, ' = ', quad(g,[0,l*10]))

Integral from 0 to  150  =  -4027207776910521.878532395
Integral from 0 to  160  =  4475397256614113.025802875
Integral from 0 to  170  =  5032028392897261.000738395
Integral from 0 to  180  =  1368943760662856.81477378
Integral from 0 to  190  =  -5670867742668200.379345995
Integral from 0 to  200  =  6293201245607762.71051154
Integral from 0 to  210  =  -3030930189883354.986057916
Integral from 0 to  220  =  -6843259753634191.086749538





Here is my code


G = lambda s: exp(-(s-s**2)**2)
g = lambda t: re(G(2+j*t))

#for l in range(1,1000):
#    print(l*0.1,g(l*0.1))


for l in range(1,50):
    print('Integral from 0 to ', l*10, ' = ', quad(g,[0,l*10]))
   




   








Kris Kuhlman

unread,
Oct 31, 2018, 9:53:43 PM10/31/18
to mpmath
Real and imaginary parts are both oscillatory, when real part is positive.

I wish mpmath had an iPhone app.
B0CCCC5B-48CD-42AB-95E3-791109B3FDDE.png
8C2C0137-0417-456C-81FA-E05110473DAF.png
27B72790-3710-4AD4-8356-061AB141D3ED.png

Joshua Friedman

unread,
Oct 31, 2018, 10:16:25 PM10/31/18
to mpm...@googlegroups.com
Yes, I see that it oscillates, but the integral converges absolutely. From the plots you sent, when |y| > 5, it is rapidly decreasing (in absolute value).  Does the mp math quad integral not work on oscillating functions, even if they decay in absolute value?

--
You received this message because you are subscribed to the Google Groups "mpmath" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mpmath+un...@googlegroups.com.
To post to this group, send email to mpm...@googlegroups.com.
Visit this group at https://groups.google.com/group/mpmath.
For more options, visit https://groups.google.com/d/optout.


--

Kris Kuhlman

unread,
Oct 31, 2018, 10:20:09 PM10/31/18
to mpmath
http://www.mpmath.org/doc/current/calculus/integration.html

The quadosc function works with oscillating functions (like J Bessel functions)

You either need to supply the person or the zeros for it to work.
Reply all
Reply to author
Forward
0 new messages