<s>[INST] How to find $\theta$ at which $d$ is the maximum possible? I have an equation:
$$d=\dfrac{v\cos \theta}{g}\left(v \sin \theta + \sqrt{v^{2} \sin^{2}\theta + 2gh} \right),\ g≈9.81 \dfrac {m}{s^{2}}$$
How to find $\theta$ at which $d$ is the maximum possible?
 [/INST] For simplicity consider $$d=2v\cos\theta(v\sin\theta+\sqrt{v^2\sin^2\theta+H}).$$ 
$$(d-v^2\sin 2\theta)^2=4v^2\cos^2\theta(v^2\sin^2\theta+H)=v^4\sin^22\theta+4v^2H\cos^2\theta$$
$$d^2-2v^2d\sin 2\theta=4v^2H\cos^2\theta=2v^2H(\cos 2\theta-1)$$
$$2v^2H\cos 2\theta+2v^2d\sin 2\theta=d^2+2v^2H$$ $$d^2-2v^2d\sin 2\theta+2v^2H(1-\cos 2\theta)=0$$ This is a quadratic equation of $d.$ Note that when $d$ reached to its maximum discriminant of this equation should be zero. Therefore, when $d$ is maximum $$4v^4\sin^2 2\theta-8v^2H(1-\cos 2\theta)=0$$ $$(1-\cos 2\theta)(v^2((1+\cos 2\theta)-2H))=0.$$ This gives $$\cos 2\theta=1$$ or $$1+\cos 2\theta=\dfrac{2H}{v^2}$$
</s>