# How to solve this FindFit::nrlnum:

the following code show error message

FindFit::nrlnum: "The function value {6.71759 -9.36268*10^-8\ I,6.51797 -8.42641*10^-8\ I,6.31789 -7.49014*10^-8\ I,6.1179 -6.55387*10^-8\ I,5.91794 -5.61761*10^-8\ I,5.71797 -4.68134*10^-8\ I,<<5>>,4.53457 +0.\ I,4.35846 +0.\ I,4.21276 +0.\ I,4.12436 +0.\ I,4.12268 +0.\ I}\n is not a list of real numbers with dimensions {16} at {a,b} = {1.,1.}. "

FindFit[{{-1.9999999999999993, -8.71758682396597}, \
{-1.7999999999999994, -8.317969980679658}, {-1.5999999999999996, \
-7.9178913932701125}, {-1.3999999999999995, -7.517895681098703}, \
{-1.1999999999999997, -7.117935726160363}, {-0.9999999999999997, \
-6.717970679612214}, {-0.7999999999999997, -6.318075235251766}, \
{-0.5999999999999999, -5.918333526484718}, {-0.3999999999999999, \
-5.518978976322539}, {-0.1999999999999999, -5.120597037968602}, \
{0., -4.724630562634576}, {0.1999999999999997, \
-4.334574650968856}, {0.3999999999999999, -3.9584626158001357}, \
{0.6000000000000001, -3.6127563661613884}, {0.7999999999999998, \
-3.324357131929245}, {0.9999999999999994, -3.1226771789912595}},
a x^b, {a, b}, x]


I tried the method here, but all didn't work.

data = {{-1.9999999999999993, -8.71758682396597}, \
{-1.7999999999999994, -8.317969980679658}, {-1.5999999999999996, \
-7.9178913932701125}, {-1.3999999999999995, -7.517895681098703}, \
{-1.1999999999999997, -7.117935726160363}, {-0.9999999999999997, \
-6.717970679612214}, {-0.7999999999999997, -6.318075235251766}, \
{-0.5999999999999999, -5.918333526484718}, {0., \
-4.724630562634576}, {-0.3999999999999999, -5.518978976322539}, \
{-0.1999999999999999, -5.120597037968602}, {0.1999999999999997, \
-4.334574650968856}, {0.3999999999999999, -3.9584626158001357}, \
{0.6000000000000001, -3.6127563661613884}, {0.7999999999999998, \
-3.324357131929245}, {0.9999999999999994, -3.1226771789912595}};
model = a x^b;
f = FindFit[data, model, {a, b}, x,NormFunction -> (Norm[#, Infinity] &)]

(* {a -> 1.90367964288013, b -> 1.10590831050973} *)


Use different Norm function. Gradient -> "FiniteDifference" is not really needed, I just left it there, since help says to use it when getting singularity. But it will work without it here if you use infinity norm.

But the fit does not look good. There is a constant offset, and does not generate go to the negative x as the data does:

 Show[ListPlot[data], Plot[model /. f, {x, -1, 2}], PlotRange -> All]


• Interesting, your method works in MM9 while not work in MM8. And I really don't understand that the data points are so trivial, why I have to add so many options to make the fit work? Commented Dec 3, 2013 at 7:25
• Oh,I understand why. I made a silly mistake, what a shame! I give Mathematica an improper fitting function, I should have add a constant term. Thank you Nasser! Commented Dec 3, 2013 at 14:57

The negative values for the model chosen pose the problem. There are a number of approaches noting the data: 1. a linear model (this give quite a reasonable fit) 2. Using non linear model fit with your model but transforming your data 3. Perhaps, the simplest approach and using your desired FindFit is to transform your data and back transform.

ft = FindFit[# + {2, 9} & /@ data, a x^b, {a, b}, x]


{a -> 2.33187, b -> 0.862647}

Show[ListPlot[data],