Course-related Matlab functionalities
By Afshine Amidi and Shervine Amidi
Discrete distribution functions
Uniform
unidrnd(N)
randomly generates an integer between1
andN
.
So if you want to generate the rolling result obtained by a fair die, just type
unidrnd(6)
To generate a vector of n
such trials, you can use:
n = 100
unidrnd(6, 1, n)
unidpdf(x, N)
provides the probability of the outcomex
happening in the case of a discrete uniform distribution between1
toN
.
For example, the probability that rolling a fair die gives a 1
is given by
unidpdf(1, 6)
unidcdf(x, N)
gives the probability of obtaining an outcome less or equal thatx
for a discrete uniform distribution between1
toN
.
For example, the probability of obtaining a number between 1
and 3
after rolling a faire die can be computed with
unidcdf(3, 6)
unidinv(P, N)
provides the smallest integerk
such that the probability of obtaining an outcome between1
andk
is greater or equal toP
.
For instance, the smallest integer k
such that at least 60% of the outcomes generated by a fair die are between 1
and k
is given by
unidinv(0.60, 6)
Binomial
binornd(N, p)
generates from the binomial distribution a possible number of successes out ofN
trials, each of which has a probability of successp
.
To illustrate this, a possible number of times a fair coin is flipped as heads out of 100
trials is given by
binornd(100, 0.5)
binopdf(x, N, p)
gives the probability of obtainingx
successes out ofN
trials, each of which has a probability of success ofp
.
In the example of flipping coins, the probability of observing tails 60 times after 100
flipping trials of a fair coin is provided by
binopdf(60, 100, 0.5)
binocdf(x, N, p)
gives the probability of observing at mostx
successes out ofN
trials, each of which has a probability of success ofp
.
In the example of flipping coins, the probability of obtaining tails at most 60 times after 100
flipping trials of a fair coin is provided by
binocdf(60, 100, 0.5)
binoinv(P, N, p)
gives the smallest integerk
such that the probability of obtaining between0
andk
successes afterN
trials -- each of which has a probability of success ofp
-- is greater or equal toP
.
For example, the smallest integer k
such that at least 40% of the time, generating 100
trials provides a number of heads between 0
and k
is given by
binoinv(0.40, 100, 0.5)
Poisson
-
poissrnd(mu)
generates a random number from the Poisson distribution of parametermu
. -
poisspdf(x, mu)
gives the probability of obtainingx
from the Poisson distribution of parametermu
. -
poisscdf(x, mu)
gives the probability of observing a value between0
andx
from the Poisson distribution of parametermu
-
poissinv(P, mu)
gives the smallest integerk
such that the probability of obtaining a value between0
andk
from the Poisson distribution of parametermu
is greater or equal toP
.
Continuous distribution functions
Uniform
-
unifrnd(x_min, x_max)
randomly generates a real number between the valuesx_min
andx_max
. -
unifpdf(x, x_min, x_max)
returns the value atx
of the probability density function of the continuous uniform distribution with boundsx_min
andx_max
. -
unifcdf(x, x_min, x_max)
returns the probability that the continuous uniform distribution with boundsx_min
andx_max
yields a value of at mostx
. -
unifinv(P, x_min, x_max)
gives the valuex
such that the continuous uniform distribution with boundsx_min
andx_max
has a probability of exactlyP
to yield outcomes that are less or equal thanx
.
Normal
-
normrnd(mu, sigma)
generates a random number from the Gaussian distribution of meanmu
and standard deviationsigma
. -
normpdf(x, mu, sigma)
returns the value atx
of the probability density function of the Gaussian distribution of meanmu
and standard deviationsigma
. -
normcdf(x, mu, sigma)
returns the probability that a random number drawn from the Gaussian distribution of meanmu
and standard deviationsigma
has a value of at mostx
. -
norminv(P, mu, sigma)
gives the valuex
such that the Gaussian distribution of meanmu
and standard deviationsigma
has a probability of exactlyP
to yield outcomes that are less or equal thanx
.
Exponential
-
exprnd(lambda)
generates a random number from the exponential distribution of parameterlambda
. -
exppdf(x, lambda)
returns the value atx
of the probability density function of the exponential distribution of parameterlambda
. -
expcdf(x, lambda)
returns the probability that a random number drawn from the exponential distribution of parameterlambda
has a value of at mostx
. -
expinv(P, lambda)
gives the valuex
such that the exponential distribution of parameterlambda
has a probability of exactlyP
to yield outcomes that are less or equal thanx
.