def test_get_quadratic_fit(self): """get quadratic fit""" lf = LinCurveFit( self.myds, ['const', 'x', 'x**2'], fit_best_pcent=0) val = lf.cArr[0] refVal = 17.116 self.assertAlmostEqual(val, refVal) val = lf.cArr[1] refVal = -7.7477857 self.assertAlmostEqual(val, refVal) val = lf.cArr[2] refVal = 0.8353571428 self.assertAlmostEqual(val, refVal) yArr = lf.eval_xrange( array([1.0, 2.0]) ) refVal = 4.9618571428571432 self.assertAlmostEqual(yArr[1], refVal)
def test_get_linear_fit(self): """get linear fit""" lf = LinCurveFit( self.myds, ['const', 'x'], fit_best_pcent=0) val = lf.cArr[0] refVal = 9.3193333333333399 self.assertAlmostEqual(val, refVal) val = lf.cArr[1] refVal = -1.9002857142857148 self.assertAlmostEqual(val, refVal)
def test_get_fit_for_constant(self): """get LinCurveFit for constant""" lf = LinCurveFit( self.myds, ['const'], fit_best_pcent=0) val = lf.cArr[0] refVal = 2.6683333333333348 self.assertAlmostEqual(val, refVal)
from matplotlib import pyplot as plt got_plt = True except: got_plt = False from xymath.dataset import DataSet from xymath.linfit import LinCurveFit concL = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1] readingL = [1.54,2.03,3.17,3.67,4.89,6.73,6.74,7.87,8.86,10.35] DS = DataSet(concL, readingL, xName='Concentration', yName='Instrument Reading') print('\n\n') print('='*55) print(".... First show author's answer ....") Fit_ref = LinCurveFit(DS, xtranL=['const', 'x'] , ytran='y', cArrInp=[0.199, 9.7926], fit_best_pcent=0) # 0=fit best total error print(Fit_ref.get_full_description()) print('='*55) print('.... Then show XYmath answer ....') Fit_linear = LinCurveFit(DS, xtranL=['const', 'x'] , ytran='y', fit_best_pcent=0) # 0=fit best total error print(Fit_linear.get_full_description()) print('='*55) print('.... Then show XYmath Quadratic answer ....') v2_concL = [0.1, 0.2, 0.3, 0.4, 0.5, 0.7, 0.8, 0.9, 1] v2_readingL = [1.54,2.03,3.17,3.67,4.89,6.74,7.87,8.86,10.35] DS = DataSet(v2_concL, v2_readingL, xName='Concentration', yName='Instrument Reading')