Maximizing hole in a filled cylinder Question:
Consider a water-filled cylinder of height $H$. A hole is drilled into the side of the cylinder and water jet forms.
(1) The water jet follows the parabola:
$$y = y_0 - \frac{g}{2} \frac{(x-x_0)^2}{v^2}$$
$y_0$ and $x_0$ are the coordinates for the hole, $g$ is a constant and $v$ is the velocity at the hole.
(2) It is also known that the velocity at the hole is proportional to the square root of the distance between the water surface and the hole.
At which height should the hole be drilled so that the point where the water jet touches the ground will be as far away from the tank as possible at the start moment?
The problem has to be solved by calculus-based optimization.
Attempted solution:
First, I draw an image:

$H$ is the total height of the cylinder and also the total height of the water pillar inside the cylinder since it is completely filled with water.
Let $h$ be the height at which the hole is drilled. The distance from the hole to the top is then $H-h$.
The expression for the outflow velocity of water is then:
$$v \propto \sqrt{H-h} \Rightarrow v = k\sqrt{H-h}$$
If we put the Cartesian coordinate system with the origin at the bottom right of the cylinder, then the $y$-coordinate of the hole should be equal to $h$ and the x-coordinate of the hole should be equal to zero.
$$y = y_0 - \frac{g}{2} \frac{(x-x_0)^2}{v^2} = h - \frac{g}{2} \frac{x^2}{v^2}$$
Adding in the expression for the velocity:
$$y = h - \frac{g}{2} \frac{x^2}{v^2} = h - \frac{g}{2} \frac{x^2}{k(H-h)}$$
Since we are maximizing distance, we need to solve for $x$:
$$x = \sqrt{\frac{2(h -y)}{g}k(H-h)} $$
Then we take the derivative of this and set to zero to find $h$ expressed in terms of $H$. Clearly, the longest $x$ must be when $y = 0$:
$$x = \sqrt{\frac{2h}{g}k(H-h)}.$$
Taking the derivative with respect to $h$ becomes very complex and does not get rid of $k$.
The expected answer is $h=\frac{H}{2}$.
Why does this approach not work and what is a more productive approach to finding $h$?
 A: Your approach is fine. There is no need to get rid of the constant $k$. 
It suffices to note that $\sqrt{ab}\leq \frac{a+b}{2}$  for $a,b\geq 0$ and therefore for $0\leq h\leq H$,
$$x(h) = \sqrt{\frac{2h}{g}k(H-h)}=\sqrt{\frac{2k}{g}}\cdot \sqrt{h(H-h)}\leq \sqrt{\frac{2k}{g}}\cdot \frac{h+(H-h)}{2}=\sqrt{\frac{2k}{g}}\cdot \frac{H}{2}.$$
The equality, i.e. the maximum distance, is attained when $a=b$, that is when $h=H-h$, or $h=H/2$.
A: Yes, your approach works fine. The constant $k$ can be separated & we can differentiate $x$ as follows
$$x=\sqrt{\frac{2h}{g}k(H-h)}$$
$$x=\sqrt{\frac{2k}{g}}\sqrt{Hh-h^2}$$
$$\frac{dx}{dh}=\sqrt{\frac{2k}{g}}\frac{d}{dh}\sqrt{Hh-h^2}$$
$$=\sqrt{\frac{2k}{g}}\frac{1}{2\sqrt{Hh-h^2}}\frac{d}{dh}(Hh-h^2)$$
$$=\frac12\sqrt{\frac{2k}{g}}\frac{1}{\sqrt{Hh-h^2}}(H-2h)$$ 
Now, for maximum value of $x$ we have $\frac{dx}{dh}=0$ i.e. 
$$\frac12\sqrt{\frac{2k}{g}}\frac{1}{\sqrt{Hh-h^2}}(H-2h)=0$$
$$H-2h=0\quad (\because \ h\ne 0, h\ne H)$$
$$2h=H$$
$$h=\frac{H}{2}$$
