联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Python编程Python编程

日期:2019-11-09 11:24

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 1/10

In [ ]:

Question 1: Linear Regression (10 marks)

The data listed below come from an experiment to verify Ohm's law. The voltage across a resistor (the

dependent variable) was measured as a function of the current flowing (the independent variable). The

precision of the voltmeter was 0.01mV, and the uncertainty in the current was negligible.

This data is saved as 'ohms_law.csv'

Required:

(i) Calculate the unweighted best-fit gradient and intercept, and their uncertainties. (2 marks)

(ii) Calculate the common uncertainty, , and compare the value with the experimental

uncertainty. (2 marks)

(iii) Plot a graph of the data and add the best-fit straight line. Remember to label your axes. (4

marks)

(iv) Calculate the residuals, and comment on their magnitudes. (2 marks)

Current (μA)

Voltage (mV)

Current (μA)

Voltage (mV)

(i) Calculate the unweighted best-fit gradient and intercept, and their

uncertainties.

%matplotlib nbagg

from __future__ import division

from scipy.stats import norm

from IPython.display import HTML

from IPython.display import display

from scipy.optimize import *

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 2/10

(ii) Calculate the common uncertainty (inside the function) and compare with the

experimental uncertainty (by typing your comparison in the markdown cell below

the function). You must return your answer in micro volts.

In [ ]:

YOUR ANSWER HERE

(iii) Plot a graph of the data adding the best fit line and residuals below.

data = pd.read_csv('ohms_law.csv')

current = np.array(data.iloc[:,0])

voltage = np.array(data.iloc[:,1])

voltage_error = data.iloc[:,2]

def linear(x,m,c):

return x*m + c

def one_i():

gradient = 0

intercept = 0

uncertainty_gradient = 0

uncertainty_intercept = 0

# YOUR CODE HERE

return(gradient,intercept,uncertainty_gradient,uncertainty_intercept)

print(one_i())

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

data = pd.read_csv('ohms_law.csv')

current = np.array(data.iloc[:,0])

voltage = np.array(data.iloc[:,1])

voltage_error = data.iloc[:,2]

def one_ii():

# YOUR CODE HERE

return(common_uncertainty)

print(one_ii())

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 3/10

In [ ]:

(iv) Comment on the magnitude of the residuals.

YOUR ANSWER HERE

Question 2: Does the noise on a photo-diode signal follow a

Gaussian distribution? (10 marks)

As we discussed in Chapter 1, for very low intensities the distribution of counts from a photo-detector is

expected to follow the Poisson shot-noise distribution. However, for larger photon fluxes the noise on the

voltage generated in a photo-diode circuit is expected to follow a Gaussian distribution.

The above figure shows the signal output from a photo-diode as a function of time, and in part (b) a histogram

of the distribution of data. The number of observed data points lying within specified bands, , is given below.

Required:

(i) Use the equation,

to determine the number of data points expected in each interval, . You must give your

answer to 4 decimal places (2 marks)

# YOUR CODE HERE

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 4/10

(ii) Show that for all bins, and state why there is no need to combine sequential bins. (2 marks)

(iii) Calculate from the formula (2 marks)

.

(iv) Calculate the number of degrees of freedom. (2 marks)

(v) Given the answers you found in (iii) and (iv), are the data consistent with the hypothesis of a Gaussian

distribution? (2 marks)

(i) Determine the number of data points expected in each interval, . You must

give your answer to 4 decimal places

Ei

In [ ]:

In [ ]:

(ii) Is for all bins? State why there is no need to combine sequential

bins.

Ei > 5

YOUR ANSWER HERE

(iii) Calculate χ .

2

In [ ]:

In [ ]:

(iv) What is the number of degrees of freedom?

def two_i():

intervals = [-1000000000,-2.5,-2,-1.5,-1,-0.5,0,0.5,1,1.5,2,2.5,10000000000]

expected_points = []

# YOUR CODE HERE

return(expected_points)

print(two_i())

'''TEST CELL- DO NOT DELETE'''

def two_iii():

# YOUR CODE HERE

return(chi2)

print(two_iii())

'''TEST CELL- DO NOT DELETE'''

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 5/10

In [ ]:

In [ ]:

(v) Given the answers you found in (iii) and (iv), are the data consistent with the

hypothesis of a Gaussian distribution?

YOUR ANSWER HERE

Question 3: Benford's Law of Anomalous Numbers (10

marks)

It has been observed that the first pages of a table of common logarithms show more wear than do the last

pages, indicating that more used numbers begin with the digit 1 than with the digit 9. (F. Benford, Proceedings

of the American Philosophical Society, 78, March 1938). The Law can be stated that the probability of obtaining

a first digit is equal to .

Table 1 shows some of the data sets analysed by Benford, of which is saved as 'benford.csv'.

Let's consider the rivers row.

Required:

a log (1 + 1/a) 10

def two_iv():

# YOUR CODE HERE

return(degrees_of_freedom)

print(two_iv())

'''TEST CELL- DO NOT DELETE'''

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 6/10

(i) Use Benford's Law to calculate the probability of obtaining a first digit of , for . (2

marks)

(ii) Using Benford's formula and the total count for that group, calculate the expected number

of occurrences of the first digit being , , for . (2 marks)

(iii) Ascertain whether some of the bins should be combined. (1 mark)

(iv) From the table, and the total count for that group, calculate the observed number of

occurrences of the first digit being , , for . (2 mark)

(v) Calculate and the number of degrees of freedom. (1 mark)

(vi) Test the hypothesis that the distribution for that group follows Benford's Law. (2 marks)

a 1 ≤ a ≤ 9

a Ea 1 ≤ a ≤ 9

a Oa 1 ≤ a ≤ 9

(i) Use Benford's Law to calculate the probability of obtaining a first digit of , for

(ii) Using Benford's formula and the total count for that group, calculate the

expected number of occurrences of the first digit being , , for

.

a Ea

(iii) Ascertain whether some of the bins should be combined.

YOUR ANSWER HERE

def three_i():

'''Your function must return an array of all the probabilities from a=1 to a=9'

probability = []

# YOUR CODE HERE

return(probability)

print(three_i())

'''TEST CELL- DO NOT DELETE'''

def three_ii():

expected_occurances = []

# YOUR CODE HERE

return(expected_occurances)

print(three_ii())

'''TEST CELL- DO NOT DELETE'''

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 7/10

YOUR ANSWER HERE

(iv) From the table, and the total count for that group, calculate the observed

number of occurrences of the first digit being a, Oa, for 1 ≤ a ≤ 9.

(v) Calculate χ and the number of degrees of freedom.

(vi) Test the hypothesis that the distribution for that group follows Benford's Law

and make appropiate comments.

YOUR ANSWER HERE

Question 4: Analysing Bevington's data (10 marks)

In this question we will analyse the data from Table~8.1 in P.R. Bevington's book 'Data reduction and error

analysis'.

The data can be obtained from the file BevingtonData.csv. There are two columns: time, and number of counts

detected.

def three_iv():

'''Your function must return an array of occurances from a = 1 to a = 9'''

observed_occurances = []

# YOUR CODE HERE

return(observed_occurances)

print(three_iv())

'''TEST CELL- DO NOT DELETE'''

def three_v():

'''Your function must return the chi^2 value and the degrees of freedom'''

# YOUR CODE HERE

return(chi2,degrees_of_freedom)

print(three_v())

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 8/10

The experiment involves irradiating a coin with thermal neutrons to create two short-lived silver isotopes that

subsequently decay by beta emission. Students count the emitted beta particles in 15s intervals for

approximately 4 minutes.

The model to describe the data has five parameters: a background, ; amplitudes of two excited states,

and , respectively; the mean lives of the excited states, and , respectively. Mathematically, we can

represent the decay by the fitting function:

Required:

(i) What are the count errors? (2 marks)

(ii) Perform a fit to find the parameters (with their errors) (4 marks)

(iii) What is the reduced value? (2 marks)

(iv) Plot an appropriate graph (i.e. counts versus time, with residuals) (2 marks)

(i) What are the count errors?

(ii) Perform a fit using the fitting function f defined in the cell below. What are the

best-fit parameters for a1, ..., a5 along with their errors?

data = pd.read_csv('BevingtonData.csv')

time = np.array(data.iloc[:,0])

count = np.array(data.iloc[:,1])

def count_errors():

'''Your function should return an array of the errors on each of the counts.'''

errors = []

# YOUR CODE HERE

return(errors)

print(count_errors())

'''TEST CELL- DO NOT DELETE'''

assert len(count_errors()) == 59, 'Please make sure that your function returns an ar

'''TEST CELL- DO NOT DELETE'''

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 9/10

data = pd.read_csv('BevingtonData.csv')

time = np.array(data.iloc[:,0])

count = np.array(data.iloc[:,1])

def f(time,a_1,a_2,a_3,a_4,a_5):

return a_1 + a_2*np.exp(-time/a_4) + a_3*np.exp(-time/a_5)

def best_fit_line():

# YOUR CODE HERE

return(a1,a2,a3,a4,a5,error_a1,error_a2,error_a3,error_a4,error_a5)

print(best_fit_line())

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

2019/11/7 Assignment 4

https://notebooks.dmaitre.phyip3.dur.ac.uk/miscada-da/user/czjs88/notebooks/Homework 4/Assignment 4.ipynb 10/10

In [ ]:

In [ ]:

(iii) What is the reduced χ value?

2

In [ ]:

In [ ]:

(iv) Plot a suitable graph. This is, counts versus time, with residuals.

In [ ]:

'''TEST CELL- DO NOT DELETE'''

'''TEST CELL- DO NOT DELETE'''

def reduced_chi_squared():

reduced_chi_squared = 0

# YOUR CODE HERE

return(reduced_chi_squared)

'''TEST CELL- DO NOT DELETE'''

# YOUR CODE HERE


版权所有:留学生编程辅导网 2018 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。