title: Error in nonlinear least square fit of sine function with exponential decay
body: <p>My nonlinear data are approximated using a least square fit with the formula <code>Asin(wt+phase)exp(-decay*t)</code> while keeping <code>omega(w)</code> as a constant. I have tried several approaches without success.</p>
  <p>Below is my code</p>
  <pre><code>import numpy as np
  from numpy import loadtxt
  import lmfit
  np.random.seed(2)
  x = np.linspace(0, 10, 101)
  decay = 4.5
  shift = 0
  amp = 0.0015
  y = amp * np.sin(x*5+shift) * np.exp(-x*decay)
  yn = y + np.random.normal(size=y.size, scale=0.450)
  
  
  def resid(params, x, ydata):
      decay = params['decay'].value
      shift = params['shift'].value
      amp = params['amp'].value
  
      y_model = amp * np.sin(x*5+shift) * np.exp(-x*decay)
      return y_model - ydata
  params = lmfit.Parameters()
  params.add('shift', 0.0, min=-np.pi, max=np.pi)
  params.add('amp', 0.0015, min=0, max=0.02)
  params.add('decay', 4.0, min=0, max=10.0)
  fit = lmfit.minimize(resid, params, args=(x, yn), method='differential_evolution')
  print(&quot;\n\n# Fit using differential_evolution:&quot;)
  lmfit.report_fit(fit)
  plt.plot(x, y, 'ko', lw=2)
  plt.plot(x, yn+fit.residual, 'b--', lw=2)
  plt.legend(['data', 'leastsq', 'diffev'], loc='upper left')
  plt.show()
  </code></pre>