On Friday, July 18, 2014 3:08:34 PM UTC-4, Hans W Borchers wrote:
>
>
>     julia> x = linspace(0, 2*pi);
>
>     julia> points = exp(x*1im);
>
>     julia> quadgk(z -> 1 ./ z, points...)
>     (-2.1630337481358435e-17 + 6.283185307179583im,5.957695483631124e-16)
>

Note that linspace defaults to interpolating 100 points; this is pretty 
inefficient here, because you want quadgk to do the subdivision more 
efficiently for you.   I would just integrate over a triangle (4 points, 
since the beginning point is included twice):


julia> quadgk(z -> 1 / z, exp(linspace(0, 2pi, 4) * im)...)[1] - 2pi*im
-1.1102230246251565e-16 - 8.881784197001252e-16im


Note also that it is fine to use 1/z rather than 1./z (although the latter 
is harmless).   Unlike Matlab, quadgk evaluates your function for one point 
at a time, so you don't need to vectorize it.    (In Matlab, evaluating 
your integrand for a vector of arguments is essential for performance, but 
it is an unnecessary annoyance in Julia.)

 

Reply via email to