Skip to main content

Engineering Probability Class 15 Thu 2022-03-03

1 Matlab

  1. Matlab, Mathematica, and Maple all will help you do problems too big to do by hand. Today I'll demo Matlab.

  2. Matlab

    1. Major functions:

      cdf(dist,X,A,...)
      pdf(dist,X,A,...)
    2. Common cases of dist (there are many others):

      'Binomial'
      'Exponential'
      'Poisson'
      'Normal'
      'Geometric'
      'Uniform'
      'Discrete Uniform'
    3. 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)
    4. Interactive GUI to explore distributions: disttool

    5. Random numbers:

      rand(3)
      rand(1,5)
      randn(1,10)
      randn(1,10)*100+500
      randi(100,4)
    6. Interactive GUI to explore random numbers: randtool

    7. 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')
  3. Use Matlab to compute a geometric pdf w/o using the builtin function.

  4. Review. Which of the following do you prefer to use?

    1. Matlab

    2. Maple

    3. Mathematica

    4. Paper. It was good enough for Bernoulli and Gauss; it's good enough for me.

    5. Something else (please email about it me after the class).

1.1 My opinion

This is my opinion of Matlab.

  1. Advantages

    1. Excellent quality numerical routines.

    2. Free at RPI.

    3. Many toolkits available.

    4. Uses parallel computers and GPUs.

    5. Interactive - you type commands and immediately see results.

    6. No need to compile programs.

  2. Disadvantages

    1. Very expensive outside RPI.

    2. Once you start using Matlab, you can't easily move away when their prices rise.

    3. You must force your data structures to look like arrays.

    4. Long programs must still be developed offline.

    5. Hard to write in Matlab's style.

    6. Programs are hard to read.

  3. Alternatives

    1. Free clones like Octave are not very good.

    2. The excellent math routines in Matlab are also available free in C++ librarues

    3. With C++ libraries using template metaprogramming, your code looks like Matlab.

    4. They compile slowly.

    5. Error messages are inscrutable.

    6. 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.

  1. 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}$$

  2. $P[.5\le x\le .51] = 0.01$.

  3. Now change to centimeters. The transformation is $Y=30X$.

  4. $$f_Y(y) = \begin{cases} 1/30 & \text{if } 0\le y\le30\\ 0&\text{otherwise} \end{cases}$$

  5. Why is 1/30 reasonable?

  6. First, the pdf has to integrate to 1: $$\int_{-\infty}^\infty f_Y(y) =1$$

  7. 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.

  1. We're throwing darts uniformly at a one foot square dartboard.

  2. We observe 2 random variables, X, Y, where the dart hits (in Cartesian coordinates).

  3. $$f_{X,Y}(x,y) = \begin{cases} 1& \text{if}\,\, 0\le x\le1 \cap 0\le y\le1\\ 0&\text{otherwise} \end{cases}$$

  4. $$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 $$

  5. Transform to centimeters: $$\begin{bmatrix}V\\W\end{bmatrix} = \begin{pmatrix}30&0\\0&30\end{pmatrix} \begin{bmatrix}X\\Y\end{bmatrix}$$

  6. $$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}$$

  7. $$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$$

  8. See Section 5.8.3 on page 286.

4 Comic

Dilbert