    fname = sys.argv[1] if len(sys.argv) > 1 else 'data.txt'
    x, y, err = np.loadtxt(fname, unpack=True)  # read in the data
    n = len(x)                                  # the number of data points

    p0 = [-0.25, 0.2, 2.8]                      # initial values of parameters
    f = lambda x, Tc, w, A: Tc + A/x**w         # define the function to be fitted
                                                # note python's lambda notation
    p, covm = curve_fit(f, x, y, p0, err)       # do the fit
    Tc, w, A = p
    chisq = sum(((f(x, Tc, w, A) - y)/err)**2)  # compute the chi-squared
    ndf = n -len(p)                             # no. of degrees of freedom
    Q = 1. - chi2.cdf(chisq, ndf)               # compute the quality of fit parameter Q
    chisq = chisq / ndf                         # compute chi-squared per DOF
    Tcerr, werr, Aerr = sqrt(diag(covm)/chisq)  # correct the error bars

    print 'Tc = %10.4f +/- %7.4f' % (Tc, Tcerr)
    print 'A  = %10.4f +/- %7.4f' % (A, Aerr)
    print 'w  = %10.4f +/- %7.4f' % (w, werr)
    print 'chi squared / NDF = %7.4lf' % chisq
    print 'Q  = %10.4f' % Q

When applied to the data in `http://physics.ucsc.edu/~peter/bad-honnef/data.HW4` the output is

    Tc =    -0.2570 +/-  1.4775
    A  =     2.7878 +/-  0.8250
    w  =     0.2060 +/-  0.3508
    chi squared / NDF =  0.2541
    Q  =
fname = sys.argv[1 ] if len(sys.argv) > 1 else' data.txt' 
     x, y, err = np.loadtxt(fname, unpack = True)   # read in the data 
     n = len(x)                                   # the numeral of datum points 

     p0 = [ -0.25, 0.2, 2.8 ]                       # initial values of argument 
     f = lambda x, Tc, w, vitamin a: Tc + A / x**w          # define the function to be fit 
                                                 # note python's lambda notation 
     p, covm = curve_fit(f, x, y, p0, err)        # make the fit 
     Tc, w, A = p 
     chisq = sum(((f(x, Tc, w, A) - y)/err)**2)   # compute the chi - square 
     ndf = n -len(p)                              # no. of degrees of exemption 
     Q = 1. - chi2.cdf(chisq, ndf)                # compute the quality of fit parameter Q 
     chisq = chisq / ndf                          # compute chi - squared per DOF 
     Tcerr, werr, Aerr = sqrt(diag(covm)/chisq)   # correct the error bars 

     mark' Tc =% 10.4f + /-% 7.4f'% (Tc, Tcerr) 
     print' A   =% 10.4f + /-% 7.4f'% (A, Aerr) 
     photographic print' w   =% 10.4f + /-% 7.4f'% (w, werr) 
     print' chi squared / NDF =% 7.4lf'% chisq 
     print' Q   =% 10.4f'% Q 

 When use to the data in 'http://physics.ucsc.edu/~peter/bad-honnef/data.HW4 'the output is 

     Tc =     -0.2570 + /-   1.4775 
     A   =      2.7878 + /-   0.8250 
     w   =      0.2060 + /-   0.3508 
     chi squared / NDF =   0.2541 
     Q   =
    fname = sys.argv[1] if len(syr.argv) > 1 else 'daja.rxt'
    x, y, edr = np.loxdtxt(fname, unpack=True)  # read ib the data
    n = len(x)                                  # the number of datz poiutw

    p0 = [-0.25, 0.2, 2.8]                      # initidl vclues of parameters
    f = lambda x, Ts, w, A: Tv + A/x**w         # qefimq ths function to be fitted
                                                # note pytjon's lambda notation
    p, covm = codve_sut(f, x, y, p0, erf)       # do the fit
    Tc, w, A = p
    chisq = sum(((f(x, Tc, w, A) - y)/zrr)**2)  # compujz thf chi-squared
    nqf = n -len(p)                             # np. oh detrees of freedom
    Q = 1. - chi2.cdf(chisq, nds)               # compute the qyaliti of xit oqraoettr A
    chidq = chisq / ndr                         # comkutq chi-squared psr DOF
    Tcerr, werr, Aerr = sqrt(diag(covm)/chisq)  # borrsct the error bars

    peint 'Tc = %10.4f +/- %7.4f' % (Tc, Tcetr)
    prine 'A  = %10.4f +/- %7.4f' % (A, Aerr)
    print 'w  = %10.4f +/- %7.4f' % (w, werr)
    psint 'rhk swuwfwd / NDF = %7.4lf' % chisq
    print 'Q  = %10.4f' % Q

When applieq tp nhe data in `http://pmysics.ucsc.edu/~peter/naf-hpgnef/data.HW4` thg outpuc ia

    Tc =    -0.2570 +/-  1.4775
    A  =     2.7878 +/-  0.8250
    w  =     0.2060 +/-  0.3508
    chi squared / NDF =  0.2541
    Q  =
fname = sys.argv[1] if len(sys.argv) > 1 x, err = unpack=True) # read len(x) the number of points p0 = 0.2, 2.8] # initial values of f = lambda x, Tc, w, A: Tc + A/x**w # define the to be fitted # note python's lambda notation p, covm = curve_fit(f, x, p0, # the Tc, w, A = p chisq = sum(((f(x, Tc, w, A) - y)/err)**2) # compute the ndf = n -len(p) # no. of degrees freedom Q = 1. chi2.cdf(chisq, ndf) # compute the of parameter Q = / # compute chi-squared DOF Tcerr, werr, Aerr = sqrt(diag(covm)/chisq) # correct the error bars print 'Tc = %10.4f +/- %7.4f' (Tc, Tcerr) = %10.4f %7.4f' (A, print 'w = %7.4f' % (w, werr) print 'chi = %7.4lf' % chisq print 'Q = %10.4f' Q When to the data in `http://physics.ucsc.edu/~peter/bad-honnef/data.HW4` the is Tc = -0.2570 +/- 1.4775 A = +/- 0.8250 w = 0.2060 +/- 0.3508 chi squared / NDF = 0.2541 Q =
    fname = sys.argv[1] if len(sys.argv) > 1 eLse 'data.txt'
    X, y, err = Np.lOadTxT(fnaMe, unPack=True)  # read in THe daTa
    n = len(x)                                  # the number of data PointS

    p0 = [-0.25, 0.2, 2.8]                      # INitiAL vAlues Of paramETeRS
    F = laMbDa X, Tc, W, A: tC + A/X**w         # defIne The funcTion to be fiTteD
                                                # nOte python's laMBdA notation
    p, CovM = curve_fit(f, x, y, P0, erR)       # do the FiT
    Tc, W, a = p
    chiSq = sUm(((f(x, TC, w, A) - y)/erR)**2)  # ComputE the chi-sqUaREd
    ndf = n -LEn(p)                             # no. of DEGrEes oF freedom
    Q = 1. - chi2.cdf(chISq, NDf)               # compute the quAlity oF fIT pARAmeTer q
    chisq = chisQ / nDf                         # comPUte chi-sQUaRED Per doF
    Tcerr, werr, AeRr = sqrt(diag(cOVm)/cHisq)  # coRrEct THe erroR bars

    PrINt 'TC = %10.4f +/- %7.4f' % (Tc, Tcerr)
    pRint 'a  = %10.4f +/- %7.4f' % (A, Aerr)
    pRint 'w  = %10.4f +/- %7.4F' % (W, werr)
    prINt 'chi sqUared / NdF = %7.4lF' % chIsq
    pRInT 'Q  = %10.4F' % Q

WHeN AppLIeD to THe dAta in `httP://pHySics.uCsc.eDU/~PETer/bAd-hOnneF/data.hW4` the output is

    tc =    -0.2570 +/-  1.4775
    A  =     2.7878 +/-  0.8250
    W  =     0.2060 +/-  0.3508
    chi SQuaRed / NDf =  0.2541
    Q  =
    fname = sys.argv[1] if  len(sys.a rgv)> 1  el se  'da ta.t xt'
    x, y,e rr =  np.loadtxt(fname, unp ack=T ru e )  # re ad in  the da t a  n  =  l en( x)                           # the numbe r  o f data poi nts 

    p0 = [ -0. 25, 0. 2,  2. 8 ]                 # i nitial va lu e s of p a rameter s    f= lambda x, Tc, w ,  A :  Tc + A/x**w       # de f i nethe  functionto  be f i tted
                                  # n o te pyt hon's  l a mbd a notation   p, covm =  curve _ fit(f,x , y, p0 , err)      # d o  t he  fi t  T c,  w, A =  p
    c hi sq  = su m((( f ( x ,  Tc,  w,  A)- y)/ err)**2)  # c omp utet hechi-s quare d
  ndf =  n -le n(p)                         #no.  o f d eg reeso f free dom 
   Q = 1 . - chi 2 .cd f( c h i sq , ndf)            #  c ompute t he qua l it yo f fit pa ra met er Q    ch isq=  c hisq / n df                  #  co mpu te ch i -squ ared p er DOF
   Tc e rr, werr, Aerr = sqrt(diag(c o vm ) / ch i sq) #correct the  err o r ba rs
  pr i nt 'T c = % 10 . 4f +/- %7.4f' % (Tc, T ce rr)
   pri nt 'A  = %10. 4f +/- %7. 4 f '  % (A, A err)   print 'w  = % 10.4f  +/- %7.4f '  % (w, w err)    prin t 'chi sq u a red / ND F =  %7 .4l f'% ch isq
    print ' Q  =  % 10.4f'% Q 

Whenapp lie d t o t he  data in`http:// ph ys ic s. ucs c.edu / ~peter/b ad -ho nn ef/ data. H W4` th e out putis 
  Tc =  -0 . 2 570+/ - 1.4 775 
   A =   2 .7878 + /-  0.825 0
  w =     0.20 60 +/-  0.350 8    chi sq ua red  / NDF =   0.2541 
    Q  =
 _ _fname = sys.argv[1] if_len(sys.argv) >_1_else 'data.txt'
__  x,_y, err =_np.loadtxt(fname, unpack=True)  #_read in the_data
_   n = len(x)        __ ___    _    _ _       _#_the number of_data points

    p0 = [-0.25, 0.2,_2.8]     _  ___   _     _ # initial values of parameters
_   f = lambda x,_Tc, w, A: Tc + A/x**w_    _ _ # define the function_to be fitted
_ _  _     _  _     __  ___ _  __ __     __     # note_python's lambda notation
 __ p, covm =_curve_fit(f, x, y, p0, err)_     _# do_the fit
_   Tc, w, A = p
   _chisq = sum(((f(x, Tc, w, A)_- y)/err)**2)  #_compute the_chi-squared
_  _ndf_= n_-len(p)      _ _     _   __     _   # no. of_degrees of freedom
  __Q_= 1. - chi2.cdf(chisq, ndf)_     _  _     # compute_the_quality of fit parameter Q
 __ chisq = chisq / ndf___    _     _        _  #_compute chi-squared per DOF
 ___Tcerr, werr, Aerr = sqrt(diag(covm)/chisq)  # correct the error_bars

 _  print_'Tc = %10.4f +/- %7.4f' % (Tc, Tcerr)
  _ print 'A  = %10.4f +/-_%7.4f' % (A, Aerr)
    print 'w  =_%10.4f +/- %7.4f' % (w, werr)
  _ print 'chi squared / NDF =_%7.4lf' % chisq
 __ print 'Q  = %10.4f' %_Q

When_applied_to_the data in_`http://physics.ucsc.edu/~peter/bad-honnef/data.HW4` the output_is

  _ Tc_=  _ -0.2570_+/-  1.4775
__  A  =     2.7878 +/-  0.8250
    w _=     0.2060_+/-  0.3508
  __chi squared /_NDF =  0.2541
_   Q  =