title: Is it possible to enforce bounds on the range/dependent function when using scipy curve_fit?
body: <p>I have a logarithmic function being fit to a set of points</p>
  
  <pre><code>def log_func(x, a, b):
      return a * np.log(x) + b
  popt, pcov = curve_fit(log_func, x, yn)
  </code></pre>
  
  <p>This results in a plot as follows - <a href="https://i.stack.imgur.com/VQ7ZN.png" rel="nofollow noreferrer">Plotted Curve</a></p>
  
  <p>However, the system has constraints that the range should be fixed between 0 and 100. I've specifically passed points at those bounds (i.e. <code>x = np.array([3200 ... other points ... 42000 ])</code> and <code>y = np.array([0 ... other points ... 100 ] )</code> but obviously the curve does not necessarily fix those values.</p>
  
  <p>I've read that I can add bounds to the parameters (so <code>a</code> and <code>b</code> here), but is there a way to constrain the output by specifically forcing the curve through two endpoints. Or alternatively, do I have to introduce some sort of extreme penalization to the function to result in parameters that will be force a result between 0 and 100?</p>