{ "cells": [ { "cell_type": "markdown", "id": "997a3352", "metadata": {}, "source": [ "# PHYS 310 HW 1 Solutions\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "0d86ca50", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import matplotlib.pyplot as plt\n" ] }, { "cell_type": "markdown", "id": "3691bbf9", "metadata": {}, "source": [ "## Hughes & Hayes: 2.2\n", "\n", "Mean: \n", "$$\\mu = \\frac{1}{N} \\sum_i x_i$$\n", "\n", "Standard Deviation:\n", "$$\\sigma_{N-1} = \\sqrt{\\frac{1}{N-1} \\sum_i (x_i - \\mu)^2}$$\n", "\n", "Standard Error (Standard deviation of the mean):\n", "$$\\alpha = \\frac{\\sigma_{N-1}}{\\sqrt{N}}$$" ] }, { "cell_type": "code", "execution_count": 2, "id": "a3671faa", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(i) The mean sensitivity of the photodiode is 5.078333333333334 = 5.07833 A/W\n", "(ii) The standard deviation of the sensitivity measurements is 0.14357977404617803 = 0.14358 A/W\n", "(iii) The standard error of the sensitivity measurements is 0.04144791059787326 = 0.04145 A/W\n", "(iv) The Sensitivity of the Photodiode is 5.08 +/- 0.04 A/W\n" ] } ], "source": [ "sensitive = np.asarray([5.33,4.95,4.93,5.08,4.95,4.96,5.02,4.99,5.24,5.25,5.23,5.01]) #A/W\n", "\n", "#(i)\n", "mu_manual = sum(sensitive)/len(sensitive)\n", "mu = np.mean(sensitive) #Two ways of doing the same thing\n", "\n", "print('(i) The mean sensitivity of the photodiode is ',mu_manual, '= %.5f'%(mu), 'A/W')\n", "# The %.5f in a string followed by %(number) magic keeps 5 decimal places to read more easily\n", "\n", "#(ii)\n", "sig_manual = np.sqrt(sum((sensitive - mu)**2)/(len(sensitive)-1))\n", "sig = np.std(sensitive, ddof=1) \n", "#REMEMBER TO USE ddof = 1, because we will only ever be able to take a sampling of all the data there ever could be\n", "print('(ii) The standard deviation of the sensitivity measurements is ',sig_manual, '= %.5f'%(sig), 'A/W')\n", "\n", "#(iii)\n", "alpha = sig/np.sqrt(len(sensitive))\n", "print('(iii) The standard error of the sensitivity measurements is ',alpha, '= %.5f'%(alpha), 'A/W')\n", "\n", "#(iv) Our addition\n", "#Now we know what precision to actually print .2f\n", "print('(iv) The Sensitivity of the Photodiode is %.2f +/- %.2f A/W'%(mu,alpha))\n" ] }, { "cell_type": "markdown", "id": "f2fb0967", "metadata": {}, "source": [ "## H&H: 2.3\n", "\n", "The standard error, or standard deviation of the mean, is given by Eq.(2.7):\n", "$$\\alpha = \\frac{\\sigma_{N−1}}{\\sqrt{N}}$$\n", "\n", "To decrease $\\alpha$ by a factor of 10, the denominator must be increased by the same factor, which means\n", "that N must increase by a factor of 100. Translating to the described experiment, this means that\n", "data should be collected for 100 minutes (assuming that everything in the experiment is stable for\n", "that length of time)." ] }, { "cell_type": "markdown", "id": "d2cebe15", "metadata": {}, "source": [ "## Pendulum Problem\n", "\n", "The standard deviation is an estimate of timing accuracy.\n", "\n", "**Experiment A:** 12 sets of 10 swings gives a result of $T_{10} = 28.39 \\pm \\frac{0.04}{\\sqrt{12}}$ seconds for timing for 10 swings. That is distributed to the 10 swings to give:\n", "$$T_1 = \\frac{28.39 \\pm \\frac{0.04}{\\sqrt{12}}}{10}~\\mathrm{s}$$\n", "$$T_1= 2.839 \\pm 0.001~\\mathrm{s}$$\n", "\n", "**Experiment B:** The single measurement of 120 swings is assumed to have the same timing accuracy, giving a result of $T_{120} = 340.61 \\pm \\frac{0.04}{\\sqrt{1}}$ seconds for timing for 120 swings. That is distributed to the 120 swings to give:\n", "$$T_1 = \\frac{340.61 \\pm \\frac{0.04}{\\sqrt{1}}}{120}~\\mathrm{s}$$\n", "$$T_1= 2.8384 \\pm 0.0003~\\mathrm{s}$$\n", "\n", "\n", "Distributing a fixed uncertainty over many cycles in one measurement (Experiment B) is more precise than taking more measurements that compound effects from the uncertainty (Experiment A). It is often hard to take one measurement that captures many instances of the phenomenon we want." ] }, { "cell_type": "code", "execution_count": 3, "id": "c27bd672", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Experiment A: 2.839 +/- 0.001 s\n", "Experiment B: 2.8384 +/- 0.0003 s\n" ] } ], "source": [ "print('Experiment A: %.3f +/- %.3f s'%(28.39/10,0.04/np.sqrt(12)/10))\n", "print('Experiment B: %.4f +/- %.4f s'%(340.61/120,0.04/120))" ] }, { "cell_type": "markdown", "id": "26451b39", "metadata": {}, "source": [ "## Estimates\n", "\n", "Getting an intuitive idea of what the data should give you before you run it through statistical formulae is a good skill.\n", "\n", "We can sort the data from smallest to largest, that gives us an idea of the range where the center value is probably close to the average.\n", "It goes from about 3.9s to 4.5s, spanning 0.6s so the middle should be around 3.9+0.3 =4.2s\n", "The median of the 15 measurements (7 values lower and 7 values higher) is 4.19365 s so that double-check worked well.\n", "\n", "For the \"rough and ready\" estimate of standard deviation, the estimate of the mean is 0.3 s away from the ends and we'll use 2/3 of that : 0.2s. \n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "89781e19", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The sorted data from smallest to largest: [3.94315 3.97548 4.0101 4.01286 4.1075 4.13037 4.15578 4.19365 4.20259\n", " 4.21082 4.26921 4.30801 4.35153 4.39831 4.51314]\n", "The median value is: 4.19365\n", "The Estimate might be a mean of: 4.193650 and standard deviation of 0.2\n", "The actual mean: 4.185500 and standard devaition: 0.164020\n" ] } ], "source": [ "period = np.asarray([4.1075, 4.39831, 4.19365, 4.20259, 4.26921, 4.13037, 3.97548, 4.51314, 4.01286,\n", "4.0101, 4.15578, 4.35153, 4.30801, 4.21082, 3.94315])\n", "\n", "print('The sorted data from smallest to largest:',np.sort(period))\n", "print('The median value is:',np.median(period))\n", "print('The Estimate might be a mean of: %f and standard deviation of 0.2'%np.median(period))\n", "print('The actual mean: %f and standard devaition: %f'%(np.mean(period),np.std(period, ddof =1)))" ] }, { "cell_type": "markdown", "id": "c9a491f2", "metadata": {}, "source": [ "The Mean and Standard Deviation of this data is well estimated by the median and 2/3 of half of the range." ] }, { "cell_type": "code", "execution_count": 5, "id": "43104a3c", "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.12.8 64bit [Clang 14.0.6 ]" }, { "module": "IPython", "version": "8.30.0" }, { "module": "OS", "version": "macOS 15.2 arm64 arm 64bit" } ] }, "text/html": [ "
Software | Version |
---|---|
Python | 3.12.8 64bit [Clang 14.0.6 ] |
IPython | 8.30.0 |
OS | macOS 15.2 arm64 arm 64bit |
Wed Jan 29 16:33:02 2025 EST |