First, I think, Steven is talking about line integrals along a path, and
these integrals are one-dimensional.
And secondly, of course you should avoid poles along your path, by making
the radius big enough, or similar. These things are standard techniques in
complex analysis.
As an example, I append a function `line_integral` from my package
NumericalMath (not in METADATA) that does integrate along a path given by
`points`.
function line_integral(f::Function, points::Array{Complex{Float64},1}; tol =
1e-15)
local n::Int = length(points)
local Q::Complex = 0.0 + 0.0im
if n == 1; return Q; end
for i = 2:n
a = points[i-1]
b = points[i]
d = b - a
f1(t) = real(f(a + t*d))
f2(t) = imag(f(a + t*d))
Qre = quadgk(f1, 0.0, 1.0)[1]
Qim = quadgk(f2, 0.0, 1.0)[1]
Q += d * (Qre + Qim*1.0im)
end
return Q
end
On Friday, July 18, 2014 11:48:55 AM UTC+2, Andrei Berceanu wrote:
>
> Say I would like to do the integral using quadgk. There are 2 caveats,
> however.
> Quoting from the Julia manual
> "These quadrature rules work best for smooth functions within each
> interval, so if your function has a known discontinuity or other
> singularity, it is best to subdivide your interval to put the singularity
> at an endpoint."
> My function does have singularities (i.e. poles) inside of the integration
> contour, and it is not clear to me how I should split the interval. Am I
> missinterpreting this?
> The other issue is that quadgk seems to only accept function of one
> variable, wheres mine are 2-variable functions.
>
> On Thursday, July 17, 2014 7:53:38 PM UTC+2, Steven G. Johnson wrote:
>>
>>
>>
>> On Thursday, July 17, 2014 9:19:04 AM UTC-4, Andrei Berceanu wrote:
>>>
>>> I should perhaps mention that this is part of a bigger scheme, to first
>>> find all the poles of G(x,y)/F(x,y) and then use the residue theorem for
>>> solving a complex integral of the type
>>> integral( G(x,y)/F(x,y), (x,y))
>>>
>>
>> Unless F(x,y) is very special (e.g. a polynomial), I suspect that it
>> would be much faster to just do the integral. Since you have analytic
>> functions, 1d/contour integration is very efficient (with an appropriate
>> algorithm, e.g. the built-in quadgk function) unless you have poles lying
>> very close to your integration contour (and even then it is not too bad
>> with an adaptive scheme like quadgk.)
>>
>> In contrast, finding *all* the zeros of an arbitrary analytic function is
>> hard, usually harder than integrating it unless you have a good idea of
>> where the zeros are. In general, it's not practical to guarantee that you
>> have found all the zeros unless you can restrict your search to some finite
>> portion of the complex plane. For finding the roots of analytic functions
>> inside a given contour, some of the best algorithms actually involve doing
>> a sequence of integrals (
>> http://www.chebfun.org/examples/roots/ComplexRoots.html) that are just
>> as hard as your original integral above. So, you might as well just do
>> the integral to begin with.
>>
>>