Re: Using a function defined by NIntegrate in NonLinearFit
- To: mathgroup at smc.vnet.net
- Subject: [mg14530] Re: Using a function defined by NIntegrate in NonLinearFit
- From: Paul Abbott <paul at physics.uwa.edu.au>
- Date: Thu, 29 Oct 1998 04:33:26 -0500
- Organization: University of Western Australia
- References: <70rak2$sfm@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Olivier Pelletier wrote: > my problem is the following: > I have defined a funtion > inten[q_,a_,b_,c_]:=NIntegrate[...] > Now I want to perform a non linear fit using inten[q,a,b,c] as a model. > The problem is that NIntegrate as HoldAll as an attribute which seems > to generate a conflict. Use a test to test that the argument(s) to inten are numeric. E.g., In[1]:= Needs["Statistics`NonlinearFit`"] Here is the model: In[2]:= model[(x_)?NumericQ] := Module[{t}, NIntegrate[t^x, {t, 0, 1}]] Some dummy data: In[3]:= data = Table[{x, model[x] + Random[Real, {-0.1, 0.1}]}, {x, 0, 5}]; Compute the fit: In[4]:= NonlinearFit[data, a*model[x] + b, x, {{a, 1}, {b, 0}}, ShowProgress -> True] Display the fit and the data: In[5]:= ListPlot[data, PlotStyle -> {Hue[1], AbsolutePointSize[3]}, Epilog -> Plot[%, {x, 0, Length[data]}, DisplayFunction -> Identity][[1]]]; Cheers, Paul ____________________________________________________________________ Paul Abbott Phone: +61-8-9380-2734 Department of Physics Fax: +61-8-9380-1014 The University of Western Australia Nedlands WA 6907 mailto:paul at physics.uwa.edu.au AUSTRALIA http://www.physics.uwa.edu.au/~paul God IS a weakly left-handed dice player ____________________________________________________________________