Having deposited $\$5,000$ at $9\%$ annual interest, for how many years can you withdraw $\$500$? What's a good way to iterate this? NOTES:
I hope the tags are appropriate, this is a homework problem EDIT (another note): if it makes a difference, this question may involve calculus since it's in my calculus homework... I doubt it would make sense to use calculus in any way here

If you deposit $5,000$ dollars at $9\%$ annual interest, for how many years can you withdraw $500$ dollars (starting after the first year) without running out of money?

I've tried several equations, such as: $f(x)=5000(1.09)^x-500x$ but this never reaches $0$
The most recent thing I've tried is setting up an iteration equation: $x_{n+1}=x_n(1.09)-500$ where $x_0=5000$ which I will iterate until $x_{n+1}\le0$.
Question: Can I easily make Desmos (and the like) repeat iteration equations to infinity? AND Is there a way I can solve this problem without having to iterate (an equation that doesn't use the previous output as the next input)?
Bonus: If there's a way to turn my iteration into a "regular"<--(lack of technical terms) equation, can all iteration equations be made that way as well? Is there a general way to take an iteration equation and turn it into a simple $f(x)$ function?
 A: The problem with your formulation of $f(x)$ is that you're compounding the 9% for $x$ years and then removing $ \$500$ per year as an aggregate after $x$ years, not each year. You want to reformulate the function by compounding the $ \$500 $ every year too:
$$ f(x) = 5000*1.09^x - \sum_{k=1}^{x} {500*1.09^{k-1}} . $$
This is a geometric series, so you can find a closed-form solution to the sum, then iterate.
A: Let $A=5000$ be the Amount you start with, and let $W=500$ be the amount you Withdraw at the end of each year. Let $r=.09$ be the annual interest rate, and, for convenience, let $R=1+r$. The amount that's left after your first withdrawal is $AR-W$. On compounding this, the amount that's left after your second withdrawal is $(AR-W)R-W=AR^2-W(R+1)$. Compounding this remainder, the amount left after the third withdrawal is
$$(AR^2-W(R+1))R-W=AR^3-W(R^2+R+1)$$
and so forth. I.e., the amount left after the $n$th withdrawal is
$$AR^n-W(R^{n-1}+R^{n-2}+\cdots+R+1)=AR^n-W{R^n-1\over R-1}$$
Our only constraint is that this amount must be non-negative, that is
$$AR^n\ge W{R^n-1\over R-1}$$
A little algebra rewrites this as
$$(1+r)^n=R^n\le{W\over W-(R-1)A}={W\over W-rA}$$
which implies
$$n\le{\log(W/(W-rA))\over\log(1+r)}$$
Plugging in our values for $A$, $W$, and $r$, we find that
$$n\le{\log(10)\over\log(1.09)}\approx26.719$$
which implies the number of times you can withdraw $\$500$ without running out of money is $26$.
Remark: It's important here that $W\gt rA$. That is, if your account earns more each year than you withdraw, you'll never run out of money!
