I am trying to fit our measured data of the viscosity of fluids with the andrade equation:
eta(T)=A*exp(b/T)
The problem is that our measurments errors are almost only in the x-direction. Thats why using curve_fit yields pretty bad results. For that reason I tried to use scipy ODR. But doing so yields the following:
Beta: [nan nan]
Beta Std Error: [0. 0.]
Beta Covariance: [[0. 0.]
[0. 0.]]
Residual Variance: 0.0
Inverse Condition #: 0.010405369378825816
Reason(s) for Halting:
Numerical error detected
c:UsersNils Huberanaconda3Libsite-packagesscipyodr_odrpack.py:394: RuntimeWarning: divide by zero encountered in divide
return 1./numpy.power(sd, 2)
I suppose it because the uncertainties are to small or because the function consists of an 1/x but the x values should be large enough for that to not be problem.
Here is the important part of my code:
Data from measurments:
pet_Ti = [300.15 316.5 331.25 345.8 353.15 343.3 337. 325.35 321.6 320.4
318.35 316.2 313.2 310.9 308.9 306.55 274.9 291.25 304.65 301.4
299.75 299.35 298.1 296.55 295.15 293.95 292.6 291.5 289.85 286.85
285.7 283.9 280.3 ]
pet_dynvis = [0.00135192 0.00100329 0.00086392 0.00072153 0.00064 0.00071678
0.00078402 0.00089695 0.00095471 0.00094642 0.00097903 0.00098607
0.00106022 0.00110484 0.00110248 0.00116256 0.00211384 0.00141347
0.00112535 0.00120344 0.00123174 0.0012284 0.00122092 0.00131004
0.00133253 0.00134795 0.00140059 0.00144983 0.00147594 0.00158999
0.00159174 0.0016704 0.0018222 ]
pet_dT = [0.38729833 2.83989436 5.12445119 7.04166174 7.1526219 2.3010867
0.46368092 1.15325626 0.41833001 0.23452079 0.24494897 0.23452079
0.23452079 0.23452079 0.23452079 0.26457513 1.90918831 0.
0.65574385 0.62048368 0.60827625 0.2236068 0.45276926 0.41231056
0.26457513 0.24494897 0.3082207 0.79056942 1.28840987 0.74161985
1.08397417 2.33773395 2.21020361]
pet_ddynvis = [8.42043077e-07 6.51836544e-07 5.83059780e-07 5.02409095e-07
4.71362716e-07 5.09201376e-07 5.44278635e-07 5.96485086e-07
6.29123988e-07 6.26551992e-07 6.47858967e-07 6.62144975e-07
6.94679317e-07 7.19763961e-07 7.17798323e-07 7.42372844e-07
1.28663178e-06 8.90186526e-07 7.42136729e-07 7.76387532e-07
7.87383198e-07 7.86220936e-07 7.91617783e-07 8.44122653e-07
8.43088524e-07 8.53521721e-07 8.81071755e-07 9.08348846e-07
9.25153220e-07 9.91918448e-07 9.94984530e-07 1.03639134e-06
1.12577314e-06]
I used the following code:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from pylab import *
from scipy.optimize import curve_fit
from scipy import odr
from IPython.display import display, Latex
from sympy import symbols, latex
from IPython.display import display, Math
import math
(…)
def afunc(A,x):
return A[0]*np.exp(A[1]/(x))
model=odr.Model(afunc)
pet_data = odr.RealData(pet_Ti,pet_dynvis,sx=pet_dT,sy=pet_ddynvis)
pet_odr = odr.ODR(pet_data, model,beta0=[1e-5,1400])
pet_out=pet_odr.run()
pet_out.pprint()
That produces this error:
thanks in advance 🙂
Nils Huber is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.