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)
- 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)
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)
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 )