import numpy as numpy import math from astropy.io import ascii from BayesicFitting import ExpModel from BayesicFitting import PolynomialModel from BayesicFitting import LevenbergMarquardtFitter from BayesicFitting import formatter as fmt from BayesicFitting import plotFit from BayesicFitting import Tools import matplotlib.pyplot as plt
#%matplotlib osx
x = [ 0, 0.2, 0.4, 0.6, 0.8, 1.0] y = [955, 634, 513, 411, 317, 280]
plt.plot( x, y, 'k.' ) plt.show()
model = ExpModel() + PolynomialModel( 0 ) model.parameters = [700, -10, 200] ftr = LevenbergMarquardtFitter( x, model ) par = ftr.fit( y ) print( par )
[718.53092773 -2.46766391 226.80115419]
plt.plot( x, y, 'k.' ) xx = numpy.linspace( 0.0, 1.0, 101 ) yy = model( xx ) plt.plot( xx, yy, 'b-') plt.xlabel( 'tea fraction' ) plt.ylabel( 'transparency' ) plt.title( 'measured data and exponential fit' ) plt.show()