I am trying to fit (using scipy.optimize.curve_fit) using mpmath.polylog.
For this I have defined the following function
def Vendik(x, C, T0, eps_cst, Td, xsi):
integral = (np.pi**2)/6. + (Td/x) * np.log(1-np.cosh(Td/x)+np.sinh(Td/x)) - polylog(2, np.exp(-Td/x))
eta = ( Td/ (2*T0) ) * ( 0.5 + 2./(Td/x)**2 * integral) -1
term1 = np.sqrt( xsi**2 + eta**3 ) + xsi
term2 = np.sqrt( xsi**2 + eta**3 ) - xsi
return eps_cst + (C*1e4/T0) / ( term1**(2./3.) + term2**(2./3.) - eta )
The data I want to fit are in a pandas DataFrame, and I carry out the fit with
xdata = data1['T(K)']
ydata = data1['epsr_STO’]
p1 = np.array([5.769, 13.16, 66.7, 86.5, 0.667])
popt_Vendik, pcov_Vendik = curve_fit(Vendik, xdata, ydata, p1)
This gives me an error:
File /opt/anaconda3/lib/python3.9/site-packages/mpmath/ctx_mp.py:634 in _convert_fallback
raise TypeError("cannot create mpf from " + repr(x))
whereas if I try res= [Vendik(data1['T(K)'][i], 5.769, 13.16, 66.7, 86.5, 0.667) for i in range(len(data1))]
I do not get such an error message. Therefore, the Vendik
function works with these data. I have defined other fitting functions (not relying on mpmath
), and the fit works seamlessly with the same data.
I have tried to transform my xdata
and ydata
into np.array()
and list
but the error message persists.
Would someone have a suggestion as to what I should modify to carry out my fit, I’d very much appreciate it.
Below are the first 100 values for xdata=data1[’T(K)’]
and ydata=data1[‘epsr_STO’]
respectively
data = [6.1727, 6.5735, 6.8074, 7.1052, 7.333, 7.6286, 7.8439, 8.1311, 8.3964, 8.6278, 8.887, 9.1358, 9.3781, 9.6301, 9.8589, 10.0725, 10.3733, 10.6386, 10.8744, 11.1192, 11.373, 11.6233, 11.8729, 12.1353, 12.3567, 12.6395, 12.8974, 13.1583, 13.4392, 13.67, 13.9283, 14.2244, 14.4684, 14.7365, 14.9683, 15.2161, 15.4826, 15.7594, 16.0293, 16.2869, 16.5325, 16.7837, 17.0395, 17.2937, 17.5569, 17.8181, 18.0474, 18.3436, 18.6019, 18.854, 19.083, 19.3497, 19.6359, 19.8911, 20.1694, 20.4052, 20.707, 20.9671, 21.2323, 21.483, 21.7547, 21.9903, 22.2897, 22.5568, 22.818, 23.0883, 23.3466, 23.6158, 23.8702, 24.1274, 24.3925, 24.6567, 24.9204, 25.1985, 25.516, 25.8149, 26.1764, 26.4486, 26.7175, 26.9845, 27.2523, 27.5219, 27.7737, 28.0813, 28.3641, 28.6534, 28.9295, 29.2104, 29.487, 29.7602, 30.0334, 30.3026, 30.5742, 30.8446, 31.1174, 31.3826, 31.6518, 31.9262, 32.1889, 32.4566]
ydata = [2326.1750294600747, 2325.5381972187943, 2324.851474894096, 2323.94171454941, 2322.861740978944, 2321.6144888934873, 2320.3466938325055, 2318.530107853923, 2316.684174767447, 2314.8910664751784, 2312.634273878199, 2310.3070482222765, 2307.8683035563604, 2305.2153250028246, 2302.5828894248134, 2299.7303505376044, 2296.4552132967347, 2293.2710520903333, 2290.2629735312908, 2287.298915634088, 2284.3465965800424, 2281.538078354673, 2278.864556825612, 2276.164622899447, 2273.4881666595966, 2270.7324732284346, 2267.6363533457125, 2263.7684045254023, 2259.1843862725004, 2254.039838258841, 2248.2584580039006, 2241.75513889479, 2234.585640436506, 2227.9385204987193, 2221.085970805681, 2213.716912013724, 2205.549611887075, 2196.3845100920607, 2187.407229787562, 2178.6177709735794, 2169.8312468703857, 2160.739512845104, 2151.4364796429923, 2141.9514943719428, 2132.117278516966, 2122.021873401741, 2111.671148447845, 2101.2646639889526, 2091.2543654866167, 2081.082657890869, 2070.488351941461, 2059.5976402023325, 2048.9710524342418, 2038.0245811901161, 2026.822790107321, 2015.6943667942583, 2004.2343211620039, 1993.1939391726203, 1982.326705119806, 1971.2481718901618, 1959.9788824592122, 1948.5159021161685, 1937.24074326364, 1925.871673665854, 1914.5701024162224, 1903.077774965285, 1891.459254950408, 1880.1077936173576, 1868.9353496424553, 1858.0798544327986, 1846.998386492365, 1835.7349664829937, 1824.4891547383586, 1813.1729099347804, 1800.4744163494368, 1787.1801764738636, 1774.0796275103846, 1762.5286058436618, 1751.781694933209, 1741.093478238543, 1730.422869808613, 1719.7845431973649, 1708.8380719532395, 1697.645085002812, 1686.114606311614, 1674.760210267774, 1663.4058142239346, 1652.2186966950858, 1641.0139709015014, 1630.038152549483, 1619.0183135356244, 1608.0454298943953, 1597.210477660264, 1586.3755254261318, 1575.6755698883085, 1564.9403978210134, 1554.307940631344, 1543.6608098877282, 1533.1926965022603, 1522.6952360088992]