FindFit is producing a list of imaginary numbers when there is non

I am trying to find the fit of an equation to some data and mathematica thinks there is a list of imaginary values. My data is all real positive number.

FindFit[Data, z*(x + shift)^2*Exp[y*Sqrt[x + shift]], {z, y, shift}, x]


FindFit::nrlnum: The function value {-122.656+0. I,-88.6481+0. I,-50.2375+0. I,-25.8042+0. I,-10.6896+0. I,<<42>>,6.49683 +0. I,5.78851 +0. I,1.22054 +0. I,<<450>>} is not a list of real numbers with dimensions {500} at {z,y,shift} = {1.40756,1.57721,-0.273062}. >>

The issue only happens when I add the shift variable.

• Where is your data? – Apple Jul 9 '14 at 13:46

2 Answers

You might want to limit "shift" to positive only? Otherwise your function can be complex? I am guessing the value of "shift" Mathematica obtained from FindFit is negative.

• No need to guess, the error message shows shift = -0.273062. – m_goldberg Jul 9 '14 at 14:46

I've noticed that sometimes I get some small imaginary components due to error etc. You may want to use the Chop[] function to kill anything like that.