Re: Exponential fit question.
- To: mathgroup at smc.vnet.net
- Subject: [mg28012] Re: [mg27986] Exponential fit question.
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Wed, 28 Mar 2001 02:40:41 -0500 (EST)
- References: <200103270626.BAA21789@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
joe wrote: > > hello. > > I was wondering if someone could help me with the following problem. > > I am trying to perform an exponential fit to the following data > {{x,y}} > > data > ={{50,22},{64,62},{78,122},{93,269},{107,414},{122,507},{136,597}} > > Fit[data,Exp[x],x] > > what I get is > > 1.94272422061017735^-63 *E^x Which is not correct. > > With Excel I get 7.5*E^0.0034x which is correct. > > How can I do this with Mathematica ? > > Thanks. > -Joseph. I think you meant 7.5*E^(0.034x). Fit does a linear fit (as per the usage message) and so cannot change the exponent. You might instead use NonlinearFit in the Statistics` standard add-on packages. In[22]:= data = {{50,22},{64,62},{78,122},{93,269},{107,414},{122,507},{136,597}}; In[23]:= <<Statistics` In[24]:= InputForm[nlfit = NonlinearFit[data, a*Exp[b*x], x, {{a,0,10},{b,0,.2}}]] Out[24]//InputForm= 26.60756323602873*E^(0.023495962867351394*x) Alternatively you can linearize by taking logarithms. This will distort errors with respect to the original model, but all the same frequently gives a good result, and it requires no guess as to starting points, search regions, and the like. In[25]:= data2 = Map[{#[[1]],Log[N[#[[2]]]]}&, data]; In[29]:= linfit = Fit[data2, {1,x}, x] Out[29]= 1.65305 + 0.0379875 x In[34]:= InputForm[origfit = Exp[linfit] /. E^(a_?NumberQ+b_):>E^a*E^b] Out[34]//InputForm= 5.222891180611507*E^(0.037987454694543205*x) The results below may give some feel for the accuracy of these various fits. In[35]:= Map[{#,nlfit/.x->#[[1]]}&, data] Out[35]= {{{50, 22}, 86.1417}, {{64, 62}, 119.694}, {{78, 122}, 166.315}, {{93, 269}, 236.588}, {{107, 414}, 328.739}, {{122, 507}, 467.642}, {{136, 597}, 649.788}} In[36]:= Map[{#,origfit/.x->#[[1]]}&, data] Out[36]= {{{50, 22}, 34.8978}, {{64, 62}, 59.3973}, {{78, 122}, 101.096}, {{93, 269}, 178.731}, {{107, 414}, 304.207}, {{122, 507}, 537.818}, {{136, 597}, 915.385}} In[37]:= Map[{#,7.5*E^(0.034x)/.x->#[[1]]}&, data] Out[37]= {{{50, 22}, 41.0546}, {{64, 62}, 66.0824}, {{78, 122}, 106.368}, {{93, 269}, 177.133}, {{107, 414}, 285.118}, {{122, 507}, 474.804}, {{136, 597}, 764.256}} Daniel Lichtblau Wolfram Research
- References:
- Exponential fit question.
- From: joe <joe@wam.umd.edu>
- Exponential fit question.