Engineering Probability Class 15 Thu 2022-03-03
1 Matlab
Matlab, Mathematica, and Maple all will help you do problems too big to do by hand. Today I'll demo Matlab.
-
Matlab
-
Major functions:
cdf(dist,X,A,...) pdf(dist,X,A,...)
-
Common cases of dist (there are many others):
'Binomial' 'Exponential' 'Poisson' 'Normal' 'Geometric' 'Uniform' 'Discrete Uniform'
-
Examples:
pdf('Normal',-2:2,0,1) cdf('Normal',-2:2,0,1) p=0.2 n=10 k=0:10 bp=pdf('Binomial',k,n,p) bar(k,bp) grid on bc=cdf('Binomial',k,n,p) bar(k,bc) grid on x=-3:.2:3 np=pdf('Normal',x,0,1) plot(x,np)
Interactive GUI to explore distributions: disttool
-
Random numbers:
rand(3) rand(1,5) randn(1,10) randn(1,10)*100+500 randi(100,4)
Interactive GUI to explore random numbers: randtool
-
Plotting two things at once:
x=-3:.2:3 n1=pdf('Normal',x,0,1) n2=pdf('Normal',x,0,2) plot(x,n1,n2) plot(x,n1,x,n2) plot(x,n1,'--r',x,n2,'.g')
-
Use Matlab to compute a geometric pdf w/o using the builtin function.
-
Review. Which of the following do you prefer to use?
Matlab
Maple
Mathematica
Paper. It was good enough for Bernoulli and Gauss; it's good enough for me.
Something else (please email about it me after the class).
1.1 My opinion
This is my opinion of Matlab.
-
Advantages
Excellent quality numerical routines.
Free at RPI.
Many toolkits available.
Uses parallel computers and GPUs.
Interactive - you type commands and immediately see results.
No need to compile programs.
-
Disadvantages
Very expensive outside RPI.
Once you start using Matlab, you can't easily move away when their prices rise.
You must force your data structures to look like arrays.
Long programs must still be developed offline.
Hard to write in Matlab's style.
Programs are hard to read.
-
Alternatives
Free clones like Octave are not very good.
The excellent math routines in Matlab are also available free in C++ librarues
With C++ libraries using template metaprogramming, your code looks like Matlab.
They compile slowly.
Error messages are inscrutable.
Executables run very quickly.
2 Tutorial on probability density
Since the meaning of probability density when you transform variables is still causing problems for some people, think of changing units from English to metric. First, with one variable, X.
-
Let X be in feet and be U[0,1].
$$f_X(x) = \begin{cases} 1& \text{if } 0\le x\le1\\ 0&\text{otherwise} \end{cases}$$
$P[.5\le x\le .51] = 0.01$.
Now change to centimeters. The transformation is $Y=30X$.
$$f_Y(y) = \begin{cases} 1/30 & \text{if } 0\le y\le30\\ 0&\text{otherwise} \end{cases}$$
Why is 1/30 reasonable?
First, the pdf has to integrate to 1: $$\int_{-\infty}^\infty f_Y(y) =1$$
Second, $$\begin{align} & P[.5\le x\le .51] \\ &= \int_.5^.51 f_X(x) dx \\& =0.01 \\& = P[15\le y\le 15.3] \\& = \int_{15}^{15.3} f_Y(y) dy \end{align}$$
3 Tutorial on probability density - 2 variables
Here's a try at motivating changing 2 variables.
We're throwing darts uniformly at a one foot square dartboard.
We observe 2 random variables, X, Y, where the dart hits (in Cartesian coordinates).
$$f_{X,Y}(x,y) = \begin{cases} 1& \text{if}\,\, 0\le x\le1 \cap 0\le y\le1\\ 0&\text{otherwise} \end{cases}$$
$$P[.5\le x\le .6 \cap .8\le y\le.9] = \int_{.5}^{.6}\int_{.8}^{.9} f_{XY}(x,y) dx \, dy = 0.01 $$
Transform to centimeters: $$\begin{bmatrix}V\\W\end{bmatrix} = \begin{pmatrix}30&0\\0&30\end{pmatrix} \begin{bmatrix}X\\Y\end{bmatrix}$$
$$f_{V,W}(v,w) = \begin{cases} 1/900& \text{if } 0\le v\le30 \cap 0\le w\le30\\ 0&\text{otherwise} \end{cases}$$
$$P[15\le v\le 18 \cap 24\le w\le27] = \\ \int_{15}^{18}\int_{24}^{27} f_{VW}(v,w)\, dv\, dw = \frac{ (18-15)(27-24) }{900} = 0.01$$
See Section 5.8.3 on page 286.