%% Complex Contour Integration
% Integrate a complex function around a pole by specifying a contour.
%
% Evaluate the complex contour integral
% q=\oint \frac{\textrm{dz}}{2z-1}\ldotp
% The integrand has a simple pole at z=1/2, so use a rectangular contour that encloses that point. The contour starts and ends at x=1 on the real number line. Use the 'Waypoints' name-value pair to specify the piecewise segments in the contour.

f = @(z) 1./(2.*z-1);
contour_segments = [1+1i 0+1i 0-1i 1-1i];
q = quadgk(f,1,1,'Waypoints',contour_segments)

% Copyright 2019 The MathWorks, Inc.