Let Width = W, then Length = L = 5000/W
Apply the $4 fence on the shorter side W, then total cost
C(W)=$4*(2W)+$2*(2L)
=(8W^2+20000)/W
To find the minimum cost, differentiate C(W) with respect to W and equate to zero and solve for W:
C'(W)=(8W^2-20000)/W^2=0 => 8W^2-20000=0 =>
W=sqrt(20000/8)=50'
Length L=5000/50=100'
We now need to check that W indeed gives a minimum cost C(W).
This can be done by checking the sign of C"(W), the second derivative.
The second derivative C"(W)=40000/W^3 >0, which means that W=50 gives a minimum value for C(W).
The total (minimum) cost is therefore
C(50)=(8*50^2+20000)/50=$800
check average cost = $800/(2(50+100))=$800/300=$2.67 / foot,
which is between $2 and $4, and that sounds reasonable!