title: python curve_fit doesn't work with stiff model
body: <p>I am trying to find the <code>x0</code>parameter which fits as much as possible the blue model on the green curve (<code>x0</code>control the width of the crenel; see below).</p>
  
  <p><a href="https://i.stack.imgur.com/D8C8u.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D8C8u.png" alt="enter image description here"></a></p>
  
  <p>Here is my attempt:</p>
  
  <pre><code>from pylab import *
  from scipy.optimize import curve_fit
  
  x=linspace(0,2*pi,1000)    
  def crenel(x):return sign(sin(x))
  def inverter(x,x0): return (crenel(x-x0)+crenel(x+x0))/2
  
  p,e = curve_fit(inverter,x,sin(x),1)    
  plot(x,inverter(x,*p),x,sin(x))
  ylim(-1.5,1.5)
  </code></pre>
  
  <p>By hand, the optimal value is <code>x0 = arcsin(1/2) # 0.523598</code>, but curve_fit doesn't estimate any value ( <em>"OptimizeWarning: Covariance of the parameters could not be estimated"</em>) . I suspect the stiffness of the model. The <a href="http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.optimize.curve_fit.html" rel="nofollow noreferrer">docs</a> inform :</p>
  
  <blockquote>
    <p>The algorithm uses the Levenberg-Marquardt algorithm through leastsq. Additional keyword arguments are passed directly to that algorithm. </p>
  </blockquote>
  
  <p>So my question is : Is there keyword arguments that can help <code>curve_fit</code> to estimate the parameter in this case ? or another approach ?</p>
  
  <p>Thanks for any advice.  </p>