wwwowwweeee
wwwowwweeee

Reputation: 1

Lorentzian fit warnings.warn('Covariance of the parameters could not be estimated',

I'm trying to fit a lorentzian curve with the following equation: Lorentzian

import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
import numpy as np

# Fit a Lorentzian.
def duallorentz(x, x0, g, F,M) :
    return ( (F/M) /((x0**2 - x**2)**2 + (g*x)**2)**0.5) 
xdata = np.array([188.49, 191.63, 194.77, 196.66, 198.54, 200.43, 202.31 ,204.20,206.08,207.977,209.85])
ydata = np.array([0.0052, 0.0071, 0.0091, 0.0118,0.0152,0.225,0.228, 0.037, 0.017,0.012,0.009])

plt.plot(xdata, ydata, 'bo', label='experimental-data')

popt, pcov = curve_fit(duallorentz, xdata, ydata)
print(popt)

xFit = np.arange(0, 25)

plt.plot(xFit, duallorentz(xFit, *popt), 'r', label='fit params')

plt.xlabel('Frequency of the driven coupled oscillators.')
plt.ylabel('Amplitude of the driven coupled oscillators.')
plt.legend()
plt.title('Part II Data')

plt.show()

But it shows the message "warnings.warn('Covariance of the parameters could not be estimated',". What's wrong here?

Upvotes: 0

Views: 249

Answers (1)

ev-br
ev-br

Reputation: 26080

Since your fit function depends on the ratio F/M, it cannot estimate the covariance of F and M separately.

Upvotes: 0

Related Questions