Home > wafo > wstats > mdist2drnd.m

# mdist2drnd

## PURPOSE

Random points from a bivariate MDIST2D distribution

## SYNOPSIS

[V,H,ind] = mdist2drnd(N,phat)

## DESCRIPTION

``` MDIST2DRND  Random points from a bivariate MDIST2D distribution

CALL:  [R1,R2] = dist2drnd(N,phat);

R1,R2   = N random points in R^2.
N       = number of points generated
phat    = parameter structure array (see mdist2dfit)

Example: Random points from a 2D Rayleigh distribution
x1=linspace(0,10)';
phat.x={1 2  2 };
phat.dist={'rayl','rayl'};
[y1,y2] = mdist2drnd(1000,phat);
f = mdist2dpdf2(x1,x1,phat);
pdfplot(f), hold on
plot(y1,y2,'.'), hold off

## CROSS-REFERENCE INFORMATION

This function calls:
 mdist2dcinv Inverse of the conditional cdf of X2 given X1. wgamrnd Random matrices from a Gamma distribution. wgumbrnd Random matrices from a Gumbel distribution. wlognrnd Random matrices from a Lognormal distribution. wraylrnd Random matrices from a Rayleigh distribution wweibrnd Random matrices a the Weibull distribution. error Display message and abort function. lower Convert string to lowercase.
This function is called by:

## SOURCE CODE

```001 function [V,H,ind] = mdist2drnd(N,phat)
002 %MDIST2DRND  Random points from a bivariate MDIST2D distribution
003 %
004 % CALL:  [R1,R2] = dist2drnd(N,phat);
005 %
006 %     R1,R2   = N random points in R^2.
007 %     N       = number of points generated
008 %     phat    = parameter structure array (see mdist2dfit)
009 %
010 %Example: Random points from a 2D Rayleigh distribution
011 %    x1=linspace(0,10)';
012 %    phat.x={1 2  2 };
013 %    phat.dist={'rayl','rayl'};
014 %    [y1,y2] = mdist2drnd(1000,phat);
015 %    f = mdist2dpdf2(x1,x1,phat);
016 %    pdfplot(f), hold on
017 %    plot(y1,y2,'.'), hold off
018 %
020
021
022 %   References:
023 %      [1]  Michel K. Ochi,
024 %       OCEAN TECHNOLOGY series 6
025 %      "OCEAN WAVES, The stochastic approach", Cambridge
026 %      1998 p. 133-134.
027
028 %  tested on: matlab 5.2
029 % history
030 % revised pab 8.11.1999
031 %  - updated header info
032 %  - changed phat from vector to structure
033 %  Per A. Brodtkorb 28.01.99
034
035 if (nargin < 2),
036   error('Requires two input arguments.');
037 end
038
039 VDIST=lower(phat.dist{1});
040 HDIST=lower(phat.dist{2});
041
042 psi=phat.x{3};
043 switch VDIST(1:2),
044   case 'ra', nv=1;
045  otherwise, nv=2;
046 end
047 switch HDIST(1:2),
048   case 'ra', nh=1;
049  otherwise, nh=2;
050 end
051 PV=phat.x{1};
052 PH=phat.x{2};
053 if nv+nh~=length(PV)+length(PH)
054  error('param is not the right size')
055 end
056
057 % V is distributed
058 switch VDIST(1:2),
059   case 'ra', V=wraylrnd(PV(ones(N,1),:));
060   case 'we', V=wweibrnd(PV(ones(N,1),1) , PV(ones(N,1),2));
061   case 'tg', V=wgumbrnd(PV(ones(N,1),1) , PV(ones(N,1),2),[],[],1);
062   case 'gu', V=wgumbrnd(PV(ones(N,1),1) , PV(ones(N,1),2),[],[],0);
063   case 'lo', V=wlognrnd(PV(ones(N,1),1) , PV(ones(N,1),2));
064   case 'ga', V=wgamrnd(PV(ones(N,1),1) , PV(ones(N,1),2));
065   otherwise , error('unknown distribution')
066 end
067
068
069 % perform a direct inversion by newton
070 P=rand(N,1);
071 [H ind]=mdist2dcinv(V ,P,phat); % Inverse of the 2D  cdf given V . slow
072
073
074
075
076```

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