This problem can be solve by using ration and proportion, since you want to enlarge the picture by not distorting the image, the new dimensions should be in proportion with the old one.
Let x be length of the image
(5/40 = (x/5)
X = 5(5/4)
X = 6.25 in