Optimal ladder position to maximize height reached Suppose we have a ladder (with a unit length) and we want to position it to reach the highest point possible on a vertical wall. The terrain is sloped and can be described with a variable k. What is the optimal distance from the wall the ladder should be placed at, so the point reached is the highest? 
See the picture, we are looking for x.

I've concluded, "experimentally", that the ladder should be placed vertical to the terrain, but I've been unable to prove it. I didn't how to set a Lagrange correctly. (and yes, this was an exam question, I don't plan on scaling any walls!)
 A: Alternatively look at it like this. Take a point on the wall. What is the shortest ladder which reaches that point? Clearly one perpendicular to the ground (shortest line between ground and point). If the ladder is not perpendicular to the ground, we can reach the same point with a shorter ladder, which is perpendicular, and place our longer ladder higher up and parallel.
A: The height reached is $kx$ plus the "extra height" which is, by the Pythagorean Theorem, $\sqrt{1-x^2}$.
So we want to maximize $f(x)=kx+\sqrt{1-x^2}$. As usual, find where $f'(x)=0$. Compare with any endpoint candidates.  (In the case of $0$ or negative  slope, a vertical ladder is optimal, though unpleasantly dangerous.)
A: This seems to be a very straightforward calculus I problem, so I'll present my solution in that manner. We can define a function $h(x)=kx+\sqrt{1-x^2}$ so that $h(x)$ is the height of the ladder according to the wall. With this in mind, we calculate $$h'(x)=k-\frac{x}{\sqrt{1-x^2}}.$$ Setting this to zero and solving, we get that $$x=\pm\sqrt{\frac{k^2}{k^2+1}}.$$ Since a negative value for $x$ is inappropriate for this type of problem, we throw out the solution that doesn't make sense, and we have as our final answer $$x=\sqrt{\frac{k^2}{k^2+1}}.$$
A: Yet another solution:
The top of the ladder is at $(x+\cos \theta,kx+\sin \theta)$, where $\theta$ is the anti-clockwise angle from the $x$ axis. The problem is then $\max_{\theta, x} \{  kx + \sin \theta | x + \cos \theta = 0 \}$. The constraint bounds $|x|$  by $1$, and the problem is equivalent to $\max_{\theta, x} \{  kx + \sin \theta | x + \cos \theta = 0,\ \theta \in [0,2 \pi] \}$, hence the feasible set may be taken to be compact and non-empty, hence a solution exists.
Then we use Lagrange to characterize the solutions:
$$ \binom{k}{\cos \theta} + \lambda  \binom{1}{-\sin \theta} = 0$$
which reduces to $\cos \theta = - k \sin \theta$. Squaring and using the identity $\cos^2 x + \sin^2 x = 1$ gives $\sin \theta = \pm \frac{1}{\sqrt{1+ k^2}}$, and the Lagrange condition then gives $\cos \theta = \mp \frac{k}{\sqrt{1+ k^2}}$, and hence the constraint gives $x = \pm \frac{k}{\sqrt{1+ k^2}}$. Choosing the  higher objective value, we have the solution $x = \frac{k}{\sqrt{1+ k^2}}$, with optimal value $\sqrt{k^2+1}$.
To confirm your intuition: If we let $\alpha$ satisfy $\cos \alpha = \frac{1}{\sqrt{1+ k^2}}$, $\sin \alpha = \frac{k}{\sqrt{1+ k^2}}$, then we see that if $\theta$ is the optimal angle, then $\theta = \alpha + \frac{\pi}{2}$ (modulo $2 \pi$, of course).
A: At the optimal configuration, we have $\mathrm dh/\mathrm dx = 0$, that is, moving the foot of the ladder a small amount will not change the height of the top. Conversely, what is the configuration such that if you keep the top fixed and nudge the ladder slightly, its foot remains on the terrain? Only when the ladder is perpendicular to the terrain. The solution follows.
A: $M$ is the endpoint of the ladder on the $y$-axis. $T$ is the endpoint of the ladder on the ground. Draw a circle with center $M$ through the ther endpoint $T$ of the ladder. The radius of the circle is the length of the ladder. If t he ground is tangent to the circle then the height of $M$ is maximal. 
The radius (the ladder) is normal to the tangent (the ground).
The angle $\angle(TMO)$ is equal to the angle between the $x$-axis and the ground. So $\overline{OT}=k$ and the height $\overline{OM}$ can be calculated using the Pythagorean theorem as   $\sqrt{1+k^2}$
