Re: Getting rid of ProductLog

*To*: mathgroup at smc.vnet.net*Subject*: [mg49292] Re: Getting rid of ProductLog*From*: "David W. Cantrell" <DWCantrell at sigmaxi.org>*Date*: Mon, 12 Jul 2004 02:11:32 -0400 (EDT)*References*: <ccisbq$4de$1@smc.vnet.net> <ccqm5c$gcn$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

"Dana" <delouis at bellsouth.net> wrote: > Here is my attempt using Excel vba. You need to supply a good initial > guess. Here, you enter a=3,c=4, and a guess of -1, I get... > > 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 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 > 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.hulme at gmail.com> wrote in message > news:ccisbq$4de$1 at smc.vnet.net... > > Hi, > > > > 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 > >