Let $\gamma$ be the unit circle in the complex plane. I am trying to show in MatLab that for $f(z) = 1/z$ we have
$$ \int_\gamma f(z) dz = 2\pi i, $$
However I get (effectively) zero as my answer when I run the code. I am using a periodic trapezoidal/midpoint rule for the quadrature on the contour.
tN = 2^5;
t = 2*pi*(0:tN-1)'/tN;
z = exp(1i*t);
dz = 1i*exp(1i*t);
w = (2*pi/tN)*dz;
f_z = 1./z;
int_f_z = w' * f_z;
disp(int_f_z)
Does anyone know why this is not returning the correct answer?
It seems as though you're calculating $$ \sum_{k=1}^{T_n} \frac 1{\exp\left(\frac{2 \pi (k-1)}{T_n}\,i\right)} \cdot \frac{2 \pi}{T_n} \approx \int_0^{2 \pi} \frac 1{z(t)}\,dt $$ where $z(t) = \exp(it)$. What you should instead be calculating is $$ \int_\gamma \frac 1z \,dz = \int_0^{2 \pi} \frac 1{z(t)} \frac{dz}{dt}\,dt $$