Finding the ideal angle for the maximum range of a projectile when elevated? I was thinking about physics, and I thought of something.  How do we find the ideal angle for the maximum range of a projectile when elevated?
Assumptions:
Parabolic flight path
No air friction
g = gravity constant, h = elevation height, v_i = velocity initial, l = launch angle

The time it takes to fall from h to 0 is defined as
$$\frac{1}{2} * g * (t_0)^2 = h$$
$$\sqrt{\frac{2h}{g}} = t_0$$
The launch velocity for y can be defined as
$v_i sin(l)$ 
The launch velocity for x can be defined as
$v_i cos(l)$
The launch velocity for y will effect the range, find the maximum height of the object
relative to its launch height
$$v_i sin(l) * t_1 - \frac{1}{2} * g * (t_1)^2 = h_1$$
If we assume a parabolic arc, when relative 0 exists at t != 0
$$v_i sin(l) * t_1 - \frac{1}{2} g * (t_1)^2 = 0$$
$$v_i sin(l) * t_1 = \frac{1}{2} g * (t_1)^2$$
$$v_i sin(l) = \frac{1}{2} g t_1$$
$$t_1 = \frac{2 v_i sin(l)}{g}$$
Where the maximum height reached is at $\frac{t_1}{2}$
$$t_1 = \frac{v_isin(l)}{g}$$
The object is in the air for t_1 + t_0 seconds
$$\frac{v_i sin(l)}{g} + \sqrt(\frac{2h}{g}) = t_1 + t_0 = t$$
The range can now be maximized
$$range = v_i cos(l) * t$$
$$range = v_i cos(l) * \frac{v_i sin(l)}{g} + \sqrt{\frac{2h}{g}}$$
$$range = \frac{sin(l)cos(l)}{g} + \frac{cos(l)\sqrt{\frac{2h}{g}}}{v_i}$$
I am unsure how to continue to maximize this.  I am also unsure if what I have done so far is correct.
EDIT:
I think that I could theoretically remove all constant values so that my equation would become:  (Am I allowed to do this)?
$$range = sin(l)cos(l) + cos(l)$$
$$range = cos(l)( sin(l) + 1 )$$
However, I'm not sure if I am able to do this to solve the problem.
 A: First, call its initial velocity $v$ and height $h$. 
Here is the equation modelling the trajectory of the projectile: $y = h + x \tan \theta - \frac{g}{2v^2} x^2 (1 + \tan^2 \theta)$. We want to find where the projectile hits the ground, so let $y = 0$. We can now use calculus to find the maximum by differentiating w.r.t $\theta$.
$$x \sec^2 \theta + \tan \theta\frac{dx}{d \theta} - \left(\frac{gx}{v^2} \frac{dx}{d \theta} (1 + \tan^2 \theta) + \frac{gx^2}{2v^2} (2 \tan \theta \sec^2 \theta)\right) = 0$$
So $$\frac{dx}{d \theta} = \frac{x \sec^2 \theta \left(\frac{gx}{v^2} \tan \theta - 1\right)}{\tan \theta - \frac{gx}{v^2} (1 + \tan^2 \theta)}$$
So we find a critical value in $\tan \theta = \frac{v^2}{gx}$, and can substitute it back in the original equation:
$0 = h + \frac{v^2}{g} - \frac{g}{2v^2} x^2  - \frac{v^2}{2g}$ so $x = \frac{v}{g} \sqrt{v^2 + 2gh}$.
To find the angle, substitute in above to get $\theta = \tan^{-1} \left(\frac{v}{\sqrt{v^2 + 2gh}}\right)$
Notes: If you don't trust that this is a maximum, finding the second derivative is left as an exercise to the OP :)
