# Transform the data, and fitting it with a Lambert function

I got a list of numbers $$x$$:

{152.5285260903254, 153.08990920351394, 150.5730994009649, 149.0795578315097, 150.88564540579486, 152.3019304735997, 152.37506265139996, 152.51287363037363, 156.84267475421257, 155.85016036253063, 159.11346614134825, 158.80508701729102, 161.82212273568132, 161.45879678320438, 161.57999620831998, 163.05078964530156, 163.40668013399412, 165.61439029469895, 165.96286560965856, 166.85424050737484, 167.84426760187614, 168.10577531838976, 170.94478872202194, 172.09262076110664, 173.21079646594495, 174.51889536587046, 176.0434240141512, 174.42493778541734, 178.08383020438276, 180.04544009519114, 180.84630456751376, 183.09581891182182, 185.48799769181767, 184.0226947181274, 185.20548948442453, 187.803111339266, 191.61775408658363, 192.54080319349242, 197.05568077436087, 199.394528570621, 198.2305613405485, 197.29702476574695, 199.85296147031664, 202.0625912703998, 203.7599405786387, 205.15720711276578, 208.60676201877635, 210.30578229203624, 211.48607218315064, 214.02872244302984, 217.2862486864062, 219.0654506776754, 219.51905466149833, 221.72865971916855, 223.88234152720256, 226.37434747890677, 225.5354475953967, 230.8811023008481, 230.35177385240976, 230.81008964379734, 233.41498824837703, 235.89130152137233, 235.60438118129062, 237.34417095771278, 239.43251410697522, 243.17225554377904, 245.1824087393706, 247.35708261994085, 248.08949915806144, 252.81989317545782, 255.38600977529074, 255.4233986582199}


Each number corresponds to a certain time $$t$$, let's say the first number is a $$t=0$$, the second $$t=1$$, ... and so on $$x_i=x(t=i)$$.:

That I want to fit the function that has 3 parameters $$a,b,c$$ :

(-b - b ProductLog[-1,-(E^(-1 - (a^2 (t + c))/b)/b)])/a


I assume the best way to proceed is to use the command

NonlinearModelFit[]


I read the wolfram guide for it but I'm a bit lost... and I think that my data is not written correctly as $$\{\{x_i,t_i\}...\}$$ and I don't know how to change that.

Could you help me plz ?

PS: The function I want to fit it with is just the solution of $$x'(t)=a+b/x(t)$$

Edit : Following @CarlLange, I wrote :

fn[t_] = (-b - b*ProductLog[-1, -(E^(-1 - (a^2 (t + c))/b)/b)])/a
data={...} "I copied all the number inside "
data0 = Transpose[{data, Range[Length@data]}]
model = NonlinearModelFit[data0, fn, {a, b, c}, t]


but I get the error :

NonlinearModelFit::nrlnum: The function value {-1.+fn,-2.+fn,-3.+fn,-4.+fn,-5.+fn,-6.+fn,-7.+fn,-8.+fn,-9.+fn,-10.+fn,-11.+fn,-12.+fn,-13.+fn,-14.+fn,-15.+fn,-16.+fn,-17.+fn,-18.+fn,-19.+fn,-20.+fn,-21.+fn,-22.+fn,-23.+fn,-24.+fn,-25.+fn,-26.+fn,-27.+fn,-28.+fn,-29.+fn,-30.+fn,-31.+fn,-32.+fn,-33.+fn,-34.+fn,-35.+fn,-36.+fn,-37.+fn,-38.+fn,-39.+fn,-40.+fn,-41.+fn,-42.+fn,-43.+fn,-44.+fn,-45.+fn,-46.+fn,-47.+fn,-48.+fn,-49.+fn,-50.+fn,<<22>>} is not a list of real numbers with dimensions {72} at {a,b,c} = {1.,1.,1.}.

which I don't understand !

------>>>> I found the solution by writing directly my function in the command

data={...} "I copied all the number inside "
data0 = Transpose[{data, Range[Length@data]}]
model = NonlinearModelFit[data0, (-b - b*ProductLog[-1, -(E^(-1 - (a^2 (t + c))/b)/b)])/a, {a, b, c}, t]


And no error anymore

Edit : Regarding the other comment of @CarlLange , is there a way to ask a fit in the space in which the values of the function are real numbers ?

Edit : Why did I choose this function ? The function

     (-b - b ProductLog[-1,-(E^(-1 - (a^2 (t + c))/b)/b)])/a


is the solution of the equation : $$f'(x)=a+b/f(x)$$

 DSolve[G'[x] == a + b/G[x], G, x][[1]]


{G -> Function[{x}, (-b - b ProductLog[-(E^(-1 - (a^2 (x + C[1]))/b)/b)])/a]}

• I'm not sure that your function you'd like to fit is correctly defined, but your data should be fine as input like so: model = NonlinearModelFit[data, fn, {a, b, c}, t] where fn is the function above and data is the list. However, this returns a model with complex results, which I assume you do not want.. – Carl Lange Jan 24 at 16:48
• Also, if you would like your data in the format {{x1,t1}, {x2,t2}...} you can use this: Transpose[{data, Range[Length@data]}] - but it is not strictly necessary for NonlinearModelFit. – Carl Lange Jan 24 at 16:52
• Can you explain (that is, show the code) for how you arrived at (-b - b*ProductLog[-1, -(E^(-1 - (a^2 (t + c))/b)/b)])/a? – Carl Lange Jan 24 at 22:22
• @CarlLange Actually I played a lot with the parameters, and at the beginning I was supposing that I had to use the branch -1 of the Lambert function, but actually maybe not because I thought $b>0$... So I played with the main branch and no assumption on $b$ but nothing really comes out. After some reflections, I also noticed that the derivative was not decreasing as it should if my equation was adapted. So the model in order to describe the curve I used is probably wrong. I was curious to see what would come out from the model but not much apparently... Thx anyway for your help ! – J.A Jan 24 at 23:07
• @CarlLange I mean in order to explain more I should explain to you the topic I'm studying, which would not be appropriate in that forum. But I did learn something thanks to u ! – J.A Jan 24 at 23:08