<< Chapter < Page Chapter >> Page >

Use of matlab on simple random variables

For simple random variables, we use the discrete alternative approach, since this may be implemented easily with MATLAB. Suppose the distribution for X is expressed in the row vectors X and P X .

  • We perform array operations on vector X to obtain
    G = [ g ( t 1 ) g ( t 2 ) g ( t n ) ]
  • We use relational and logical operations on G to obtain a matrix M which has ones for those t i (values of X ) such that g ( t i ) satisfies the desired condition (and zeros elsewhere).
  • The zero-one matrix M is used to select the the corresponding p i = P ( X = t i ) and sum them by the taking the dot product of M and P X .

Basic calculations for a function of a simple random variable

X = -5:10; % Values of X PX = ibinom(15,0.6,0:15); % Probabilities for XG = (X + 6).*(X - 1).*(X - 8); % Array operations on X matrix to get G = g(X) M = (G>- 100)&(G<130); % Relational and logical operations on G PM = M*PX' % Sum of probabilities for selected valuesPM = 0.4800 disp([X;G;M;PX]') % Display of various matrices (as columns) -5.0000 78.0000 1.0000 0.0000-4.0000 120.0000 1.0000 0.0000 -3.0000 132.0000 0 0.0003-2.0000 120.0000 1.0000 0.0016 -1.0000 90.0000 1.0000 0.00740 48.0000 1.0000 0.0245 1.0000 0 1.0000 0.06122.0000 -48.0000 1.0000 0.1181 3.0000 -90.0000 1.0000 0.17714.0000 -120.0000 0 0.2066 5.0000 -132.0000 0 0.18596.0000 -120.0000 0 0.1268 7.0000 -78.0000 1.0000 0.06348.0000 0 1.0000 0.0219 9.0000 120.0000 1.0000 0.004710.0000 288.0000 0 0.0005 [Z,PZ]= csort(G,PX); % Sorting and consolidating to obtaindisp([Z;PZ]') % the distribution for Z = g(X)-132.0000 0.1859 -120.0000 0.3334-90.0000 0.1771 -78.0000 0.0634-48.0000 0.1181 0 0.083248.0000 0.0245 78.0000 0.000090.0000 0.0074 120.0000 0.0064132.0000 0.0003 288.0000 0.0005P1 = (G<-120)*PX ' % Further calculation using G, PX P1 = 0.1859p1 = (Z<-120)*PZ' % Alternate using Z, PZ p1 = 0.1859
Got questions? Get instant answers now!

X = 10 I A + 18 I B + 10 I C with { A , B , C } independent and P = [ 0 . 6 0 . 3 0 . 5 ] .

We calculate the distribution for X , then determine the distribution for

Z = X 1 / 2 - X + 50
c = [10 18 10 0];pm = minprob(0.1*[6 3 5]);canonic Enter row vector of coefficients cEnter row vector of minterm probabilities pm Use row matrices X and PX for calculationsCall for XDBN to view the distribution disp(XDBN)0 0.1400 10.0000 0.350018.0000 0.0600 20.0000 0.210028.0000 0.1500 38.0000 0.0900G = sqrt(X) - X + 50; % Formation of G matrix [Z,PZ]= csort(G,PX); % Sorts distinct values of g(X) disp([Z;PZ]') % consolidates probabilities 18.1644 0.090027.2915 0.1500 34.4721 0.210036.2426 0.0600 43.1623 0.350050.0000 0.1400 M = (Z<20)|(Z>= 40) % Direct use of Z distribution M = 1 0 0 0 1 1PZM = M*PZ' PZM = 0.5800
Got questions? Get instant answers now!

Remark . Note that with the m-function csort, we may name the output as desired.

Continuation of [link] , above.

H = 2*X.^2 - 3*X + 1; [W,PW]= csort(H,PX) W = 1 171 595 741 1485 2775PW = 0.1400 0.3500 0.0600 0.2100 0.1500 0.0900
Got questions? Get instant answers now!

A discrete approximation

Suppose X has density function f X ( t ) = 1 2 ( 3 t 2 + 2 t ) for 0 t 1 . Then F X ( t ) = 1 2 ( t 3 + t 2 ) . Let Z = X 1 / 2 . We may use the approximation m-procedure tappr to obtain an approximate discrete distribution. Then we work with theapproximating random variable as a simple random variable. Suppose we want P ( Z 0 . 8 ) . Now Z 0 . 8 iff X 0 . 8 2 = 0 . 64 . The desired probability may be calculated to be

P ( Z 0 . 8 ) = F X ( 0 . 64 ) = ( 0 . 64 3 + 0 . 64 2 ) / 2 = 0 . 3359

Using the approximation procedure, we have

tappr Enter matrix [a b]of x-range endpoints [0 1] Enter number of x approximation points 200Enter density as a function of t (3*t.^2 + 2*t)/2 Use row matrices X and PX as in the simple caseG = X.^(1/2); M = G<= 0.8; PM = M*PX'PM = 0.3359 % Agrees quite closely with the theoretical
Got questions? Get instant answers now!

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Applied probability. OpenStax CNX. Aug 31, 2009 Download for free at http://cnx.org/content/col10708/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Applied probability' conversation and receive update notifications?

Ask