MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Using a function defined by NIntegrate in NonLinearFit

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]]]; 


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  AUSTRALIA              

            God IS a weakly left-handed dice player

  • Prev by Date: Newton-Raphson Method
  • Next by Date: Logarithmic plot
  • Previous by thread: Using a function defined by NIntegrate in NonLinearFit
  • Next by thread: stats libs/add ons