Re: Nonlinear Fit
- To: mathgroup at smc.vnet.net
- Subject: [mg38387] Re: Nonlinear Fit
- From: "Carl K. Woll" <carlw at u.washington.edu>
- Date: Fri, 13 Dec 2002 04:10:07 -0500 (EST)
- Organization: University of Washington
- References: <at9c7d$pu4$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hypermars, Your question has come up before, and I will give you the solution I like the best. The problem you are having arises because Mathematica doesn't know how to differentiate your function. So, my solution is to teach Mathematica how to do the derivative. First, we need to change your function definition so that the definition is applied only when the arguments to the function are numbers: f[r_?NumericQ,a_?NumericQ] := NIntegrate[x/(x^2+a^2) Exp[-x^2] BesselJ[0,x r],{x,0,Infinity}] Next, the derivative with respect to r is fr[r_?NumericQ,a_?NumericQ]:=NIntegrate[x/(x^2+a^2)Exp[-x^2](-x BesselJ[1,x r]),{x,0,Infinity}] fa[r_?NumericQ,a_?NumericQ]:=NIntegrate[-2 a x/(x^2+a^2)^2Exp[-x^2]BesselJ[0,x r],{x,0,Infinity}] We need to teach Mathematica about these derivatives: Derivative[1,0][f]=fr; Derivative[0,1][f]=fa; Now, we're all set. Let's create some data: data=Table[{i,f[i,1]+Random[]10^-3},{i,0,1,10^-2}]; Load the package and run NonlinearFit: <<Statistics`NonlinearFit` NonlinearFit[data,f[r,a],r,{a}] Good luck, Carl Woll Physics Dept U of Washington "Hypermars" <hypermars00 at yahoo.com> wrote in message news:at9c7d$pu4$1 at smc.vnet.net... > Hello, > > regarding the package "Statistics'NonlinearFit'" is it possible to fit an > array of data with a function defined by NIntegrate? > > Example: > > f[r_,a_] := NIntegrate[x/(x^2+a^2) Exp[-x^2] BesselJ[0,x r],{x,0,Infinity}] > > BestFitParameters /. NonlinearRegress[data,f[r,a],r,{a},RegressionReport -> > BestFitParameters] > > I mean, I know it's not possible because I tried and it doesn't work, but I > was wondering if there is some way to do that. > > Any suggestion is more than welcome. > > Thanks > Hyper > > >