{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Hughes and Hase, Problem 3.5\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from scipy import stats" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Introduction\n", "\n", "The probabilities in this problem can be evaluated with the cumulative distribution function, or $C_{DF}$, of a normal distribution. (This $C_{DF}$ also has the name $\\mbox{Erf}(x)$.) \n", "I will use the $C_{DF}$ from the `stats` sub-module of `scipy`." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "mean = 502\n", "sigma = 14" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Probability that the bag contains less than $500\\, \\mbox{g}$:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.4432015031835318" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stats.norm.cdf(500, mean, sigma)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The probability is about 44%." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Probability that the bag contains at least $530\\, \\mbox{g}$:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.02275013194817921" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 - stats.norm.cdf(530, mean, sigma)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The probability is about 2.3%, and so, out of 1000 bags, you would expect about 23 to have a mass greater than 530 g." ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "#### Version information\n", "`version_information` is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python for more information and instructions for package installation.\n", "\n", "`version_information` is installed on the linux network at Bucknell" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "%load_ext version_information" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.7.8 64bit [GCC 7.5.0]" }, { "module": "IPython", "version": "7.17.0" }, { "module": "OS", "version": "Linux 3.10.0 1160.36.2.el7.x86_64 x86_64 with centos 7.9.2009 Core" }, { "module": "numpy", "version": "1.19.1" }, { "module": "scipy", "version": "1.5.0" } ] }, "text/html": [ "
SoftwareVersion
Python3.7.8 64bit [GCC 7.5.0]
IPython7.17.0
OSLinux 3.10.0 1160.36.2.el7.x86_64 x86_64 with centos 7.9.2009 Core
numpy1.19.1
scipy1.5.0
Fri Feb 04 15:03:33 2022 EST
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.7.8 64bit [GCC 7.5.0] \\\\ \\hline\n", "IPython & 7.17.0 \\\\ \\hline\n", "OS & Linux 3.10.0 1160.36.2.el7.x86\\_64 x86\\_64 with centos 7.9.2009 Core \\\\ \\hline\n", "numpy & 1.19.1 \\\\ \\hline\n", "scipy & 1.5.0 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Fri Feb 04 15:03:33 2022 EST} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.7.8 64bit [GCC 7.5.0]\n", "IPython 7.17.0\n", "OS Linux 3.10.0 1160.36.2.el7.x86_64 x86_64 with centos 7.9.2009 Core\n", "numpy 1.19.1\n", "scipy 1.5.0\n", "Fri Feb 04 15:03:33 2022 EST" ] }, "execution_count": 6, "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": 2 }