Let x be the lengths parallel to the brick side and y be the lengths perpendicular to the brick side...
C=4(2y)+4x+16x
C=8y+20x
The area of this enclosure is xy and we are told that it is equal to 40 ft^2 so:
xy=40, so we can say y=40/x, using this y in our Cost function gives us:
C=8(40/x)+20x
C=320/x+20x
C=(320+20x^2)/x now we can take the derivatives...
dC/dx=(40x^2-20x^2-320)/x^2
dC/dx=(20x^2-320)/x^2
d2C/dx2=(40x^3-40x^3+640x)/x^4
d2C/dx2=640/x^3
Since x>0, the acceleration will always be positive, which means than when dC/dx=0, it will represent an absolute minimum for C(x)...
dC/dx=0 when 20x^2-320=0, x^2=16, x=4
So the sides parallel to the brick wall are 4 feet and those perpendicular to the brick wall are 10 feet when the cost is minimized