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.Fri, 10 Mar 2017 20:49:41 +0100Integrating Log(x²+y²)https://ask.sagemath.org/question/36911/integrating-logx2y2/I'm making the following calculations:
> X,Y,L=var('X,Y,L')
>
> assume(L>0)
>
> F(L)=integrate(integrate(log((X)^2+(Y)^2),Y,L/2,3*L/2),X,-L/2,L/2)
Maxima requested tor assume(4*X^2+L^2-4>0) and for assume(L-2>0), so I run the following
>X,Y,L=var('X,Y,L')
>assume(L>0)
>assume(4*X^2+L^2-4>0)
>assume(L-2>0)
>F(L)=integrate(integrate(log((X)^2+(Y)^2),Y,L/2,3*L/2),X,-L/2,L/2)
>print(F)
and the result is
>-1/4*pi*L^2 + 1/2*L^2*(arctan(3) - 9*arctan(1/3) - 2) + 9*L^2*arctan(1/3) + 3/2*L^2*log(5/2*L^2) - 1/2*L^2*log(1/2*L^2) - 2*L^2
After this, I change the limits of the integration
> X,Y,L=var('X,Y,L')
>assume(L>0)
>assume(4*X^2+L^2-4>0)
>assume(L-2>0)
>F(L)=integrate(integrate(log((X)^2+(Y)^2),Y,-3*L/2,-L/2),X,-L/2,L/2)
>print(F)
and the result is
>1/4*pi*L^2 - 1/2*L^2*(arctan(3) - 9*arctan(1/3) - 2) - 9*L^2*arctan(1/3) - 3/2*L^2*log(5/2*L^2) + 1/2*L^2*log(1/2*L^2) + 2*L^2
If we subtract this to results and considering L=10 The result should be Zero, but the result is very different
> Z(L)=(-1/4*pi*L^2 + 1/2*L^2*(arctan(3) - 9*arctan(1/3) - 2) + 9*L^2*arctan(1/3) + 3/2*L^2*log(5/2*L^2) - 1/2*L^2*log(1/2*L^2) - 2*L^2)-(1/4*pi*L^2 - 1/2*L^2*(arctan(3) - 9*arctan(1/3) - 2) - 9*L^2*arctan(1/3) - 3/2*L^2*log(5/2*L^2) + 1/2*L^2*log(1/2*L^2) + 2*L^2)
>Z(10).n()
___________
>922.636418333173
I know that the result should be zero from the math and I also use the software Mathematica.
The question is: I'm making something wrong? Or this is a well known problem of Sage?RRPFri, 10 Mar 2017 20:49:41 +0100https://ask.sagemath.org/question/36911/log_integral gives wrong values for complex argumentshttps://ask.sagemath.org/question/24630/log_integral-gives-wrong-values-for-complex-arguments/Riemann's formula for the number of primes less than a given number requires the calculation of the logarithmic integral (Li(x) or li(x)) for complex values. This function is implemented in Sage as log_integral.
However, it does not seem to give the correct values for complex arguments. When I feed in -4.42464733272289 + 0.649996908475887*I it returns -0.0380977804390431 + 4.49840994945387*I, but -4.41940689179334 - 0.684720910130221*I returns -0.0281163576275170 - 4.50165559913773*I, i.e., there seems to be a discontinuity when the imaginary part turns negative.
This script shows the behaviour:
start = 0
end = 10
steps = 100
args = [(start * (1 - s / steps) + end * (s / steps)) for s in range(steps+1)]
val1 = [20^(1/2+s*i) for s in args]
val2 = [log_integral(s) for s in val1]
for (x,y,z) in zip(args, val1, val2):
print n(x), '\t', n(y), '\t', n(z)
Maybe the problem is that a different branch of the complex logarithm should be used. But the values of the above sequence should converge to pi * i, which doesn't seem to be the case at all.
Has anybody seen this behaviour before or any idea how to fix it?Markus SchepkeSat, 25 Oct 2014 17:15:02 +0200https://ask.sagemath.org/question/24630/