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, x data points, data and error on the data, sigma
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 b Are the fitted values within sigma of the real values?
c Notice that the formula used to make the data also has an x term. If you fit the data with a degree polynomial, what values of the 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 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 # initial guess bounds npinf,npinf,nppi # bounds on parameters popt,pcov optimize.curvefitsinfit,xypsigmasigma,boundsbounds,absolutesigmaTrue,method'dogbox'
However, we can also make the fitting fail.
a Try changing the initial guess to something else, say
p
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, ielmtrf '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 second intervals spaced minute apart:
time minutes: counts per second:
a Fit a reasonable function An expoential decay to this data, using curvefit. Assume the error sigma on each measurement is 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 second time interval, the error sigma will be the square root of the number of counts. Using this, try using curvefit 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 parameters with and without assuming Poisson noise. How do these results compare to the values in part a and c
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
