First, let’s call the horizontal distance from the ladder’s base on the ground to the building “x.” Consider the two right triangles with bases on the ground and hypotenuses on the ladder, where the first has height along the fence and the second has height along the building.
Call the height the ladder touches on the building “y.” We see through similar triangles that (x-3)/x = 13/y, meaning y = 13x/(x-3).
Now by Pythagorean theorem, the ladder’s length is equal to √(x2+y2). Now, we want to find when this value is at a local minimum. We do this by taking the derivative using the chain rule, keeping in mind that y is a function of x:
d/dx(√(x2+y2)) = (2x+2y(y’))(1/(2√(x2+y2)) = (x+y·y’)/√(x2+y2)
Now we set this equal to 0:
(x+y·y’)/√(x2+y2) = 0
x = -y·y’
Now, y’ is found by deriving 13x/(x-3). d/dx(13(1 + 3/(x-3))) = -39/(x-3)2.
We can rewrite the equation we found now as x = (-13x/(x-3))*(-39/(x-3)2)
This simplifies to (x-3)3 = 3·132. Thus, the optimal x value is 3 + (507)1/3. We can use our expression for y to find y = 13(1 + 3(507)-1/3), then our final expression to solve for the optimal length:
√(x2 + y2) = (1691/3 + 91/3)3/2 ≈ 20.99 feet
This is the minimal ladder length!