Evaluate the following $ \int\frac{1}{x^2+k}\,\mathrm{d}x$ when $k<0$
so, here is what i've done: I changed the denominator to $x^2-(\sqrt k)^2$ where $k>0$, so that i can easily apply the formula to solve the type $ \int\frac{1}{x^2-a^2}\,\mathrm{d}x$.
so my question is, is this modification in $k$ correct (or legal in math sense) to solve these type of integrals ? if not then can you please explain whats wrong?
No, it's not correct: you should transform into $x^2-(\sqrt{-k})^2$ or, which is the same, $$ x^2-(\sqrt{|k|})^2 $$ It's much simpler to set $-k=a^2$. Then you can decompose $$ \frac{1}{x^2-a^2}=\frac{p}{x-a}+\frac{q}{x+a} $$ (partial fractions). The condition is equivalent to $$ \begin{cases} p+q=0\\[4px] ap-aq=1 \end{cases} $$ After this the integration is elementary.