# import the toolbox and call it B import LT.box as B import numpy as np # the data t = np.array([ 0. , 0.2, 0.4, 0.6, 0.8, 1. , 1.2, 1.4, 1.6, 1.8, 2. ]) counts = np.array([ 1235., 665., 369., 221., 165., 108., 79., 77., 67., 56., 46.]) sigma = np.array([ 34.64101615, 24.92931125, 18.70989477, 14.77306954, 12.26884392, 10.62021419, 9.46275219, 8.58402083, 7.8676807 , 7.25221607, 6.7053333 ]) # now the parameters a1 = B.Parameter( 1000., 'A1') a2 = B.Parameter( 100., 'A2') lam1 = B.Parameter( 3., 'lambda1') lam2 = B.Parameter( 1., 'lambda2') # now the fit function, not the indentation def f(x): return ( a1() * np.exp(-lam1()*x) + a2() * np.exp(-lam2()*x) ) # end of the fit function # carry out the fit F = B.genfit(f, [a1, lam1, a2, lam2], x = t, y = counts, y_err = sigma) B.plot_exp(t, counts, sigma, logy = 'True', x_label = 't (s)', y_label = 'Counts', plot_title = 'Radioactive Decay with 2 time constants') # use a logarithmic scale ! B.plot_line(F.xpl, F.ypl) # show everything B.pl.show()