{ "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\n", "\n" ] }, { "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": {}, "source": [ "#### Version information\n", "`version_information` is from J.R. Johansson (jrjohansson at gmail.com); see Introduction to scientific computing with Python . If not already installed on your machine, run `pip install --upgrade version_information` from the terminal\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/json": { "Software versions": [ { "module": "Python", "version": "3.11.5 64bit [MSC v.1916 64 bit (AMD64)]" }, { "module": "IPython", "version": "8.15.0" }, { "module": "OS", "version": "Windows 10 10.0.26100 SP0" }, { "module": "numpy", "version": "1.23.2" }, { "module": "scipy", "version": "1.11.1" } ] }, "text/html": [ "
SoftwareVersion
Python3.11.5 64bit [MSC v.1916 64 bit (AMD64)]
IPython8.15.0
OSWindows 10 10.0.26100 SP0
numpy1.23.2
scipy1.11.1
Sat Feb 08 13:55:56 2025 Eastern Standard Time
" ], "text/latex": [ "\\begin{tabular}{|l|l|}\\hline\n", "{\\bf Software} & {\\bf Version} \\\\ \\hline\\hline\n", "Python & 3.11.5 64bit [MSC v.1916 64 bit (AMD64)] \\\\ \\hline\n", "IPython & 8.15.0 \\\\ \\hline\n", "OS & Windows 10 10.0.26100 SP0 \\\\ \\hline\n", "numpy & 1.23.2 \\\\ \\hline\n", "scipy & 1.11.1 \\\\ \\hline\n", "\\hline \\multicolumn{2}{|l|}{Sat Feb 08 13:55:56 2025 Eastern Standard Time} \\\\ \\hline\n", "\\end{tabular}\n" ], "text/plain": [ "Software versions\n", "Python 3.11.5 64bit [MSC v.1916 64 bit (AMD64)]\n", "IPython 8.15.0\n", "OS Windows 10 10.0.26100 SP0\n", "numpy 1.23.2\n", "scipy 1.11.1\n", "Sat Feb 08 13:55:56 2025 Eastern Standard Time" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%load_ext version_information\n", "%version_information numpy, scipy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.11.5" } }, "nbformat": 4, "nbformat_minor": 4 }