Complex integration is integration along a path. You can parametrize the path, by arc length, i.e., using a real interval. (The result can actually depend on the path.)
One would expect to be able to compute
the integral of 1/z
along a straight line between -2-1i
and 2-1i
as follows (note the use of 1i
rather than i
).
f <- function(s) {
z <- s-1i
1/z
}
integrate( f, -2, 2 ) # Fails
But integrate
only works with real numbers.
You need to compute separately the real and imaginary parts.
integrate( function(s) Re(f(s)), -2, 2 )$value +
1i * integrate( function(s) Im(f(s)), -2, 2 )$value
# [1] 0+2.214297i