title: fitting an inverse proportional function
body: <p>I want to fit the function <code>f(x) = b + a / x</code> to my data set. For that I found scipy <code>leastsquares</code> from optimize were suitable.</p>
  
  <p>My code is as follows: </p>
  
  <pre><code>x = np.asarray(range(20,401,20))
  </code></pre>
  
  <p><code>y</code> is distances that I calculated, but is an array of length 20, here is just random numbers for example</p>
  
  <pre><code>y = np.random.rand(20)
  </code></pre>
  
  <p>Initial guesses of the params a and b:</p>
  
  <pre><code>params = np.array([1,1])
  </code></pre>
  
  <p>Function to minimize</p>
  
  <pre><code>def funcinv(x):
      return params[0]/x+params[1]
  
  res = least_squares(funinv, params, args=(x, y))
  </code></pre>
  
  <p>Error given:</p>
  
  <pre><code> return np.atleast_1d(fun(x, *args, **kwargs))
  </code></pre>
  
  <blockquote>
    <p>TypeError: funinv() takes 1 positional argument but 3 were given</p>
  </blockquote>
  
  <p>How can I fit my data?</p>