# Improper Numerical integral

I am self teaching myself python and computational physics via Mark Newmans book Computational Physics the exercise is 5.17 of Computational Physics. I have to shift the limits of integration for an improper integral after a change of variables so that Gaussian quadrature method gives a more accurate result. I am suppose to approximate the Gamma function $\Gamma(a)$

The relevant equation is here: This is the question:  When I isolate for $x$ I get $x = \frac{zc}{1-x}$. But when $z = \frac{1}{2}$ I get $x = c$ but this makes no sense because this implies z is a constant which it's not. I know in order to shift a function $f(x)$ to the left you $f(x + c)$ but how would I do this with an integrand?

The task in this problem is to apply the variable transformation $$z=\frac{x}{c+x} \Leftrightarrow x=\frac{zc}{1-z}\,,\quad \textrm{d}x=\frac{c}{(1-z)^2}\textrm{d}z$$ to the integral $$\int\limits_0^\infty f(x)\textrm{d}x\,,\quad f(x)=x^{a-1}e^{-x}\,,$$ which yields $$\int\limits_0^1 \tilde{f}(z)\textrm{d}z\,,\quad \tilde{f}(z)=\left(\frac{zc}{1-z}\right)^{a-1}\exp\left(-\frac{zc}{1-z}\right)\frac{c}{(1-z)^2}\,,$$ and chose the parameter $c$ such that $\tilde{f}(z)$ takes its maximum at $z=\frac{1}{2}$.
You have already completed the first part of the question: $z$ takes the value $\frac{1}{2}$ when $x=c$.
The second part asks which is the correct $c$. We tackle this by computing the derivative of $\tilde{f}(z=\frac{1}{2})$ with respect to the unknown parameter $c$ and set this to zero: $$\left.\frac{\partial \tilde{f}}{\partial c}\right\vert_{z=\frac{1}{2}} = \frac{1}{4}c^{a-1}e^{-c}\left(a-c\right)=0\,.$$ Thus, we find $c=a$.