Upload
omarseng
View
61
Download
0
Tags:
Embed Size (px)
DESCRIPTION
some matlab code on random variable -Probability and random variable ,function codes ,and others "How To Simulate Random Variable using MATLAB "
Citation preview
1
Yarmouk University
Hijjawii faculty for engineering Technology
Communication Engineering Department
&
Prince Fasial Information Technology center
RANDOM PROJECT
CME 610
Dr. Khaled Gharaibeh
Prensented By : Eng. Omar S. Abu_Rumman
2012976008
2
Table of contents
1. Introduction………………………………….….…………...…….…………3
2. Definitions ……………………………………….….………….….…………4
3. General Information………………………………………………………….5
4. Analysis Using Matlab & Result………………..………………………….…7
5. Acceptable Strings For Name………………………………………………....13
3
1. Introduction :
MATLAB is a high-performance language for technical computing. It integratescomputation, visualization, and programmingin an easy-to-use environment whereproblems and solutions are expressed in familiar mathematical notation. MATLAB is aninteractive system whose basic data element is an array that does not requiredimensioning. MATLAB stands for MATrix LABoratory.
Typical uses include:
Math and computation. Algorithm development. Data acquisition. Modeling, simulation, and prototyping. Data analysis, exploration, and visualization. Scientific and engineering graphics. Application development, including graphical user interface building.
And you will be using Matlab to solve problems in many application :
Circuits Communication systems Digital signal processing Control systems Probability and statistics
Why Use Computer Simulation?
A computer simulation is valuable in many respects. It can be useda. to provide counterexamples to proposed theoremsb.to build intuition by experimenting with random numbersc. to lend evidence to a conjecture.
4
2. Definitions
Random Variable Concept ?
Random Variable (r.v): Afinite single valued function X() that maps the set of allexperimental outcomes into the set of real numbers R is said to be a r.v, if the set | X ( ) x is an event (F) for every x in R.Or is numerically valued function X of ω with domain Ω. whereω ∈ Ω : ω→ X (ω) is called a r.v. on Ω.A real r.v. is a real function of the elements of a sample space S.
Distribution Function (CDF) ?
Cumulative probability distribution function (CPDF) defined as
P X ≤ x = probability of the event X ≤ x= function of x= FX (x) with (−∞ ≤ x ≤ ∞)
So for a given random variable X, let us consider the event X ≤ x where x is any real number inthe interval (-∞, ∞). We write the probability of this event as P(X≤ x) and denote it simply by F(x),i.e.F(x) = P(X≤ x) -∞ < x < ∞
Function F(x) is called Probability Distribution Function, also known as CumulativeDistribution Function (CDF).
In MatlabY = cdf('name',X,A)Y = cdf('name',X,A,B)Y = cdf('name',X,A,B,C)
Description:
Y = cdf('name',X,A) computes the cumulative distribution function for the one-parameterfamily of distributions specified by name. A contains parameter values for the distribution.The cumulative distribution function is evaluated at the values in X and its values are returnedin Y.If X and A are arrays, they must be the same size. If X is a scalar, it is expanded to a constantmatrix the same size as A. If A is a scalar, it is expanded to a constant matrix the same sizeas X.Y is the common size of X and A after any necessary scalar expansion.
5
Y = cdf('name',X,A,B) computes the cumulative distribution function for two-parameterfamilies of distributions, where parameter values are given in A and B.If X, A, and B are arrays, they must be the same size. If X is a scalar, it is expanded to aconstant matrix the same size as A and B. If either A or B are scalars, they are expanded toconstant matrices the same size as X.Y is the common size of X, A, and B after any necessary scalar expansion.
Y = cdf('name',X,A,B,C) computes the cumulative distribution function for three-parameterfamilies of distributions, where parameter values are given in A, B, and C.If X, A, B, and C are arrays, they must be the same size. If X is a scalar, it is expanded to aconstant matrix the same size as A, B, and C. If any of A, B or C are scalars, they areexpanded to constant matrices the same size as X.Y is the common size of X, A, B, and C after any necessary scalar expansion.
Probability Density Function (PDF) ?
The derivative of CDF is known as probability density function (PDF) and it is denotedas f(x). Mathematically: ( ) = ( )Probability Density Function PDFEquivalently
F(x) =∫ ( )∝ −∝< <∝This is for continuous variables,but in case of discrete random variables PDF is expressed as( ) = ( = ) ( − )
3. General Information
Statistical Averages of Random variables:
The first and second moments of a single random variable and the joint moments such arecorrelation and covariance between any pair of random variables in a multidimensional set ofrandom variables are of particular interests.For all the cases below: X is single random variable and its PDF is ( ) .
6
Mean or Expected value of X:
This is first moment of the random variable X. E() denotes expectation (statistical averaging)E(x) =mx=∫ ( )∝∝ −∝< <∝
The n-th moment is defined as
E( ) =mx=∫ ( )∝∝If mx is the mean value of the random variable X, the nth central moment is defined as
E(Y)=E((X- mx) )= ∫ ( −mx) ( )∝∝ Variance ?
when n = 2 the central moment is called the variance of the random variable and denoted as
= ∫ ( − mx) ( )∝∝variance provides the measure of the dispersion of the random variable X.
= ( ) - mx
Joint moment ?in case of two random variables X1 and X2 with joint PDF f(x1,x2) we define joint moment as:
E( ) =∬ ( , )∝−∝ joint central moment as:
E( − mx ) ( − mx ) ) = ∬ ( − m1) ( − mx) ( , )∝∝ Correlation ?
when k = n = 1, we get correlation and covariance of the random variables X1andX2 i.e. Correlation between Xi and Xj is given by joint moment
E = ∬ ∬ ( , )∝∝ Covariance ? of Xi and Xj is= E -mi mj
7
the n x n matrix with the elements µij is called the covariance matrix of the randomvariablesXi , i = 1,2,……..n
The two random variables are said to be uncorrelated if
E(XiXj) = E(Xi)E(Xj) = mimj
which means µij =0.
i.e. Xi and Xj are statistically independent then they are uncorrelated but vice versa isnot true.
Two random variables are said to be orthogonal is
E(XiXj) = 0
this condition holds when Xi and Xj are uncorrelated and either one or both of therandom variables have zero mean
The equivalent Matlab functions for above :
8
4. Analysis Using Matlab & Result :
Note: please press ctrl+click on m file to open it (Gauusian.m)%plot Gaussian density function,mean=3,stdev(sigma)=1ax=3; sigma=1; %range for x from -3 to +3x=-1:0.1:7;c=1/sqrt(2*pi*sigma^2);y=c*exp((-(x-ax).^2)/(2*sigma^2))plot(x,y); ylabel('Gaussian pdf');xlabel('mean=3, sigma=1'); grid;
Common PDFs command
Uniformpdf .m :
Uniform probability density functions can be generated using Function unifpdf,Given a range x, and a left and right endpoint, unifpdf distributes probabilitiesuniformly over x.%plot a uniform density function, %range for x from -10 to +10%a=-7;b=7;x=-10:1:10;pdfuniform = unifpdf(x,a,b)plot(x,pdfuniform); ylabel('uniform pdf');grid
-1 0 1 2 3 4 5 6 70
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
Gaussianpdf
mean=3, sigma=1
9
Normalpdf.m :
Normal probability density functions are generated using function normpdf.Characteristic of a normal distribution are mean and standard deviation.
%plot Normal Density function,normpdf(x,mean,std)%range for x from -15 to +25 (vector range )x=-15:0.1:25;mean=3;sigma=4;pdfnormal=normpdf(x,mean,sigma);plot(x,pdfnormal); ylabel('norma pdf');xlabel('mean=3, sigma=3'); grid;
-10 -8 -6 -4 -2 0 2 4 6 8 100
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
uniformpdf
-15 -10 -5 0 5 10 15 20 250
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
0.09
0.1
normapdf
mean=3, sigma=3
10
Normal and Uniform PDFs (joint)
randPdf.m
unifpdf and normpdf generate "perfect" densities; however, typical dataobservations only fit these distributions approximately. To simulate thesesituations , Matlab offers functions for random number generation for bothuniform and normal distributions.
Function rand generates uniformly distributed random values between 0 and 1.
rand(rows ,columns): matrix with rows and columns of random values.
%plot Normal Density function with uniform ,rand(rows,columns)pdfUniform = rand(1, 10000);subplot(2,1,1), hist(pdfUniform),title('Uniform distribution, histogram');subplot(2,1,2), hist(pdfUniform, 100),title('Uniform distribution, 100 bin histogram');
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
500
1000
1500Uniform distribution, histogram
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10
50
100
150Uniform distribution, 100 bin histogram
11
rand2Pdf.mTo fit a different range of x-values, we can shift and scale the random value matrix accordingly:
%plot Normal Density function with shifting uniform ,rand(rows,columns)pdfUniform = rand(1, 10000);pdfUniformSS = pdfUniform * 10 + 100;hist(pdfUniformSS, 100),title('Uniform distribution Shifted and Scaled, 100 bin histogram');
randnPdf.m:
Function randn generates normally distributed random values with mean=0 and standarddeviation=0.
%randn(rows, columns) matrix with rows and columns random values%;pdfNormal = randn(1, 10000);subplot(2,1,1), hist(pdfNormal), title('Normal distribution, histogram');subplot(2,1,2), hist(pdfNormal, 100), title('Normal distribution, 100 bin histogram');
100 101 102 103 104 105 106 107 108 109 1100
20
40
60
80
100
120Uniform distribution Shifted and Scaled, 100 bin histogram
12
NormalGuassian.m:
A random normal distribution with mean (mean) and standard deviation (std) is obtained by shiftingand scaling:
pdfMean = 5;pdfStd = 7;pdfNormalSS = randn(1, 10000) * pdfStd + pdfMean;subplot(2,1,1), hist(pdfNormalSS), title('Normal distribution with Mean=5, Std=7');subplot(2,1,2), hist(pdfNormalSS, 100), title('Normal distribution with Mean=5, Std=7');
-4 -3 -2 -1 0 1 2 3 4 50
1000
2000
3000Normal distribution, histogram
-4 -3 -2 -1 0 1 2 3 4 50
100
200
300
400Normal distribution, 100 bin histogram
-20 -10 0 10 20 30 400
1000
2000
3000Normal distribution with Mean=5, Std=7
-20 -10 0 10 20 30 400
100
200
300
400Normal distribution with Mean=5, Std=7
13
5. Acceptable strings for name (specified in single quotes) ::
Name Distribution InputParameter A
InputParameter B
InputParamet
er c'beta' or 'Beta' Beta Distribution A B —
'bino' or'Binomial' Binomial Distribution n: number oftrials
p: probabilityof success foreach trial
—
'birnbaumsaunders' Birnbaum-SaundersDistribution β Γ —
'burr' or 'Burr' Burr Type XII Distribution α: scaleparameter
c: shapeparameter
k: shapeparameter
'chi2' or'Chisquare' Chi-Square Distribution ν: degrees offreedom — —
'exp' or'Exponential' Exponential Distribution μ: mean — —
'ev' or 'Extreme Value' Extreme Value Distribution μ: locationparameter
σ: scaleparameter —
'f' or 'F' F Distributionν1: numeratordegrees offreedom
ν2:denominatordegrees offreedom
—
'gam' or 'Gamma' Gamma Distribution a: shapeparameter
b: scaleparameter —
'gev' or'GeneralizedExtreme Value'
Generalized Extreme ValueDistribution
k: shapeparameter
σ: scaleparameter
μ: locationparameter
'gp' or'GeneralizedPareto'
Generalized ParetoDistribution
k: tail index(shape)parameter
σ: scaleparameter
μ:threshold(location)parameter
'geo' or'Geometric' Geometric Distribution p: probabilityparameter — —
'hyge' or'Hypergeometric'
HypergeometricDistribution
M: size of thepopulation
K: number ofitems with thedesiredcharacteristicin thepopulation
n: numberof samplesdrawn
'inversegaussian' Inverse GaussianDistribution μ Λ —
'logistic' Logistic Distribution μ Σ —'loglogistic' Loglogistic Distribution μ Σ —'logn' or'Lognormal' Lognormal Distribution μ Σ —'nakagami' Nakagami Distribution μ Ω —
'nbin' or 'NegativeBinomial'
Negative BinomialDistribution
r: number ofsuccesses
p: probabilityof success in asingle trial
—
14
'ncf' or'Noncentral F' Noncentral F Distributionν1: numeratordegrees offreedom
ν2:denominatordegrees offreedom
δ:noncentralityparameter
'nct' or'Noncentral t' Noncentral t Distribution ν: degrees offreedom
δ:noncentralityparameter
—
'ncx2' or'NoncentralChi-square'
Noncentral Chi-SquareDistribution
ν: degrees offreedom
δ:noncentralityparameter
—
'norm' or 'Normal' Normal Distribution μ: mean σ: standarddeviation —
'poiss' or'Poisson' Poisson Distribution λ: mean — —
'rayl' or'Rayleigh' Rayleigh Distribution b: scaleparameter — —
'rician' Rician Distributions:noncentralityparameter
σ: scaleparameter —
't' or 'T' Student's t Distribution ν: degrees offreedom — —
'tlocationscale' t Location-ScaleDistribution
μ: locationparameter
σ: scaleparameter
ν: shapeparameter
'unif' or 'Uniform' Uniform Distribution(Continuous)
a: lowerendpoint(minimum)
b: upperendpoint(maximum)
—
'unid' or 'DiscreteUniform'
Uniform Distribution(Discrete)
N: maximumobservablevalue
— —
'wbl' or 'Weibull' Weibull Distribution a: scaleparameter
b: shapeparameter —