Home > wafo > wstats > wchi2rnd.m

wchi2rnd

PURPOSE ^

Random matrices from a Chi squared distribution.

SYNOPSIS ^

R = wchi2rnd(p,varargin);

DESCRIPTION ^

 WCHI2RND Random matrices from a Chi squared distribution. 
  
   CALL:  R = wchi2rnd(p,sz); 
  
          p = degrees of freedom, p=1,2,3,... 
         sz = size(R)    (Default size(p)) 
              sz is a comma separated list or a vector  
              giving the size of R (see zeros for options). 
  
   The Chi squared distribution is a special case of  
   the gamma distribution. Thus the wgamrnd is used to 
   generate R. 
  
  Example: 
    R=wchi2rnd(2,1,100); 
    plot(R,'.') 
  
  See also  wgamrnd

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

001 function R = wchi2rnd(p,varargin); 
002 %WCHI2RND Random matrices from a Chi squared distribution. 
003 % 
004 %  CALL:  R = wchi2rnd(p,sz); 
005 % 
006 %         p = degrees of freedom, p=1,2,3,... 
007 %        sz = size(R)    (Default size(p)) 
008 %             sz is a comma separated list or a vector  
009 %             giving the size of R (see zeros for options). 
010 % 
011 %  The Chi squared distribution is a special case of  
012 %  the gamma distribution. Thus the wgamrnd is used to 
013 %  generate R. 
014 % 
015 % Example: 
016 %   R=wchi2rnd(2,1,100); 
017 %   plot(R,'.') 
018 % 
019 % See also  wgamrnd 
020  
021 % Reference: Johnson, Kotz and Balakrishnan (1994) 
022 % "Continuous Univariate Distributions, vol. 1", p. 415 ff 
023 % Wiley 
024  
025 % Tested on; Matlab 5.3 
026 % History:  
027 % revised pab Dec2003 
028 % removed old call 
029 % revised pab 25.10.2000 
030 % - replaced code with a call to wgamrnd 
031 % added ms 26.06.2000 
032  
033 error(nargchk(1,inf,nargin)) 
034  
035 if nargin>1, 
036   [errorcode p] = comnsize(p,zeros(varargin{:})); 
037   if errorcode > 0 
038     error('p must be a scalar or comply to the size given.'); 
039   end 
040 end 
041  
042 R = wgamrnd(p/2,2); 
043  
044 k1=find(p~=round(p)|p<=0); 
045 if any(k1) 
046   warning('p must be a positive integer') 
047   tmp=NaN; 
048   R(k1)=tmp(ones(size(k1))); 
049 end 
050  
051 return 
052  
053  
054  
055  
056  
057

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group


Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003