Algebraic Manipulation of Random Variables (Numerical)
% [z zC Z ZC] = transRV(jointXY,C,opp,n) Numerically approximate the PDF of
% a nonlinear combination of the random variables X and Y given the joint
% distribution of X and Y. The joint distribution (jointXY) should be
% generated using [jointXY, C] = hist3([x(:) y(:)]). 
% 
% z = transRV(jointXY,C,opp,n) Use the opperation opp which can
% be: '+', '-', '*', or '/', to generate a PDF z of length n.
% 
% z = transRV(...,'ZLim',[minz maxz]) specify the limits on z.
% 
% z = transRV(...,'Visual') display the area of integration and CDF of Z.
% 
% [z zC Z ZC zlim] = transRV(...) returns the PDF z with values centered at
% zC, and the CDF Z with values centered at ZC. Also returns the limits on
% z. 
% 
% NOTE: Results may be noisy if the output vector z has high resolution
% (larger n) than the input distribution.
% 
% EXAMPLE
% 
%     % Set the number of bins
%     n = 200;
% 
%     % Generate random variables
%     x = 2*randn(1000000,1);
%     y = .5*randn(1000000,1);
% 
%     % Display joint distribution
%     [jointXY C] = hist3([x y],[n n]);
%     figure; imagesc(C{1},C{2},jointXY');
%     set(gca,'YDir','normal')
% 
%     % Approximate new distribution
%     [z zC Z ZC zlim] = transRV(jointXY,C,'*',n,'ZLim',[-5,5],'Visual');
% 
%     % Compare to the distribution of data under the same opperation
%     zdata = x.*y;
%     [N xc] = hist(zdata(zdata >= zlim(1) & zdata <= zlim(2)),n);
%     bin_width = xc(2)-xc(1);
%     N = N/sum(N.*bin_width);
% 
%     figure; bar(xc,N,'hist')
%     hold on; plot(zC,z,'r')
%     legend('Dist of Data','Approximation')
% Created by Aaron Swan - Summer 2010
% MERS Lab - Brigham Young University
Cita come
Aaron Swan (2025). Algebraic Manipulation of Random Variables (Numerical) (https://it.mathworks.com/matlabcentral/fileexchange/28332-algebraic-manipulation-of-random-variables-numerical), MATLAB Central File Exchange. Recuperato .
Compatibilità della release di MATLAB
Compatibilità della piattaforma
Windows macOS LinuxCategorie
Tag
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Scopri Live Editor
Crea script con codice, output e testo formattato in un unico documento eseguibile.
