title: Why is optimize curve fit in scipy creating a straight line for this non linear model?
body: <p>I'm trying to fit some data that i have to a model that is inversely proportional to x to some power.  I've looked through a few similar threads and I think the problem might have to do with scaling my data but I've experimented with that and had no success unfortunately.</p>
  
  <pre><code>import numpy as np
  import scipy.optimize as optimize
  import matplotlib.pyplot as plt
  
  x = np.array([367.18,411.42,443.76,565.22,689.31,778.94,867.38,963.98,1085.79,1112.01,1212.47,1299.21,1408.08,1458.8,1528.76])
  y = np.array([17.21,13.38,9.41,11.40,6.40,6.62,6.11,5.50,5.03,4.52,2.34,3.62,3.84,5.97,1.97])
  
  def f(a,n,x1):
      return (a*np.power(x1,-n));
  
  popt, pcov = optimize.curve_fit(f,x,y, diag=(1./x.mean(),1./y.mean()))
  x1 = np.linspace(0,1700,num =1700)
  plt.plot(x1, f(x1, *popt))
  plt.plot(x,y,'ro')
  plt.show()
  print(popt, pcov)
  </code></pre>
  
  <p>The result is this:
  <a href="https://i.stack.imgur.com/ZTdZY.png" rel="nofollow noreferrer">Plot</a></p>