ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 09 Jun 2011 14:40:34 +0200summing over bessel functionhttps://ask.sagemath.org/question/8148/summing-over-bessel-function/Hi.
I need to sum over a bessel function K:
sum(bessel_K(0,2*PI*abs(x+k)),k,-oo,oo)
How ever I get an error:
>TypeError: Cannot evaluate symbolic expression to a numeric value.
Which sounds logical. I there any way around this?
ThanksSun, 05 Jun 2011 12:26:22 +0200https://ask.sagemath.org/question/8148/summing-over-bessel-function/Answer by benjaminfjones for <p>Hi. </p>
<p>I need to sum over a bessel function K:</p>
<pre><code>sum(bessel_K(0,2*PI*abs(x+k)),k,-oo,oo)
</code></pre>
<p>How ever I get an error:</p>
<blockquote>
<p>TypeError: Cannot evaluate symbolic expression to a numeric value. </p>
</blockquote>
<p>Which sounds logical. I there any way around this?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/8148/summing-over-bessel-function/?answer=12418#post-id-12418The `bessel_K` function is only implemented as far as numerical evaluation (thanks to PARI). For example, if you try:
sage: x = var('x')
sage: f = bessel_K(0,x)
...
TypeError: Cannot evaluate symbolic expression to a numeric value.
Mon, 06 Jun 2011 01:14:44 +0200https://ask.sagemath.org/question/8148/summing-over-bessel-function/?answer=12418#post-id-12418Comment by yotama9 for <p>The <code>bessel_K</code> function is only implemented as far as numerical evaluation (thanks to PARI). For example, if you try:</p>
<pre><code>sage: x = var('x')
sage: f = bessel_K(0,x)
...
TypeError: Cannot evaluate symbolic expression to a numeric value.
</code></pre>
https://ask.sagemath.org/question/8148/summing-over-bessel-function/?comment=21616#post-id-21616So there is no way around this, perhaps using a for loop...Mon, 06 Jun 2011 03:51:58 +0200https://ask.sagemath.org/question/8148/summing-over-bessel-function/?comment=21616#post-id-21616Answer by kcrisman for <p>Hi. </p>
<p>I need to sum over a bessel function K:</p>
<pre><code>sum(bessel_K(0,2*PI*abs(x+k)),k,-oo,oo)
</code></pre>
<p>How ever I get an error:</p>
<blockquote>
<p>TypeError: Cannot evaluate symbolic expression to a numeric value. </p>
</blockquote>
<p>Which sounds logical. I there any way around this?</p>
<p>Thanks</p>
https://ask.sagemath.org/question/8148/summing-over-bessel-function/?answer=12421#post-id-12421Yes, as you say, something like
sage: G = lambda x,k: bessel_K(0,2*pi*(x+k))
sage: [sum([G(x,k) for k in [1..100]]) for x in [0,1,2,3]]
[0.000917807437286879, 1.22307638250860e-6, 1.87088814696602e-9, 3.03065972802175e-12]
However,
Sometimes bessel_K(nu,z) is denoted K_nu(z) in the literature. In
PARI, nu can be complex and z must be real and positive.
So we get errors trying to sum over negative numbers.
There is also the scipy algorithm.
sage: G = lambda x,k: bessel_K(0,2*pi*(x+k),algorithm='scipy')
sage: [sum([G(x,k) for k in [1..100]]) for x in [0,1,2,3]]
[0.000917807437286507, 1.22307638250709e-6, 1.87088814709167e-9, 3.03065985167335e-12]
But this also does not play well with negative input.
There is also the problem that bessel_k(0,0) is undefined, if you were going to do that.
You could try using Maxima inside Sage, which does give negative input meaning. But it won't do anything symbolic with a sum to infinity of Bessel K.
sage: maxima_console()
<snip>
(%i1) sum(bessel_k(0,1+k),k,-3,3);
bessel_k: bessel_k(0,0) is undefined.
-- an error. To debug this try: debugmode(true);
(%i2) sum(bessel_k(0,1.5+k),k,-3,3);
(%o2) 2.3647955753643517 - 8.514365020222318 %i
(%i3) sum(bessel_k(0,1.5+k),k,-100,100);
(%o3) 2.4596346751510154 - 1.2033957278916282e+42 %i
(%i4) sum(bessel_k(0,.01+k),k,-100,100);
(%o4) 5.894176649568293 - 5.299305601915854e+42 %i
Notice also the very large imaginary part, which I have no idea whether to trust.Mon, 06 Jun 2011 13:14:33 +0200https://ask.sagemath.org/question/8148/summing-over-bessel-function/?answer=12421#post-id-12421Comment by yotama9 for <p>Yes, as you say, something like</p>
<pre><code>sage: G = lambda x,k: bessel_K(0,2*pi*(x+k))
sage: [sum([G(x,k) for k in [1..100]]) for x in [0,1,2,3]]
[0.000917807437286879, 1.22307638250860e-6, 1.87088814696602e-9, 3.03065972802175e-12]
</code></pre>
<p>However,</p>
<pre><code>Sometimes bessel_K(nu,z) is denoted K_nu(z) in the literature. In
PARI, nu can be complex and z must be real and positive.
</code></pre>
<p>So we get errors trying to sum over negative numbers.</p>
<p>There is also the scipy algorithm.</p>
<pre><code>sage: G = lambda x,k: bessel_K(0,2*pi*(x+k),algorithm='scipy')
sage: [sum([G(x,k) for k in [1..100]]) for x in [0,1,2,3]]
[0.000917807437286507, 1.22307638250709e-6, 1.87088814709167e-9, 3.03065985167335e-12]
</code></pre>
<p>But this also does not play well with negative input. </p>
<p>There is also the problem that bessel_k(0,0) is undefined, if you were going to do that.</p>
<p>You could try using Maxima inside Sage, which does give negative input meaning. But it won't do anything symbolic with a sum to infinity of Bessel K.</p>
<pre><code>sage: maxima_console()
<snip>
(%i1) sum(bessel_k(0,1+k),k,-3,3);
bessel_k: bessel_k(0,0) is undefined.
-- an error. To debug this try: debugmode(true);
(%i2) sum(bessel_k(0,1.5+k),k,-3,3);
(%o2) 2.3647955753643517 - 8.514365020222318 %i
(%i3) sum(bessel_k(0,1.5+k),k,-100,100);
(%o3) 2.4596346751510154 - 1.2033957278916282e+42 %i
(%i4) sum(bessel_k(0,.01+k),k,-100,100);
(%o4) 5.894176649568293 - 5.299305601915854e+42 %i
</code></pre>
<p>Notice also the very large imaginary part, which I have no idea whether to trust.</p>
https://ask.sagemath.org/question/8148/summing-over-bessel-function/?comment=21602#post-id-21602Thanks. I need to sum over positive and negative k and I will not include K(0,0). Thu, 09 Jun 2011 14:40:34 +0200https://ask.sagemath.org/question/8148/summing-over-bessel-function/?comment=21602#post-id-21602