Could someone please help me?
I'm not a mathematician, but rather a programmer - I'm trying to use
Mathematica to rearrange a formula for me.
I'm trying:
Solve[a^b - b == c, b]
Which gives me:
Out[3]//TextForm=
Log[a]
ProductLog[-(------)]
c
a
{{b -> -c - ---------------------}}
Log[a]
The problem with this is that I need the solution to use normal
'primitive' (if thats the right word) math functions as I need the
formula for a computer program.
With ProductLog being an internal Mathematica function I cant
therefore use this rearrangement.
What can I do so that there is no ProductLog in there? Please go easy
on me as I'm not a math major :0) or that au fait with Mathematica.
If it helps both a and b are always positive.
Many thanks
-Rob
ProductLog is also known as the Lambert W function. You can find a
description of it here
http://mathworld.wolfram.com/LambertW-Function.html. There are a
couple of asymptotic series and an approximation of W(x) for x>=3
given. Knuth and Robert Corless published a few papers on the function
which a listed here
http://www.apmaths.uwo.ca/~rcorless/frames/PAPERS/LambertW/. Algorithm
443 of the Communications of the ACM is supposed to evaluate Lambert's
W for the principle branch and positive real arguments. For a > e
however your argument is going to be negative, apparently Algorithm 443
can be extended to account for this according to Corless. Note that
W(z) is complex valued for z<0.
Regards,
Ssezi
ProductLog, or W, *is* elementary, in the sense that it cannot be
expressed in terms of more common elementary functions.
If all you want is a numerical solution, it may be easier and faster to
apply a numerical root finding algorithm to your original equation
rather than attempt to numerically evaluate a symbolic solution.
if you are a programmer you may
a) implement a root search that solve the equation numerical
b) implement the ProductLog[] function
Regards
Jens
Mathematica didn't invent this function; it's just one that you didn't
personally recognize. It's often called the LambertW -- see
http://mathworld.wolfram.com/LambertW-Function.html
Here are some of your alternatives:
(1) A Newton's method iteration will work just about anywhere.
(2) Perhaps your target system does have the LambertW function.
(3) You could code the LambertW on the target system,
although it would probably amount again to just coding Newton's
method if the target system is a (non-symbolic) system like
C/C++/Fortan/Basic etc.
regards,
alan
>Solve[a^b - b == c, b]
>Which gives me:
>Out[3]//TextForm=
> Log[a]
> ProductLog[-(------)]
> c
> a
>{{b -> -c - ---------------------}}
> Log[a]
>The problem with this is that I need the solution to use normal
>'primitive' (if thats the right word) math functions as I need the
>formula for a computer program.
>With ProductLog being an internal Mathematica function I cant
>therefore use this rearrangement.
>What can I do so that there is no ProductLog in there?
You can't. There is no closed form solution without the ProductLog function or the equivalent with a different name. If you are trying to write program that doesn't depend on Mathematica at runtime and need the solution to a^b - b == c, you will have to either write your own numeric solver or a routine to implement the ProductLog function.
--
To reply via email subtract one hundred and four
Debug.Print MyFunction(3, 4, -1)
-3.98748338411597
and in Mathematica, I get the same answer:
{-c - ProductLog[(-a^(-c))*Log[a]]/Log[a]} /. {a -> 3, c -> 4.}
-3.9874833841159707
Function MyFunction(a, c, guess)
Dim b As Double
Dim LastGuess As Double
Dim Counter As Long
b = guess
LastGuess = b + 1 ' Just make it different
Do While LastGuess <> b And Counter <= 10
LastGuess = b
b = (c + a ^ b * (-1 + b * Log(a))) / (-1 + a ^ b * Log(a))
Counter = Counter + 1
Loop
MyFunction = b
End Function
Some functions will return an answer that alternates in the last digit.
Therefore, in some problems, the last guess will never equal the new
guess.(they will be different in the last digit). Therefore, you need to
account for this. I just limited the loops to 10. Adjust to your own
situation.
HTH
Dana DeLouis
"Robert Hulme" <robert...@gmail.com> wrote in message
news:ccisbq$4de$1...@smc.vnet.net...
But note that there is also a positive solution for b, given by using the
other real branch (i.e., the -1 branch) of ProductLog:
In[1]:= -c - ProductLog[-1,(-a^(-c))*Log[a]]/Log[a] /. {a -> 3, c -> 4.}
Out[1]= 1.56192
I would guess it's at least as likely that that would be the desired
solution in the application at hand.
In any event, to get rid of ProductLog, one can of course approximate it
using a truncated version of an appropriate series expansion. For example,
rather than doing what you've shown below to approximate the negative root
in your sample case, we can approximate ProductLog (a.k.a. Lambert W) using
z - z^2 + 3/2 z^3 +-... Using just the three terms shown, we get
In[2]:= ApproxW[z_]:= z - z^2 + 3/2 z^3
In[3]:= -c - ApproxW[-Log[a]/a^c]/Log[a] /. {a -> 3, c -> 4.}
Out[3]= -3.98748
See the Lambert W entry at MathWorld or the ProductLog entry at the Wolfram
Functions site for more information on appropriate series.
David