*To*: mathgroup@smc.vnet.net*Subject*: [mg10719] Re: NonlinearFit*From*: seanross@worldnet.att.net*Date*: Mon, 2 Feb 1998 00:44:15 -0500*References*: <199801300924.EAA15324@smc.vnet.net.>

Phil Howe wrote: > > I'm having a problem working with NonLinearFit, and would like some > advice. To demonstrate the problem, I'll use a very simple expression, > y==a*x^c +b, where I have assigned a=3, b=7, and c=2. > > Clear[data] > This generates a simple data set: > data=Table[{x, 3*x^2+7 +5*Random[]},{x,0,4,.2}]; > > Now I try to use NonLinearFit. If I specify the value of the exponent, > "c", the routine seems to work. If I ask it to find a value of c, it > chokes, even if I tell it the right answer: > > Remove[a,b,c,x]; > > NonlinearFit[data,a*x^c+b,x, {{c,2},{b,7},{a,3}}]; > > NonlinearFit::"badderiv": "The matrix of model derivatives (dimensions > \!\({3, 21}\)) includes DirectedInfinity in at least one element. Try > fitting without data points having indices in the list \!\({1}\)." > 1) If the nonlinearfit routine ever tries any negative values for x and c is any real number, then the function becomes wildly oscillatory between positive and negative numbers depending on how you want to define a negative number to a fractional power. Trying to evaluate derivatives in this region gives similarly difficult results. Trying to evaluate derivatives at x=0 is similarly problematic because the right anad left hand derivatives are different. That is what gives the directed infinity error message. 2) Using a random number from 0 to 5 to simulate experimental noise may not be a good idea. Your function ranges from 7 to 55 over the range while the noise stays fixed in size at 5 Random[] which makes a signal to noise ratio that ranges from 1.4 near zero to 8 at the end of the range. A better approximation to noise is (1+noise Random[x])(3*x^2+7). To fix the problem, just generate data that doesn't have zero as one of the data points due to the problem of evaluating derivatives there. For example: data=Table[{x,(1+0.15 Random[])( 3*x^2+7)} ,{x,.1,4.1,.2}]; NonlinearFit[data,a*x^c+b,x, {{c,2},{b,7},{a,3}}] returns: 6.756291662079482 + 3.939994195809126*x^1.858652816625926 -- Remove the _nospam_ in the return address to respond.