{ "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": [ "
Software | Version |
---|---|
Python | 3.7.7 64bit [GCC 7.3.0] |
IPython | 7.16.1 |
OS | Linux 4.9.0 9 amd64 x86_64 with debian 9.13 |
numpy | 1.18.5 |
scipy | 1.5.0 |
Wed Aug 26 13:54:36 2020 EDT |