Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import math
- import scipy.optimize
- import numpy
- # Steinhart-Hart Equation
- # from https://en.wikipedia.org/wiki/Steinhart%E2%80%93Hart_equation
- def steinhart_hart(r,a,b,c) :
- ''' Steinhart-Hart Equation, as found on Wikipedia.
- r : resistance of a thermistor, measured in Ohms
- a,b,c : steinhart-hart coefficients [a] = 1/K
- returns : temperature in degrees celsius!
- '''
- one_over_kelvins = a + b*numpy.log(r) + c*numpy.log(r)**3
- return 1.0/one_over_kelvins - 273.15
- def main():
- exp_data = numpy.array([
- [ 1.9, 627.0e3 ], # Ice water
- [ 19.8, 255.1e3 ], # Room Temperature water
- [ 65.9, 37.0e3 ] # Hot water
- ])
- temps = exp_data[:,0]
- resist = exp_data[:,1]
- # give a ballpark estimate to start from, minimization might not
- # converge if we start off too far away...
- p0 = [0.1e-3, 0.1e-4, 0.1e-7]
- print('Experimental Data:')
- print('Temperatures [degC]:', temps)
- print('Resistances [Ohm] :', resist)
- par, cov = scipy.optimize.curve_fit(steinhart_hart, resist, temps, p0)
- print('A=',par[0])
- print('B=',par[1])
- print('C=',par[2])
- temps2 = steinhart_hart(resist, *par)
- print('Can we reproduce the measured temperatures?')
- print('Temperatures [degC]:', temps2)
- if __name__ == '__main__' :
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement