I am trying to fit the function $A/x³$ to some data points (X,Y). I tried using least squares to fit the function $A x^3$ to the data points (1/X,Y) using least squares. However I do not obtain a good result. I though that maybe the data points need to be weighed somehow?

fit result

Here is the python function I am using right now:

def fit_params(x,y):
    M = np.atleast_2d(1/x[1:]**3).T
    weigth = np.diag(1/y[1:]**2).T
    p, res, rnk, s = lstsq(M, y[1:])
    plt.plot(x, y, 'o', label='data')
    plt.plot(x, p*x**(-3.), label='fit')
    return p

I obtained an equally bad result when using from scipy.curve_fit but that may be because of bad initial guesses. I also tried np.polyfit and just deleting all other coefficients, but that doesn't make sense, I think. It also led to a bad result.

In case you need the full data and code, you can have a look here.

Would appreciate any query and if needed can provide further clarification.

  • 4
    $\begingroup$ It doesn't look like your data obeys the $A/x^3$ relation $\endgroup$
    – Firebug
    Nov 21 at 10:25
  • 2
    $\begingroup$ You can let the power automatically be determined by fitting $y ~ \beta_0 + \beta_1 \log x$. $\endgroup$
    – cdalitz
    Nov 21 at 11:31
  • 2
    $\begingroup$ None of those suggestions will work, because the response is finite at $x=0.$ You should be exploring the possibilities rather than trying to shoehorn them into some preconceived formula. Could you explain why you want to use a power function for this fit? That might help suggest alternatives. $\endgroup$
    – whuber
    Nov 21 at 13:46
  • 1
    $\begingroup$ Taking the logs of both variables would linearize a power function, but that can't work as whuber points out. If you do that with your data you can see that even ignoring the issue with $x=0$, it's still clearly non linear on the log-log scale. The middle 10 values are not so far from linear but even there the slope on the logged data is nowhere near -3. $\endgroup$
    – Glen_b
    Nov 21 at 16:41
  • 1
    $\begingroup$ What exactly is the distance and how is it measured? $\endgroup$
    – Firebug
    Nov 23 at 10:13

1 Answer 1


By inspection one observe a particular behaviour at low values of $x$.

The next figure shows the function $(x^ay)$ for $a=0\;,\:a=1\;,\:a=2\;,\:a=3$.

enter image description here

One could draw intermediate cases with non integer $a$.

Nevertheless this is enough to see that the function is not simple at low $x$. But this is hidden if one choose too high value of $a$. One can understand why high $a$ gives a wrong impression that fitting higher orders seems to work because the "strange" part of the function is hidden. But this part continue to exist and disturbs the fitting calculus.

This answers to the comment: "What can I do with this question now? Should I close or delete or edit it? Fitting higher orders seems to have worked."

I suppose that one have to find a better physical model which accounts for the behaviour at low $x$.


Instead of the search for an experimental model one can try various empirical models (purely mathematical). Of course it is not as valuable as a physical model.

If the first point (at $x=0$) is kept out it seems that the power model is not bad. But one have to include in the equation a shift $a$ for $y$ and a shift $b$ for $x$.

enter image description here

The shift on the $y-$axis is small.

The shift on the $x-$axis is very important.

Surprisingly the power of the inverse function is larger than expected : around $5$ instead of $2$ or $3$.

This draw to think that this rather simple model might have few physical signifiance even with a good fitting result. Another hypothesis is that the origin for the distances measurements on $x-$ axis be not correct.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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