Ejemplo n.º 1
0
print("=" * 55)
print("..........Total Error............")
print(CFit_toterr.get_full_description())
print("=" * 55)
print("..........Percent Error............")
CFit_pcterr = NonLinCurveFit(
    DS, rhs_eqnStr="A*(c - d*x)**n", constDinp=guessD, fit_best_pcent=1
)  # 1=fit best percent error
print(CFit_pcterr.get_full_description())
print("=" * 55)

# To set parameters to reference values from www.engineeringtoolbox.com do this:
print("..........Reference Curve Fit............")
CFit_ref = NonLinCurveFit(DS, rhs_eqnStr="A*(c - d*x)**n", constDinp=guessD)
CFit_ref.constD.update({"A": 101325, "c": 1, "d": 2.25577e-5, "n": 5.25588})
CFit_ref.calc_std_values()
print(CFit_ref.get_full_description())

if got_plt:
    plt.plot(alt_mArr, PaArr, "o", markersize=10)
    xPlotArr, yPlotArr = CFit_ref.get_xy_plot_arrays(Npoints=100, logScale=False)
    plt.plot(xPlotArr, yPlotArr, "--", linewidth=5, label="Reference")
    xPlotArr, yPlotArr = CFit_toterr.get_xy_plot_arrays(Npoints=100, logScale=False)
    plt.plot(xPlotArr, yPlotArr, "-", label="Total Error", linewidth=3)
    xPlotArr, yPlotArr = CFit_pcterr.get_xy_plot_arrays(Npoints=100, logScale=False)
    plt.plot(xPlotArr, yPlotArr, "-", label="Percent Error")
    plt.title("Atmospheric Pressure")
    plt.legend()
    plt.show()
Ejemplo n.º 2
0
print('=' * 55)
print('..........Percent Error............')
CFit_pcterr = NonLinCurveFit(DS,
                             rhs_eqnStr='A*(c - d*x)**n',
                             constDinp=guessD,
                             fit_best_pcent=1)  # 1=fit best percent error
print(CFit_pcterr.get_full_description())
print('=' * 55)

# To set parameters to reference values from www.engineeringtoolbox.com do this:
print('..........Reference Curve Fit............')
CFit_ref = NonLinCurveFit(DS, rhs_eqnStr='A*(c - d*x)**n', constDinp=guessD)
CFit_ref.constD.update({'A': 101325, 'c': 1, 'd': 2.25577E-5, 'n': 5.25588})
CFit_ref.calc_std_values()
print(CFit_ref.get_full_description())

if got_plt:
    plt.plot(alt_mArr, PaArr, 'o', markersize=10)
    xPlotArr, yPlotArr = CFit_ref.get_xy_plot_arrays(Npoints=100,
                                                     logScale=False)
    plt.plot(xPlotArr, yPlotArr, '--', linewidth=5, label='Reference')
    xPlotArr, yPlotArr = CFit_toterr.get_xy_plot_arrays(Npoints=100,
                                                        logScale=False)
    plt.plot(xPlotArr, yPlotArr, '-', label='Total Error', linewidth=3)
    xPlotArr, yPlotArr = CFit_pcterr.get_xy_plot_arrays(Npoints=100,
                                                        logScale=False)
    plt.plot(xPlotArr, yPlotArr, '-', label='Percent Error')
    plt.title('Atmospheric Pressure')
    plt.legend()
    plt.show()
Ejemplo n.º 3
0
    got_plt = True
except:
    got_plt = False
    
from numpy import array
from xymath.dataset import DataSet
from xymath.nonlinfit import NonLinCurveFit

xdata = array([-2,-1.64,-1.33,-0.7,0,0.45,1.2,1.64,2.32,2.9])
ydata = array([0.699369,0.700462,0.695354,1.03905,1.97389,2.41143,
               1.91091,0.919576,-0.730975,-1.42001])
DS = DataSet(xdata, ydata, xName='x', yName='y')

guessD = {'p1':1.0, 'p2':0.2}
CFit = NonLinCurveFit(DS, rhs_eqnStr='p1*cos(p2*x) + p2*sin(p1*x)', 
                      constDinp=guessD, fit_best_pcent=0)   # 0=fit best total error

print( 'residuals from XYmath = %g'%sum( (CFit.eval_xrange( xdata ) - ydata)**2 ) )
print( 'residuals from author = 0.053812696547933969' )
print('')
print(CFit.get_full_description())

if got_plt:
    plt.plot( xdata, ydata, 'o', markersize=10  )
    xPlotArr, yPlotArr = CFit.get_xy_plot_arrays( Npoints=100, logScale=False)
    plt.plot( xPlotArr, yPlotArr )
    plt.title('Trig Function: p1*cos(p2*x) + p2*sin(p1*x)')
    plt.show()