1
$\begingroup$

Is there any reasonably fast way of finding a function of the type

enter image description here

that best fits a given data, for some K and n? For example, the following data closely follows an inverse power law

data = {{98.6, 38.8, 29.2, 23.7, 20.5, 18.1, 17, 15.9, 15, 14.3}}
ListLogPlot[data]

enter image description here

How can I find an expression that fits it?

$\endgroup$
2
  • 1
    $\begingroup$ Actually, your data doesn't really follow a power-law "closely". You can see this by plotting the points on a double logarithmic (log-log) plot: ListLogLogPlot[data] where they should fall on a line if the relationship was indeed a power-law. This can be confirmed with fitting: fit = NonlinearModelFit[First@data, 1/(k v^n), {k, n}, v]; Show[ListPlot[data], Plot[fit[x], {x, 1, 10}]] The fit can be made better by including more terms: NonlinearModelFit[First@data, 1/(k1 v^n1) + 1/(k2 v^n2), {k1, n1, k2, n2}, v] $\endgroup$
    – Domen
    Commented Nov 29, 2022 at 18:08
  • $\begingroup$ Use NonlinearModelFit, as suggested in the other comment. $\endgroup$
    – march
    Commented Nov 29, 2022 at 18:41

1 Answer 1

3
$\begingroup$

How about a sum of functions of that form?

Import["https://raw.githubusercontent.com/antononcube/MathematicaForPrediction/master/MonadicProgramming/MonadicQuantileRegression.m"]
func = First[
  QRMonUnit[N@data] ⟹
   QRMonEchoDataSummary[] ⟹
   QRMonQuantileRegressionFit[lsBasis, 0.5, Method -> {LinearProgramming, Method -> "Simplex"}] ⟹
   QRMonPlot[] ⟹
   QRMonErrorPlots[PlotRange -> All] ⟹
   QRMonTakeRegressionFunctions]
func[x]

(* 7.25308 + 30.0585/x^10. + 57.0715/x^1. + 4.21694/x^0.5 *)
Show[ListLogPlot[data], LogPlot[func[x], {x, 1, Length[data]}]]

enter image description here

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.