Question: The code below will generate some locatons, x 1 , data points, data 1 , and error on the data, sigma 1 . Using this

The code below will generate some locatons, x1, data points, data1, and error on the data, sigma1.
Using this data, answer the following questions:
a) If you ignore the error and do a linear fit, what value of m and b do you get? What are the errors on each of these values?
b) If you include the errors, what values of m and b do you get? What are the errors on these values? How close are these values to the ones used to create the data (m =2, b =4)? Are the fitted values within 1-sigma of the real values?
c) Notice that the formula used to make the data also has an x^2 term. If you fit the data with a degree-2 polynomial, what values of the 3 parameters do you get, and what is the error on each parameter? Are these values consistent with the values used to make the data?
d) By using a degree-2 polynomial in part c, how much better is the fit than in part b)? You can determine this by comparing the calues of . Is using the additional parameter reasonable when you compare the reduced ? Below is code to generate some data we saw in class, for a sin function plus some noise. In class we saw a decent fit to this, using:
p=[1.,18.,0.] # initial guess bounds =[[0,0,0],[np.inf,np.inf,2*np.pi]] # bounds on parameters popt,pcov = optimize.curve_fit(sin_fit,x,y,p,sigma=sigma,bounds=bounds,absolute_sigma=True,method='dogbox')
However, we can also make the fitting fail.
a) Try changing the initial guess to something else, say
p=[1.,8.,0.]
and rerun the fitting. What happens? Does this look like a good fit? Try changing your initial guess a few times to see roughly how close your guess has to be to get a good fit. Why does the fitting fail?
b) How about if you try different methods for finding the best fit, i.e.'lm','trf', 'dogbox'? (For 'lm', you'll need to take out the 'bounds' option.) Do some methods find a good fit over a wide range than others?
c) The optimize.minimize function has a wide range of methods available. First, write a new function that can be fed to optimize.minimize to find the best fit for this data. It should return the weighted for the parameters passed to it.
d) Now use optimize.minimize on the function you wrote in part c). Try out a few different methods with some 'bad' guesses. Do any methods produce a good fit even with a bad initial guess? You have some substance you suspect is radioactive. With a Geiger counter, you record the following counts in 1 second intervals spaced 1 minute apart:
time (minutes): [0.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.] counts (per second): [131901005573555858473734364332302825172520203023272211219101821]
a) Fit a reasonable function (An expoential decay) to this data, using curve_fit. Assume the error (sigma) on each measurement is 1 count) What is the decay constant of your substance? What are the errors on this parameter?
b) You should also be able to fit this data by making a change of coordinates, and then fitting a line to the new data. Do this. What decay constant do you get, and what are the errors? Is this consistent with your fit from part a)?
c) Really, the count data will have poisson errors. Assuming the counts were measured in a single 1-second time interval, the error (sigma) will be the square root of the number of counts. Using this, try using curve_fit again and see what you get for the decay constant ant error on this parameter.
d) To make you fit better, keep in mind there are probably some background counts as well (from cosmic rays, electronic noise in your instrument, etc.). Try fitting again using and exponential decay plus a constant (3 parameters) with and without assuming Poisson noise. How do these results compare to the values in part a) and c)?
The code below will generate some locatons, x 1 ,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!