Looking for a approximation/solution to my mortgage calculator function

75 Views Asked by At

I'm working on a little function, $t(A,y,r)$ that calculates the monthly payment of a fixed-rate mortgage, where $A$ is the amount borrowed, $y$ is the number of years over which the loan will be paid, and $r$ is the interest rate. The function I'm using is: $$t(A,y,r)=\frac{A(1+r)^y}{12y},$$ where $A>0$ and $r>0$ are real numbers and $y \geq 1$ is a counting number (although this final restriction can be loosened to include all reals $y \geq 1$).

So my question is this: Can I find a solution (or approximation) for the following equation: $$t(A,y,r)-t(A,1,r) = \frac{A(1+r)^y}{12y}-\frac{A(1+r)}{12}=0,$$ where $y>1$.

I tried multiplying by $\frac{12}{A(1+r)}$ to get $\frac{(1+r)^{(y-1)}}{y}-1=0$. Substituting $s=1+r$ and $x=y-1$, I get $s^x/(x+1)=1$ and finally multiplying by $(x+1)$ the equation becomes: $s^x=x+1$ where $x>0$. That's where I get stuck. Can anyone help solve for $x$?

Also, I researched the Lambert W-Function which seemed to have some application here, but I was having trouble understanding how to apply it here; although, I would only be concerned with real solutions.

Edit: By substituting $x=y-1$ and multiplying by $s$, I obtained the rather elegant form: $s^{y}=sy$.

1

There are 1 best solutions below

3
On

The Lambert W-function will do the trick. We start with $s^x = x+1$, and want to have something of the form $f(x)e^{f(x)} = W^{-1}\bigl(f(x)\bigr)$ \begin{align*} s^x &= x+1\\ \iff \frac{s^{x+1}}s &= x+1\\ \iff e^{(x+1)\log s} &= s(x+1)\\ \iff (x+1)e^{-(x+1)\log s} &= \frac 1s\\ \iff -\log s\cdot (x+1)\cdot e^{-(x+1)\log s} &= -\frac{\log s}s\\ \iff -(x+1)\log s &= W\left(-\frac{\log s}s\right)\\ \iff x &= -\frac{W\left(-\frac{\log s}s\right)}{\log s} - 1 \end{align*}