4) Select "y = c0 + c1*x" to duplicate the author's results 5) Go to "Data" Tab 6) Select "weight" of data point with concentration=0.6 - Set that weight to 0.0 7) Go back to "Simple Fit" Tab and hit "Curve Fit" - Notice that the zero-weighted point is marked as such on the plot - As the author predicts, the fit is greatly improved - Surprisingly, XYmath shows the 3 term equation "y = c0 + c1*x + c2/x" to be superior to the 4 term equations as well as the quadratic. """ from numpy import array from xymath.dataset import DataSet from xymath.linfit import LinCurveFit from xymath.xy_job import XY_Job from xymath.gui.xygui import main as run_gui 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) XY = XY_Job() XY.define_dataset(concL, readingL, wtArr=None, xName='Concentration', yName='Instrument Reading', xUnits='', yUnits='') run_gui( XY )
alt_mArr = array([ -1524, -1372, -1219, -1067, -914, -762, -610, -457, -305, -152, 0, 152, 305, 457, 610, 762, 914, 1067, 1219, 1372, 1524, 1829, 2134, 2438, 2743, 3048, 4572, 6096, 7620, 9144, 10668, 12192, 13716, 15240 ], dtype=double) PaArr = 1000.0 * array([ 121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99.5, 97.7, 96, 94.2, 92.5, 90.8, 89.1, 87.5, 85.9, 84.3, 81.2, 78.2, 75.3, 72.4, 69.7, 57.2, 46.6, 37.6, 30.1, 23.8, 18.7, 14.5, 11.1 ], dtype=double) XY.define_dataset(alt_mArr, PaArr, wtArr=None, xName='altitude', yName='Pressure', xUnits='m', yUnits='Pa') guessD = {'A': 100000, 'c': 1, 'd': 0.00001, 'n': 4} XY.fit_dataset_to_nonlinear_eqn(run_best_pcent=0, rhs_eqnStr='A*(c - d*x)**n', constDinp=guessD) run_gui(XY)
cd_050 = 1/(1.0410141095741985 - 0.018737945262767248*gamma) # Rup=0.75, std=1.28366e-05 cd_075 = 1/(1.0211820293860214 - 0.006064881097850447*gamma) # Rup=1, std=1.01453e-05 cd_100 = 1/(1.0125848593169495 - 0.002058029259787154*gamma) # Rup=1.5, std=4.85485e-06 cd_150 = 1/(1.0059285328940355 - 0.00011367842090816805/gamma) # Rup=2, std=1.52664e-07 cd_200 = 0.9957021782441166 + 0.0006720167698767546/gamma """ gammaL = [1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4] cdD = {} # index=RWTU, value=CD cdD[0.5] = [0.9800142, 0.9809054, 0.981803, 0.9827062, 0.9836141, 0.9845261, 0.9854414] cdD[0.75] = [0.9857159, 0.9859911, 0.9862749, 0.9865668, 0.9868662, 0.9871727, 0.9874859] cdD[1] = [0.9897993, 0.989885, 0.989977, 0.9900752, 0.9901793, 0.990289, 0.990404] cdD[1.5] = [0.9942151, 0.9942037, 0.9941956, 0.9941907, 0.9941889, 0.99419, 0.9941941] cdD[2] = [0.9963129, 0.9962867, 0.9962624, 0.9962398, 0.996219, 0.9961998, 0.9961823] RupL = sorted( list( cdD.keys() ) ) for Rup in RupL: job = XY_Job() yL = cdD[Rup] job.define_dataset( gammaL, yL, xName='gamma', yName='Cd') ordered_resultL = job.fit_dataset_to_common_eqns( run_both=1, sort_by_pcent=1, max_terms=2) print('# Rup=%g, std=%g'%(Rup, job.linfit.std)) print( 'cd_%s = '%(str(int(100*Rup)).zfill(3),), job.linfit.get_eqn_str_w_numbs() )
He makes an initial guess of p1=1 and p2=0.2 and gets an answer of: p1 = 1.88184732 p2 = 0.70022901 With no initial guess, XYmath gets: p1 = 1.88185084847 p2 = 0.70022981688 1) Launch XYmath with code below 2) Go to "Non-Linear Fit" Tab - should see "p1*cos(p2*x) + p2*sin(p1*x)" in eqn box 3) Hit "Curve Fit" 4) See what happens when you hit "Improve Fit" a few times 5) Change to "Percent Error" and notice changes """ from xymath.xy_job import XY_Job from xymath.gui.xygui import main as run_gui XY = XY_Job() xdata = [-2, -1.64, -1.33, -0.7, 0, 0.45, 1.2, 1.64, 2.32, 2.9] ydata = [0.699369, 0.700462, 0.695354, 1.03905, 1.97389, 2.41143, 1.91091, 0.919576, -0.730975, -1.42001] XY.define_dataset(xdata, ydata, wtArr=None, xName="x", yName="y", xUnits="", yUnits="") XY.fit_dataset_to_nonlinear_eqn(run_best_pcent=0, rhs_eqnStr="p1*cos(p2*x) + p2*sin(p1*x)") run_gui(XY)
- should see "p1*cos(p2*x) + p2*sin(p1*x)" in eqn box 3) Hit "Curve Fit" 4) See what happens when you hit "Improve Fit" a few times 5) Change to "Percent Error" and notice changes """ from xymath.xy_job import XY_Job from xymath.gui.xygui import main as run_gui XY = XY_Job() xdata = [-2, -1.64, -1.33, -0.7, 0, 0.45, 1.2, 1.64, 2.32, 2.9] ydata = [ 0.699369, 0.700462, 0.695354, 1.03905, 1.97389, 2.41143, 1.91091, 0.919576, -0.730975, -1.42001 ] XY.define_dataset(xdata, ydata, wtArr=None, xName='x', yName='y', xUnits='', yUnits='') XY.fit_dataset_to_nonlinear_eqn(run_best_pcent=0, rhs_eqnStr='p1*cos(p2*x) + p2*sin(p1*x)') run_gui(XY)
y = Pressure (Pa) Correlation Coefficient = 0.999996135864 Standard Deviation = 88.761441745 Percent Standard Deviation = 0.094401748723% """ from numpy import array, double from xymath.xy_job import XY_Job from xymath.gui.xygui import main as run_gui XY = XY_Job() alt_mArr = array([-1524,-1372,-1219,-1067,-914,-762,-610,-457,-305,-152,0,152, 305,457,610,762,914,1067,1219,1372,1524,1829,2134,2438,2743,3048,4572, 6096,7620,9144,10668,12192,13716,15240], dtype=double) PaArr = 1000.0 * array([121,119,117,115,113,111,109,107,105,103,101,99.5,97.7,96, 94.2,92.5,90.8,89.1,87.5,85.9,84.3,81.2,78.2,75.3,72.4,69.7,57.2,46.6,37.6, 30.1,23.8,18.7,14.5,11.1], dtype=double) XY.define_dataset(alt_mArr, PaArr, wtArr=None, xName='altitude', yName='Pressure', xUnits='m', yUnits='Pa') guessD = {'A':100000, 'c':1, 'd':0.00001, 'n':4 } XY.fit_dataset_to_nonlinear_eqn(run_best_pcent=0, rhs_eqnStr='A*(c - d*x)**n', constDinp=guessD) run_gui( XY )
- Surprisingly, XYmath shows the 3 term equation "y = c0 + c1*x + c2/x" to be superior to the 4 term equations as well as the quadratic. """ from numpy import array from xymath.dataset import DataSet from xymath.linfit import LinCurveFit from xymath.xy_job import XY_Job from xymath.gui.xygui import main as run_gui 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) XY = XY_Job() XY.define_dataset(concL, readingL, wtArr=None, xName='Concentration', yName='Instrument Reading', xUnits='', yUnits='') run_gui(XY)