Re: FinFit question

*To*: mathgroup at smc.vnet.net*Subject*: [mg54898] Re: FinFit question*From*: Peter Pein <petsie at arcor.de>*Date*: Sat, 5 Mar 2005 01:34:42 -0500 (EST)*References*: <d060ku$koc$1@smc.vnet.net> <d09d0q$d3b$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Kevin wrote: > I suspect the cause of your problem is that the parameter search in > NonlinearFit has been changed in 5.0, and now allows Ro to be sampled in > the negative range, which results in a complex result. > > Here is what I did: > > f[B_, Ro_, x_] := B/Log[x/Ro] > > lsFit[B_, Ro_] := > Plus @@ Apply[ > (Re[f[B, Ro, #1] - #2])^2 & , > points, 1] > > sol = FindMinimum[lsFit[B, Ro], {B, 1000}, {Ro, .01}][[2]] > > I get: > > B = 4021.058892362411 > Ro = 0.009479542538875833 > > with residual: 0.000958775 > > My first try did not have the Re[] in the lsFit definition; however, I > found that I ran into the same complex problem that you had in the > search. So, I modified the function to accomodate, and then checked to > ensure that the final result was a real function over the range of > points. This flexibility is why I always roll my own LSQ fit. > > Cheers, > > Kevin > > Zsolt Reg=E1ly wrote: > > >>Hi >> >>I have used Mathematica 4.2 to solve this problem >> >> points = {{23400, 273.2}, {6800, 298.2}, {2400, 323.2}}; >> T[R_] = NonlinearFit[points, B/Log[R/Ro], {R}, {B, Ro}]; >> >>wihich gives the result as >> >> 4021.05/Log[105.49 R] >> >> >>That is a good result, but when I try to do the same in Mathematica 5.0 >>I get error messaeges and an other solutions, which is surely bad >> >> 1556.90/Log[-0.014 R] >> >>Why doesn't work FindFit for this function in Mathematica 5.0 >> >>Regards, >>Zsolt Regaly (zs.regaly at astro.elte.hu) >> > > As Mathematica doesn't return exact numbers, adding a simple "^2" To Ro would eliminate the problem: In[1]:= points = {{23400, 273.2}, {6800, 298.2}, {2400, 323.2}}; NonlinearFit[points, B/Log[R/Ro^2], {R}, {B, Ro}] Out[2]=4021.0588923639/Log[105.49032254498822*R] -- Peter Pein Berlin