Trying to show that $ \int_\gamma f(z) dz = 2\pi i$ in MatLab but getting an incorrect answer?

60 Views Asked by At

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?

2

There are 2 best solutions below

3
On BEST 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 $$

0
On

I think you forgot to implement the term $dz$. Try by replacing

int_f_z = w' * f_z

with

int_f_z = w' * f_z * 1i*z.