Keeping a dynamic-dimensioned square centered in a rectangle For some reason this problem which seemed fairly easy on the surface has given me a lot of trouble. I have a square who's side length changes based on an independent variable. The square's upper left corner is at the origin, and the square's lower right corner is at $(l_f,-l_f)$, where $l_f$ is the length of the square. 

Our rectangle must always have a width to heigth ratio of $1280/720$. When the square is at it's initial length, the length of the square and the height of the rectangle should  be the same. Additionally, the square must always be directly in the middle of the rectangle (that is, the center of the square and the center of the rectangle coincide). And finally, the ratio of the square's length and the rectangles lengths must get linearly smaller as the square's length decreases, and linearly larger as the square's length increases. I need the equations for $(x_i,y_i)$ and $(x_f,y_f)$, where $x_i$ and $y_i$ are the coordinates of the top left corner of the rectangle, and $x_f,y_f$ are the coordinates of the bottom right corner of the rectangle,  based on the following variables. 

$d = $ an independent variable, in the domain $(0, \infty)$, initial value of $1$

$l_i = $ constant (initial size of square...for my problem it is 250)

$l_f = l_i\cdot d \rightarrow$ (where $l_f$ is the length of the square) 

My Attempt

I believe my attempt at getting the y limits is correct. 
$$y_i = \frac{l_f}{2} - \frac{l_i}{2}$$ $$y_f = \frac{l_f}{2} + \frac{l_i}{2}$$

The $x$ coordinates are the hard ones now. Because the initial height of the rectangle and the length of the square must be the same, we need a corrective term to add onto the $x$ coordinates. The following term worked (not sure if it's neccessary in the end though). $\frac{1}{2} \cdot l_f(\frac{1280}{720} - 1)$. Then, if the independent variable changes from it's default value of 1, we need another term since the width and height of the rectangle can't continue to scale at the same rate, otherwise the 1280x720 ratio is not maintained. I thought this term would do the trick $\frac{1280}{720}(\frac{l_f}{2} - \frac{l_i}{2})$, but using these terms does not give me the correct answer. Using these terms, I get the following:

$$x_i = \left(1 + \frac{1280}{720}\right) \left(\frac{l_f}{2} - \frac{l_i}{2}\right) - \frac{1}{2} \cdot l_f\left(\frac{1280}{720} - 1\right)$$
$$x_f = \left(\frac{l_f}{2} + \frac{l_i}{2}\right) - \frac{1}{2} \cdot l_f\left(\frac{1280}{720} - 1\right) - \frac{1280}{720} \left(\frac{l_f}{2} - \frac{l_i}{2}\right)$$

Like I said this doesn't work though. Let me know if you have any tips, thanks!
If I'm understanding everything correctly, here's what I think you're looking for:
\begin{align*}
y_i &amp;= \dfrac{-l_i}{2} - \dfrac{l_f}{2} \\
y_f &amp;= \dfrac{-l_i}{2} + \dfrac{l_f}{2} \\
x_i &amp;= \dfrac{l_i}{2} - \dfrac{\frac{1280}{720}l_f}{2} \\
x_f &amp;= \dfrac{l_i}{2} + \dfrac{\frac{1280}{720}l_f}{2} \\
\end{align*}
Here's what I did. Initially, the centre of the square/rectangle is at $(l_i/2, -l_i/2)$. Note that linearly scaling the square/rectangle by a factor of $d$ will not change this centre point. Now to get the corners, we simply have to either add or subtract half the dimensions of the rectangle. Initially, the rectangle has a height of $l_i$, so scaling it by $d$ gives us a new height of $l_f$. Since we know the aspect ratio, it follows that the new width must be $\frac{1280}{720}l_f$.
From the answers you gave to my comments, I figured you mixed up the $y$-direction in your question. You say that the rectangle is centered at $(l_f/2, -l_f/2)$, but in your calculation you use $(l_f/2, l_f/2)$ to obtain the $y$-boundaries of your rectangle. (Note that you get $y_f=l_f$ for $d=1$ instead of $y_f=-l_f$ as you told me in a comment.)

Suppose the formulas for the $y$-boundaries are correct in your question and the center of the square is in fact at $(l_f/2, l_f/2)$ so everything fits together, I would guess you want the following $x$-boundaries for the rectangle:

$$\begin{align*}
x_i &amp;= \frac{l_f}2 - \frac{1280}{720} \cdot \frac{l_i}{2} \\
x_f &amp;= \frac{l_f}2 + \frac{1280}{720} \cdot \frac{l_i}{2}
\end{align*}$$