{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Hughes and Hase worked example 3.2.2 (p. 25)\n", "### Using tools from the `stats` submodule of `scipy`\n", "\n", "Sampling resistors from a normal distribution with $\\bar{R} = 100\\, \\Omega$ and $\\sigma = 2\\, \\Omega$." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import numpy as np # import numpy\n", "from scipy import stats # import stats sub-module" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Probability of selection a resistor with a value of $95\\, \\Omega$ or less\n", "\n", "$$\n", "P = \\int_{-\\infty}^{95} P_{DF}(R)\\, dR \\equiv C_{DF}(R)\n", "$$" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability = 0.006209665325776132\n" ] } ], "source": [ "mean = 100\n", "sigma = 2\n", "\n", "p = stats.norm.cdf(95, mean, sigma)\n", "print('probability = ',p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This probability agrees with that given by H&H." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Probability of selection a resistor with a value in the range $99-101\\, \\Omega$\n", "\n", "\\begin{eqnarray*}\n", "P &=& \\int_{99}^{101} P_{DF}(R)\\, dR\\\\\n", " &=& \\int_{-\\infty}^{101}P_{DF}(R)\\, dR - \\int_{-\\infty}^{99} P_{DF}(R)\\, dR \\\\\n", " &=& C_{DF}(101) - C_{DF}(99)\n", "\\end{eqnarray*}\n", "\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "probability = 0.38292492254802624\n" ] } ], "source": [ "p = stats.norm.cdf(101, mean, sigma) - stats.norm.cdf(99, mean, sigma)\n", "print('probability = ',p)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This probability agrees with that given by H&H." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "%load_ext version_information" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.7.7 64bit [GCC 7.3.0]" }, { "module": "IPython", "version": "7.16.1" }, { "module": "OS", "version": "Linux 4.9.0 9 amd64 x86_64 with debian 9.13" }, { "module": "numpy", "version": "1.18.5" }, { "module": "scipy", "version": "1.5.0" } ] }, "text/html": [ "
SoftwareVersion
Python3.7.7 64bit [GCC 7.3.0]
IPython7.16.1
OSLinux 4.9.0 9 amd64 x86_64 with debian 9.13
numpy1.18.5
scipy1.5.0
Wed Aug 26 13:54:36 2020 EDT
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.7.7 64bit [GCC 7.3.0] \\\\ \\hline\n", "IPython & 7.16.1 \\\\ \\hline\n", "OS & Linux 4.9.0 9 amd64 x86\\_64 with debian 9.13 \\\\ \\hline\n", "numpy & 1.18.5 \\\\ \\hline\n", "scipy & 1.5.0 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Wed Aug 26 13:54:36 2020 EDT} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.7.7 64bit [GCC 7.3.0]\n", "IPython 7.16.1\n", "OS Linux 4.9.0 9 amd64 x86_64 with debian 9.13\n", "numpy 1.18.5\n", "scipy 1.5.0\n", "Wed Aug 26 13:54:36 2020 EDT" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%version_information numpy, scipy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.8" } }, "nbformat": 4, "nbformat_minor": 4 }