I have a list of points $(x, y)$, and I expect them to be related as $$y = a(b-x)^c,$$ where $a$, $b$, and $c$ are unknown constants. I also know the approximate values of constants, which can be used as initial guess.
How can I fit the curve to my data?
I tried using NonlinearModelFit
, but it returns errors. Here, the actual values (which I am trying to estimate) are $a = 1, b = 1, c = 0.5$.
data = N[Table[{n/50, Sqrt[1 - n/50] + RandomReal[]/10}, {n, 1, 49}]]
(* {{0.02, 0.989949}, {0.04, 0.979796}, {0.06, 0.969536}, {0.08,
0.959166}, {0.1, 0.948683}, {0.12, 0.938083}, {0.14,
0.927362}, {0.16, 0.916515}, {0.18, 0.905539}, {0.2,
0.894427}, {0.22, 0.883176}, {0.24, 0.87178}, {0.26,
0.860233}, {0.28, 0.848528}, {0.3, 0.83666}, {0.32,
0.824621}, {0.34, 0.812404}, {0.36, 0.8}, {0.38, 0.787401}, {0.4,
0.774597}, {0.42, 0.761577}, {0.44, 0.748331}, {0.46,
0.734847}, {0.48, 0.72111}, {0.5, 0.707107}, {0.52, 0.69282}, {0.54,
0.678233}, {0.56, 0.663325}, {0.58, 0.648074}, {0.6,
0.632456}, {0.62, 0.616441}, {0.64, 0.6}, {0.66, 0.583095}, {0.68,
0.565685}, {0.7, 0.547723}, {0.72, 0.52915}, {0.74,
0.509902}, {0.76, 0.489898}, {0.78, 0.469042}, {0.8,
0.447214}, {0.82, 0.424264}, {0.84, 0.4}, {0.86, 0.374166}, {0.88,
0.34641}, {0.9, 0.316228}, {0.92, 0.282843}, {0.94,
0.244949}, {0.96, 0.2}, {0.98, 0.141421}} *)
fit = NonlinearModelFit[data, {a (b - q)^c}, {{a, 0.8}, {b, 0.9}, {c, 0.6}}, q,
Method -> NMinimize]
NonlinearModelFit::nrnum: The function value 1.50013 -0.120551 I is not a real number at {a,b,c} = {0.8,0.9,0.6}.
NMinimize::nnum: The function value Experimental`NumericalFunction[{Hold[Block[{q={0.02,0.04,0.06,0.08,0.1,0.12,0.14,0.16,0.18,0.2,<<39>>},Optimization`FindFit`y$1610={0.989949,0.979796,0.969536,0.959166,0.948683,0.938083,0.927362,0.916515,0.905539,0.894427,<<39>>}},1/2 (Times[<<2>>]-Optimization`FindFit`y\$1610).(Times[<<2>>]-Optimization`FindFit`y\$1610)]],Block},{0,{{{},1,0,Hold[0.8],0,0},{{},1,1,Hold[0.9],0,0},{{},1,2,Hold[0.6],0,0}}},<<3>>,{None,None,None}][{0.8,0.9,0.6}] is not a number at {a,b,c} = {0.8,0.9,0.6}.
In[1]
with my error structure. $\endgroup$