curve_fit doesn't work properly with 4 parameters
<p>Running the following code, </p>

<pre><code>x = np.array([50.849937, 53.849937, 56.849937, 59.849937, 62.849937, 65.849937, 68.849937, 71.849937, 74.849937, 77.849937, 80.849937, 83.849937, 86.849937, 89.849937, 92.849937])
y = np.array([410.67800, 402.63800, 402.63800, 386.55800, 330.27600, 217.71400, 72.98990, 16.70860, 8.66833, 40.82920, 241.83400, 386.55800, 394.59800, 394.59800, 402.63800])
def f(om, a, i , c):
       return a - i*np.exp(- c* (om-74.)**2)
par, cov = curve_fit(f, x, y)
stdev = np.sqrt(np.diag(cov) )
</code></pre>

<p>produces this Graph,</p>

<p><a href="http://i.stack.imgur.com/0Dvop.png" rel="nofollow"><img src="http://i.stack.imgur.com/0Dvop.png" alt="enter image description here"></a></p>

<p>With the following parameters and standard deviation:</p>

<pre><code>par =   [ 4.09652163e+02, 4.33961227e+02, 1.58719772e-02]
stdev = [ 1.46309578e+01, 2.44878171e+01, 2.40474753e-03]
</code></pre>

<p>However, when trying to fit this data to the following function:</p>

<pre><code>def f(om, a, i , c, omo):
       return a - i*np.exp(- c* (om-omo)**2)
</code></pre>

<p>It doesn't work, it produces a standard deviation of </p>

<pre><code>stdev = [inf, inf, inf, inf, inf]
</code></pre>

<p>Is there any way to fix this?</p>

<p>You can calculate the initial condition from data:</p>

<pre><code>%matplotlib inline
import pylab as pl

import numpy as np
from scipy.optimize import curve_fit

x = np.array([50.849937, 53.849937, 56.849937, 59.849937, 62.849937, 65.849937, 68.849937, 71.849937, 74.849937, 77.849937, 80.849937, 83.849937, 86.849937, 89.849937, 92.849937])
y = np.array([410.67800, 402.63800, 402.63800, 386.55800, 330.27600, 217.71400, 72.98990, 16.70860, 8.66833, 40.82920, 241.83400, 386.55800, 394.59800, 394.59800, 402.63800])

def f(om, a, i , c, omo):
       return a - i*np.exp(- c* (om-omo)**2)

par, cov = curve_fit(f, x, y, p0=[y.max(), y.ptp(), 1, x[np.argmin(y)]])
stdev = np.sqrt(np.diag(cov) )

pl.plot(x, y, "o")
x2 = np.linspace(x.min(), x.max(), 100)
pl.plot(x2, f(x2, *par))
</code></pre>

python numpy matplotlib scipy curve-fitting