I'm having trouble trying to understand what I'm doing wrong in solving this complex integral.
I partitioned the square into 4 different parameterized curves (each curve being 1 of the sides of the square) and added the 4 integrals. The final answer I got was zero, but the book says the answer is $πi$. I cannot for the life of me understand how they got such an answer. Any tip will be greatly appreciated. Thanks!
EDIT: I parameterized the square as such
$c_1(t)=t-i$
$c_2(t)=1+it$
$c_3(t)=-t+i$
$c_4(t)=-1-it$, with $-1\leq t\leq 1$ for all the $c$ curves.
I obtained the following complex integrals via $\int_{-1}^{1} f(c(t))c'(t)dt$:
For $c_1$, $\int_{-1}^{1}\frac{1}{2(t-i)+1}dt$ = $\frac{1}{2}ln(3-2i) - \frac{1}{2}ln(-1-2i)$.
For $c_2$, $\int_{-1}^{1}\frac{i}{2(1+it)+1}dt$ = $\frac{1}{2}ln(3+2i) - \frac{1}{2}ln(3-2i)$.
For $c_3$, $\int_{-1}^{1}\frac{-1}{2(-t+i)+1}dt$ = $\frac{1}{2}ln(-1+2i) - \frac{1}{2}ln(3+2i)$.
For $c_4$, $\int_{-1}^{1}\frac{-i}{2(-1-it)+1}dt$ = $\frac{1}{2}ln(-1-2i) - \frac{1}{2}ln(-1+2i)$.
I added the 4 integrals up and they all cancelled out to zero. But I don't see how $πi$ was obtained.
$$ I:=\oint_C\frac{1}{2z+1}\mathrm{d}z $$ The idea of your integration path is correct. Only in $c_3$ and $c_4$ you fail to implement it correctly, when you use $-t+i$ you actually have to go from $-1$ to $+1$ in positive direction $dt$ not in negative $-dt$ to get the right orientation. You do not have to transform anything, but just construct the right path.
(I use the name $ln$ for the complex logarithm like OP did. Conventions on that are not the same in all countries.).
$$\begin{align}I & = \int_{-1}^{1}\frac{1}{2(t-i)+1}dt + \int_{-1}^{1}\frac{i}{2(1+it)+1}dt + \int_{-1}^{1}\frac{1}{2(-t+i)+1}dt + \int_{-1}^{1}\frac{i}{2(-1-it)+1}dt \\ & = \frac{1}{2}\bigg[ \ln(-1-2 i + 2t) + \ln(-i+2t) + \ln(-3i + 2t) + \ln(1-2i+2t) \bigg]^{1}_{-1}\\ &= \frac{1}{2}[\ln(3-2i)-\ln(-3-2i)+\ln(2-i)-\ln(-2-i)+\ln(2-3i)-\ln(-2-3i)+\ln(1-2i)-\ln(-1-2i)] \\ &= \frac{i}{2}\big[(\arg(3-2i)-\arg(-3-2i))+(\arg(2-i)-\arg(-2-i))+(\arg(2-3i)-\arg(-2-3i))+(\arg(1-2i)-\arg(-1-2i))\big]\\ &=\frac{i}{2}\big[\arctan(-\frac{2}{3})-(\arctan(\frac{2}{3})-\pi)+\arctan(-\frac{3}{2})-(\arctan(\frac{3}{2})-\pi)+\\ &\;\;\;+ \arctan(-\frac{1}{2})-(\arctan(\frac{1}{2})-\pi)+\arctan(-\frac{2}{1})-(\arctan(\frac{2}{1})-\pi)\big] \\ &= \frac{i}{2}\big[\pi - 2 \arctan(\frac{2}{3}) +\pi - 2 \arctan(\frac{3}{2}) + \pi - 2 \arctan(\frac{1}{2}) +\pi - 2 \arctan(\frac{2}{1})\big] \\ &= \frac{i}{2}\big[4 \pi -2[\arctan(\frac{2}{3})+\arctan(\frac{3}{2})+\arctan(\frac{1}{2})+\arctan(2) ] \big]\\ &= \frac{i}{2}(4\pi-2(\frac{\pi}{2}+\frac{\pi}{2}))\\ &= i \pi. \end{align}$$
Using $\arctan|\frac{a}{b}|+\arctan|\frac{b}{a}|=\frac{\pi}{2}.$
Edit: Since the paramterisations of the curves (lines) of the integrals are continuously differentiable we can evaluate the integrals in the way like integrals of a real variable. The residue theorem was not used here, since the choice of the loop suggests that it should be done on elementary level.