Question on Lambert W function

  • #1
1,101
615
TL;DR Summary
Difference between W(x) and Wn(x) ?
In the following I ask WA to solve the given equation and it produces a solution using the Lambert W function.

1700542538883.png

I thought : $$W(x*e^x) = x$$ but here it seems $$W_n \left(\frac{-MT}{P}*e^{\frac{-MT}{P}}\right) \neq \frac{-MT}{P}$$

Is there a difference between ##W(x)## and ##W_n(x)## ?
 
Last edited:
Physics news on Phys.org
  • #2
neilparker62 said:
TL;DR Summary: Difference between W(x) and Wn(x) ?

In the following I ask WA to solve the given equation and it produces a solution using the Lambert W function.

View attachment 335890
I thought : $$W(x*e^x) = x$$ but here it seems $$W_n \left(\frac{-MT}{P}*e^{\frac{-MT}{P}}\right) \neq \frac{-MT}{P}$$

Is there a difference between ##W(x)## and ##W_n(x)## ?
I'm not sure why your example didn't give this. Down in the lower right, on the same line with ##r = \dfrac{2 i \pi n}{T}##, there should be a little comment that "##W_k(z)## is the analytic continuation of the product log function". (W|A calls the principle value of the Lambert W function the product log function.)

-Dan
 
  • #3
Yes I did see that. But it didn't take me anywhere to explain exactly what the "analytic continuation" actually is. And how it differs from the standard Lambert W function ?
 
  • #4
neilparker62 said:
Yes I did see that. But it didn't take me anywhere to explain exactly what the "analytic continuation" actually is. And how it differs from the standard Lambert W function ?
In a nutshell, analytic continuation is a method that is used to extend function values to complex numbers, or even to regions where the function is not "legally" defined (such as ln(-1).) Properly explaining this to someone who has not heard of it is a nearly book length endeavor, so I can only suggest finding a textbook on Complex Analysis.

-Dan
 
  • Like
Likes Delta2 and neilparker62
  • #5
topsquark said:
In a nutshell, analytic continuation is a method that is used to extend function values to complex numbers, or even to regions where the function is not "legally" defined (such as ln(-1).) Properly explaining this to someone who has not heard of it is a nearly book length endeavor, so I can only suggest finding a textbook on Complex Analysis.

-Dan
Thanks - sounds like it is certainly somewhat "out of depth" as far as my limited level of Maths is concerned. But could you perhaps help me understand how the equation is manipulated into a form whereby it can be solved with the Lambert W function. By experimentation I think I've found that ##W_0## is used if: $$\frac{-MT}{P} \times e^{\frac{-MT}{P}} \geq -e^{-1} $$

https://www.desmos.com/calculator/yxfzc1mzll
 
  • #6
neilparker62 said:
Thanks - sounds like it is certainly somewhat "out of depth" as far as my limited level of Maths is concerned. But could you perhaps help me understand how the equation is manipulated into a form whereby it can be solved with the Lambert W function. By experimentation I think I've found that ##W_0## is used if: $$\frac{-MT}{P} \times e^{\frac{-MT}{P}} \geq -e^{-1} $$

https://www.desmos.com/calculator/yxfzc1mzll
See here.

-Dan
 
  • #7
Well I tried working backwards from the given solution:

$$r=\frac{M}{P}+\frac{W\left(\frac{-MT}{P}e^{\frac{MT}{P}}\right)}{T}$$
$$T\left(r-\frac{M}{P}\right)=W\left(\frac{-MT}{P}e^{\frac{MT}{P}}\right)$$
$$T\left(r-\frac{M}{P}\right)e^{T\left(r-\frac{M}{P}\right)}=\frac{-MT}{P}$$
$$\cancel{T}\left(\frac{M-rP}{\cancel P}\right)e^{T\left(r-\frac{M}{P}\right)}=\frac{M \cancel T}{\cancel P}$$
$$P=\frac{M}{r}\left(1-e^{-T\left(r-\frac{M}{P}\right)}\right)$$ Should get $$P=\frac{M}{r}\left(1-e^{-rT}\right)$$ so "close but no cigar" is all I can say! What am I missing ?
 
Last edited:
  • #8
neilparker62 said:
Well I tried working backwards from the given solution:

$$r=\frac{M}{P}+\frac{W\left(\frac{-MT}{P}e^{\frac{MT}{P}}\right)}{T}$$
$$T\left(r-\frac{M}{P}\right)=W\left(\frac{-MT}{P}e^{\frac{MT}{P}}\right)$$
$$T\left(r-\frac{M}{P}\right)e^{T\left(r-\frac{M}{P}\right)}=\frac{-MT}{P}$$
$$\cancel{T}\left(\frac{M-rP}{\cancel P}\right)e^{T\left(r-\frac{M}{P}\right)}=\frac{M \cancel T}{\cancel P}$$
$$P=\frac{M}{r}\left(1-e^{-T\left(r-\frac{M}{P}\right)}\right)$$ Should get $$P=\frac{M}{r}\left(1-e^{-rT}\right)$$ so "close but no cigar" is all I can say! What am I missing ?
##P - \dfrac{M}{r} \left ( 1 - e^{-Tr} \right ) = 0##

##P = \dfrac{M}{r} \left ( 1 - e^{-Tr} \right )##

##\dfrac{P}{M} r = 1 - e^{-Tr}##

##\dfrac{P}{M} r e^{Tr} = e^{Tr} - 1##

##\left ( \dfrac{P}{M} r - 1 \right ) e^{Tr} = - 1##

##\dfrac{M}{P} T \left ( \dfrac{P}{M} r - 1 \right ) e^{Tr} = - \dfrac{M}{P} T##

##\left (T r - \dfrac{M}{P} T \right ) e^{Tr} = - \dfrac{M}{P} T##

##\left (T r - \dfrac{M}{P} T \right ) e^{Tr - (M/P)T} = - \dfrac{M}{P} T e^{-(M/P)T}##

Now, we would like to take the Lambert function of both sides, but we need to make sure that the argument is greater than -1/e. This is where the ##W_n## comes in. We take the nth branch of the W function, (where, honestly, n is an integer that I don't know how to find):

##W_n \left ( \left (T r - \dfrac{M}{P} T \right ) e^{Tr - (M/P)T} \right )= W_n \left ( - \dfrac{M}{P} T e^{-(M/P)T} \right )##

##T r - \dfrac{M}{P} T = W_n \left ( - \dfrac{M}{P} T e^{-(M/P)T} \right )##

So
##r = \dfrac{1}{T} \left ( \dfrac{M}{P} T + W_n \left ( - \dfrac{M}{P} T e^{-(M/P)T} \right ) \right )##

##r = \dfrac{M}{P} + \dfrac{1}{T} W_n \left ( - \dfrac{M}{P} T e^{-(M/P)T} \right )##

-Dan
 
  • Like
Likes dextercioby, neilparker62 and renormalize
  • #9
neilparker62 said:
so "close but no cigar" is all I can say! What am I missing ?
Instead of working backwards, you can solve the original equation by making a variable substitution inspired by the solution that Wolfram found. Start from:$$0=P\,r-M\left(1-e^{-Tr}\right)$$and rewrite ##r## in terms of a new variable ##s## defined via ##r=s+\frac{M}{P}## to get:$$0=P\,s+Me^{-\frac{MT}{P}}e^{-Ts}\quad\text{or}\quad Me^{-\frac{MT}{P}}e^{-Ts}=-P\,s$$Invert both sides of the second equation above:$$\frac{e^{\frac{MT}{P}}e^{Ts}}{M}=-\frac{1}{P\,s}$$and multiply through by ##e^{-\frac{MT}{P}}MTs## to get a solution in terms of Lambert W:$$Ts\,e^{Ts}=-\frac{MT}{P}e^{-\frac{MT}{P}}\Rightarrow Ts=W\left(-\frac{MT}{P}e^{-\frac{MT}{P}}\right)$$Finally, convert ##s## back to the original ##r## variable:$$r=\frac{M}{P}+\frac{1}{T}W\left(-\frac{MT}{P}e^{-\frac{MT}{P}}\right)$$And you're done.
 
  • Like
Likes dextercioby, neilparker62 and topsquark
  • #10
topsquark said:
Now, we would like to take the Lambert function of both sides, but we need to make sure that the argument is greater than -1/e. This is where the ##W_n## comes in. We take the nth branch of the W function, (where, honestly, n is an integer that I don't know how to find):
Thanks so much for this - gives great insight into what's going on 'behind the scenes'!

Concerning n - practically speaking no worries. n=0 is more or less guaranteed by over enthusiastic money lenders ensuring that ##MT/P## is as large as possible. Hence $$ -e^{-1} \leq \frac{-MT}{P} e^{\frac{-MT}{P}}\leq0 $$ For example , I was recently offered a printer for R12550 cash or 36 monthly payments of R631. $$r=\left(\frac{631}{12550}+\frac{W_0(-631*36/12550\times e^{-631*36/12550})}{36}\right) \times 100=3.702\%$$ per month!

https://www.wolframalpha.com/input?i=631/12550+Lambert+w+(-631*36/12550*exp(-631*36/12550))/36
 
Last edited:
  • #11
renormalize said:
Instead of working backwards, you can solve the original equation by making a variable substitution inspired by the solution that Wolfram found. Start from:$$0=P\,r-M\left(1-e^{-Tr}\right)$$and rewrite ##r## in terms of a new variable ##s## defined via ##r=s+\frac{M}{P}## to get:$$0=P\,s+Me^{-\frac{MT}{P}}e^{-Ts}\quad\text{or}\quad Me^{-\frac{MT}{P}}e^{-Ts}=-P\,s$$Invert both sides of the second equation above:$$\frac{e^{\frac{MT}{P}}e^{Ts}}{M}=-\frac{1}{P\,s}$$and multiply through by ##e^{-\frac{MT}{P}}MTs## to get a solution in terms of Lambert W:$$Ts\,e^{Ts}=-\frac{MT}{P}e^{-\frac{MT}{P}}\Rightarrow Ts=W\left(-\frac{MT}{P}e^{-\frac{MT}{P}}\right)$$Finally, convert ##s## back to the original ##r## variable:$$r=\frac{M}{P}+\frac{1}{T}W\left(-\frac{MT}{P}e^{-\frac{MT}{P}}\right)$$And you're done.
Brilliant - that's a very cool substitution!
 
  • #12
neilparker62 said:
Thanks so much for this - gives great insight into what's going on 'behind the scenes'!

Concerning n - practically speaking no worries. n=0 is more or less guaranteed by over enthusiastic money lenders ensuring that ##MT/P## is as large as possible.

For [itex]x = MT/P \geq 0[/itex] it is not possible for [itex]f(x) = xe^{-x}[/itex] to exceed [itex]e^{-1}[/itex], so that [itex]-e^{-1} \leq -xe^{-x}[/itex] is always satisfied.

This follows from taking the derivative [itex]f'(x) = (1 - x)e^{-x}[/itex] and observing that this is positive for [itex]x < 1[/itex] and negative for [itex]x > 1[/itex], so that [itex]f[/itex] attains a global maximum at [itex]x = 1[/itex] where [itex]f(1) = e^{-1}[/itex].
 
  • Like
Likes dextercioby, neilparker62 and topsquark
  • #13
pasmith said:
For [itex]x = MT/P \geq 0[/itex] it is not possible for [itex]f(x) = xe^{-x}[/itex] to exceed [itex]e^{-1}[/itex], so that [itex]-e^{-1} \leq -xe^{-x}[/itex] is always satisfied.

This follows from taking the derivative [itex]f'(x) = (1 - x)e^{-x}[/itex] and observing that this is positive for [itex]x < 1[/itex] and negative for [itex]x > 1[/itex], so that [itex]f[/itex] attains a global maximum at [itex]x = 1[/itex] where [itex]f(1) = e^{-1}[/itex].
Yes - my apologies to finance firms - even if they were to make very little out of the deal, ##W_0## would still solve for the interest rate.

https://www.wolframalpha.com/input?i=solve+++12550+-+350*(1-(e)^(-36r))/r+

However ##W_0## does show up discrepancies in claimed interest rates used. I am not sure on what basis they work out their interest rate but the result is not even remotely close to that calculated using ##W_0##. Albeit using the approximation ##(1+r)^{-T} \approx e^{-rT} ## in the present value formula: $$P=\frac{M(1-(1+r)^{-T})}{r}$$ In this case M is a monthly payment and r is a monthly interest rate with the loan amount P being paid over T months.

One can also use numerical methods (Newton Raphson) to solve directly for r without using the approximation. I think this is what Excel's "Rate" function makes use of since it has an optional "first guess" parameter.
 
  • #14
What rate are they quoting? APR has in Europe a statutory definition which is not calculated using continuous compounding.
 
  • #15
pasmith said:
What rate are they quoting? APR has in Europe a statutory definition which is not calculated using continuous compounding.
Well here's an example of one such deal offered - this one is for a TV set. Using Excel's rate function, I determine the monthly interest rate as =RATE(36,-433,9999,0)=2.6291% per month or 31.5488% pa. So I've no idea where they get 20.75% from.

For low percentages, the continuous compounding model, should provide a reasonably accurate estimate of the above rate. In this case: $$\frac{433}{9999} + \frac{W(-433 \times 36/9999 \times e^{-433\times 36/9999})}{36} = 2.6807\%$$ per month.

Excel is an easier and more accurate choice for this kind of calculation I suppose. I was just intrigued by there being an analytic solution (using Lambert w) in the case of continuous compounding.

1701098560907.jpeg
 
  • #16
Note that the total payable is 15568, which is 35 payments of 433 followed by a final payment of 413. Your calculation assumes 36 equal payments of 433.

The monthly rate [itex]r[/itex] should be given by [tex]
413 = 9999(1 + r)^{35} - 433\frac{(1 + r)^{35} - 1}{r}[/tex] which is ~2.63 % pm or 31.6% per annum, which is also not 20.75%.

Are we neglecting to take account of something basic, such as the R9999 price excluding sales taxes, but the monthly payments and total repayable do include taxes?

EDIT: The sales tax issue seems correct, since adding a sales tax of about 15% to R9999 gives an annual rate of about 20.75%, as is shown in the following graph.
interest rate graph.png
 
Last edited:
  • Like
Likes neilparker62
  • #17
That's certainly a possibility except that a quick google on VAT as charged here reveals that legislation requires advertised prices to be vat inclusive. The one I display is from a major vendor so I don't think they would be taking chances with that unless there is some legal loophole associated with "equal prominence" of both prices whereby the VAT inclusive price is disguised under 36 equal payments of R433 @ 20.75% !

If the VAT-inclusive and VAT-exclusive prices are advertised or quoted, both prices must be advertised or quoted with equal prominence.

I also don't understand how the total payable can be advertised as 15568 when very clearly 36 x 433 = 15588 ??
 
Last edited:
  • #18
pasmith said:
EDIT: The sales tax issue seems correct, since adding a sales tax of about 15% to R9999 gives an annual rate of about 20.75%, as is shown in the following graph.
View attachment 336244
I should mention your search is almost "spot on" because VAT in this country is indeed 15%. A slight problem however is that the above ad is from an old newspaper when VAT was still 14% (?)
 
  • #19
Hi.

To all those who have contributed to this discussion. I am thinking of writing an "Insights" article based around this thread. Does anybody mind me using their contribution(s) ? Will definitely be acknowledged in the "credits" section!
 
  • #20
neilparker62 said:
Hi.

To all those who have contributed to this discussion. I am thinking of writing an "Insights" article based around this thread. Does anybody mind me using their contribution(s) ? Will definitely be acknowledged in the "credits" section!
If you think there's something there to work with, then feel free. Nothing I have said, anyway, does anything new. I'm not worried about any sort of credit.

-Dan
 
  • Like
Likes renormalize
  • #21
topsquark said:
If you think there's something there to work with, then feel free. Nothing I have said, anyway, does anything new. I'm not worried about any sort of credit.

-Dan
Ok thanks. May not be new to you but certainly was to me. I had only ever heard of the Lambert W function when I happened to run into it attempting to solve for interest rate in a continuous analogue of the PV formula!

https://en.wikipedia.org/wiki/Continuous-repayment_mortgage

That was some time back and it's certainly been "insightful" for me to understand exactly how the equation is transformed into a form whereby the Lambert w function may be invoked.

Historically the Lambert w function has an illustrious "pedigree" in respect of those who have worked on it - Lambert himself obviously and none other than the great Euler. Not to mention the more contemporary mathematicians, scientists and engineers who have discovered a number of interesting applications for it.
 
  • #22
neilparker62 said:
Hi.

To all those who have contributed to this discussion. I am thinking of writing an "Insights" article based around this thread. Does anybody mind me using their contribution(s) ? Will definitely be acknowledged in the "credits" section!
This article is now complete - first draft anyway. Would greatly appreciate it if contributors to this thread could review/comment. Any suggestions for changes or inclusions welcome. Thanks in advance.

https://www.physicsforums.com/threads/request-for-review-the-lambert-w-function-in-finance.1059029/
 
  • #24
renormalize said:
When I click on your link, I get "You do not have permission to view this page or perform this action".
Maybe because it's in an administrative group for homework helpers, mentors etc. Sorry about that - I'll post it here as well then.
 
  • #25
Just to keep things tidy here, let me rather provide a link to a pdf of the article which I have uploaded to Google drive. I copied the text from PF editor into Overleaf (online Latex editor) and re-formatted it. Also added in a few helpful (I hope!) links.



Please let me know if you have any trouble accessing the above and once again any comments or suggestions for improvement are most welcome.
 
Last edited:
  • Like
  • Informative
Likes WWGD, chwala and jim mcnamara
  • #26
No problem at all. It sent me to what I believe is your Google drive.
 
  • Haha
Likes SammyS
  • #27
Have updated the link in post #25 after quite a few formatting changes as well as including an additional section.

Edit: Updated again 4th Feb 2024. New section on "Effect of Increasing Payment Frequency" . Tried to address all points raised by reviewers.
 
Last edited:

Similar threads

Replies
3
Views
1K
Replies
3
Views
179
Replies
3
Views
1K
  • Calculus
Replies
28
Views
2K
  • Calculus and Beyond Homework Help
Replies
2
Views
139
Replies
3
Views
1K
Replies
5
Views
947
Replies
4
Views
152
Back
Top