<< Chapter < Page | Chapter >> Page > |
mgsumn.m
function [z,pz] = mgsumn(varargin)
is an alternate to mgnsum,
utilizing
varargin in MATLAB version 5.1.
The call is of the form
[z,pz] = mgsumn([x1;p1],[x2;p2], ..., [xn;pn])
.
function [z,pz] = mgsumn(varargin)% MGSUMN [z,pz] = mgsumn([x1;p1],[x2;p2], ..., [xn;pn])
% Version of 6/2/97 Uses MATLAB version 5.1% Sum of n independent simple random variables
% Utilizes distributions in the form [x;px](two rows)
% Iterates mgsumn = length(varargin); % The number of distributions
z = 0; % Initializationpz = 1;
for i = 1:n % Repeated use of mgsum[z,pz] = mgsum(z,varargin{i}(1,:),pz,varargin{i}(2,:));end
diidsum.m
function [x,px] = diidsum(X,PX,n)
determines the sum of
n iid
simple random variables, with the common distribution
.
function [x,px] = diidsum(X,PX,n)% DIIDSUM [x,px] = diidsum(X,PX,n) Sum of n iid simple random variables% Version of 10/14/95 Input rev 5/13/97
% Sum of n iid rv with common distribution X, PX% Uses m-function mgsum
x = X; % Initializationpx = PX;
for i = 1:n-1[x,px] = mgsum(x,X,px,PX);end
itest.m Tests for independence the matrix P of joint probabilities for a simple pair of random variables.
% ITEST file itest.m Tests P for independence
% Version of 5/9/95% Tests for independence the matrix of joint
% probabilities for a simple pair {X,Y}pt = input('Enter matrix of joint probabilities ');
disp(' ')px = sum(pt); % Marginal probabilities for X
py = sum(pt'); % Marginal probabilities for Y (reversed)[a,b] = meshgrid(px,py);PT = a.*b; % Joint independent probabilities
D = abs(pt - PT)>1e-9; % Threshold set above roundoff
if total(D)>0
disp('The pair {X,Y} is NOT independent')disp('To see where the product rule fails, call for D')
elsedisp('The pair {X,Y} is independent')
end
idbn.m
function p = idbn(px,py)
uses marginal probabilities to determine
the joint probability matrix (arranged as on the plane) for an independent pair of simple randomvariables.
function p = idbn(px,py)
% IDBN p = idbn(px,py) Matrix of joint independent probabilities% Version of 5/9/95
% Determines joint probability matrix for two independent% simple random variables (arranged as on the plane)
[a,b]= meshgrid(px,fliplr(py));
p = a.*b
isimple.m Takes as inputs the marginal distributions for an independent pair of simple random variables. Sets up the joint distribution probability matrix P as in idbn , and forms the calculating matrices as in jcalc . Calculates basic quantities and makes available matrices for additional calculations.
% ISIMPLE file isimple.m Calculations for independent simple rv
% Version of 5/3/95X = input('Enter row matrix of X-values ');
Y = input('Enter row matrix of Y-values ');PX = input('Enter X probabilities ');
PY = input('Enter Y probabilities ');[a,b] = meshgrid(PX,fliplr(PY));P = a.*b; % Matrix of joint independent probabilities
[t,u]= meshgrid(X,fliplr(Y)); % t, u matrices for joint calculations
EX = dot(X,PX) % E[X]EY = dot(Y,PY) % E[Y]
VX = dot(X.^2,PX) - EX^2 % Var[X]VY = dot(Y.^2,PY) - EY^2 % Var[Y]
disp(' Use array operations on matrices X, Y, PX, PY, t, u, and P')
Notification Switch
Would you like to follow the 'Applied probability' conversation and receive update notifications?