{ "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": [ "
Software | Version |
---|---|
Python | 3.11.5 64bit [MSC v.1916 64 bit (AMD64)] |
IPython | 8.15.0 |
OS | Windows 10 10.0.26100 SP0 |
numpy | 1.23.2 |
scipy | 1.11.1 |
Sat Feb 08 13:55:56 2025 Eastern Standard Time |