MathGroup Archive 2005

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

Search the Archive

Re: nonLinearFit and nonLinearRegress

  • To: mathgroup at
  • Subject: [mg55316] Re: nonLinearFit and nonLinearRegress
  • From: Peter Pein <petsie at>
  • Date: Sat, 19 Mar 2005 04:45:17 -0500 (EST)
  • References: <d1ecpc$etg$>
  • Sender: owner-wri-mathgroup at

John Hawkin wrote:
> I'm trying to do a nonLinear fit on some data, fitting a parameter
> which appears in the limits of the integral that I'm trying to fit. 
> When I do a nonLinearFit, I get about a page of errors, but it does
> work.  It takes about 10 minutes to do it for 20 points with a
> reasonable initial estimate.  However when I use the nonLinearRegress
> command, even with the best fit parameter from nonLinearFit given as
> the initial guess, it takes hours to work.  Is it possible there is a
> way to speed this up, and is this normal?
> The commands that I'm using to integrate this function are:
> h[B]:=2/(B pi) NIntegrate[x Sin[x] Exp[-(x/B)^3/2], {x, 0, inf},
> Method-Oscillatory];
> holts[c_, d_, Q_]:= NIntegrate[h[B], {B, c/Q, d/Q}];
> where holts is the function I am fitting (the h[B] integral is known
> as the Holtsmark integral).  The fitting command I'm using is:
> NonlinearFit[fitData, holts[c,d,Q], {c,d}, {Q, estimateQ}];
> where fitData contains sets of size 3, with the values of c and d as
> the first two values, and the data point that I'm fitting the integral
> to as the 3rd value.  If anyone has any ideas on how I can perform the
> nonlinear regression fast enough so that I can do it many times (maybe
> 50), I would greatly appreciate it.  Thanks very much,
> John Hawkin
Hi John,

if you are working with reals only, you can try to integrate exactly
before approximating:

If you enter

Assuming[Element[B, Reals] && z > 0,
  Integrate[(2*Integrate[(x*Sin[x])/E^((1/2)*(x/B)^2), {x, 0,
Infinity}])/(B*Pi), {B, 0, z}]]

or assuming z<0 and the outer integral going from z to 0 you get

h0[z_] := ((-Sqrt[2/Pi])*z + E^(z^2/2)*Erf[z/Sqrt[2]])/E^(z^2/2);
holts[c_, d_, Q_] := h0[d/Q] - h0[c/Q];

this should speed things up.

Peter Pein

  • Prev by Date: Re: Clamped cubic spline
  • Next by Date: Re: Distance from point to set
  • Previous by thread: Re: nonLinearFit and nonLinearRegress
  • Next by thread: Re: nonLinearFit and nonLinearRegress