The equation for a ellipse centered in the origin is
(x/A)^2 + (y/B)^2 = 1
Now if you want to enclose a rectangle of MxN with a eclipse you can move its center to the origin of coordinates. The top right coordinates are (M/2,N/2), replacing in the ellipse equation you have a formula you can use to solve B given A (or A given B).
If you have a rectangle of 4x2, the top-right coordinates are (2,1), replacing you have the (2/A)^2 + (1/B)^2 = 1, then if A=4 solving for B gives B=1/sqrt(1-(1/2)^2).