# What can I do to eliminate the error FindFit::nrjnum:?

I am testing the "Power Law with finite-time singularity" hypothesis for world population growth for a project.

The data I'm using (same behaviour should also be exhibited by the stock market, thats why I am trying this with financial data):

raw = FinancialData["GE", All];
fraw = Flatten[raw];
data = Table[fraw[[4*i]], {i, 1, Length[raw]}]; (*extracting just the prices*)


I was trying the following regression model:

model = A + B*(c - x)^z;


And then the following curve fit method:

FindFit[data, {model}, {A, B, c, z}, x]


But I always get the result:

Power::indet: "Indeterminate expression 0.^0. encountered." FindFit::nrjnum: "The Jacobian is not a matrix of real numbers at {A, B, c, z} = {1., 1., 1., 1.}. "

{A -> 1., B -> 1., c -> 1., z -> 1.}

If I do a normal Power law regression, FindFit works perfectly, but the title of the project being "Power Law with finite-time singularity" I need to have the singularity c in the model and the main aim is to find when this singularity occurs.

Is there a way to use FindFit to get the correct answer? Or should I be using some other function?

I have seen other articles on this site concerning issues with FindFit, but none of them has helped me resolve this problem.

Remark: I have already tried the version belisarius has stated below, but the problem with that is that it gives me a z > 0. What I need is z < 0 for x = c to be a singularity. So I also tried the following models: A + B*Abs[c - x]^(-z) and A + B*(c - x)^(-z) with -z instead of z but those just gave me like 15 other warnings.

-
Providing some sensible data would be a first step to reproduce/solve the problem. – Yves Klett Mar 3 '13 at 8:43
@YvesKlett data = Table[{x, RandomReal[{0.9, 1.1}] + model /. {A -> 1, B -> 2, c -> 3, z -> 0.5}}, {x, 0, 3, .01}]; works for me. – Sjoerd C. de Vries Mar 3 '13 at 9:48
@YvesKlett I have added my data source now. – standardeee Mar 3 '13 at 10:23

## 2 Answers

You may try something like:

raw = FinancialData["GE", All];
fraw = Flatten[raw];
data = Table[fraw[[4*i]], {i, 1, Length[raw]}];(*extracting just the prices*)

model = A + B*Abs[c - x]^z;
fit = FindFit[data, {model}, {A, B, c, z}, x];
modelf = Function[{t}, Evaluate[model /. fit]]
Show[Plot[modelf[x], {x, 0, 12000}], ListPlot@data]


-
Perhaps you should explicitly point out that you added an Abs to the model, and explain why that helps. – Sjoerd C. de Vries Mar 3 '13 at 12:38
@SjoerdC.deVries The OP stated that s/he has been given a project name, so I infer that this is some kind of homework. So, just teaching to fish – Dr. belisarius Mar 3 '13 at 12:52
@belisarius Thanks for your reply! As a matter of fact I did try the version you have stated, but the problem with that is that it gives me a z > 0. What I need is z < 0 for x = c to be a singularity. So I also tried the following models: A + B*Abs[c - x]^(-z) and A + B*(c - x)^(-z) but those just gave me like 15 other warnings. – standardeee Mar 3 '13 at 14:15

It looks to me like the data extends to the right of the singularity. Is it acceptable to simply remove that part of the data? It doesn't look like it could possibly fit the model.

FindFit[data[[;; 9500]], model, {{A, 0}, {B, 10^9}, {c, 10000}, {z, -2}}, x]
(*  {A -> -0.0521369, B -> 1.54292*10^10, c -> 11142.5, z -> -2.71708}  *)

Show[ListLinePlot[data], Plot[model /. %, {x, 1, 12000}, PlotStyle -> {Thick, Red}]]


-