Main Content

iwishrnd

Inverse Wishart random numbers

Description

W = iwishrnd(Tau,nu) generates a matrix of random numbers drawn from an inverse Wishart distribution with the covariance parameter Tau and nu degrees of freedom. The inverse of W has the Wishart distribution with the covariance matrix Sigma = inv(Tau) and nu degrees of freedom.

example

[W,DInvOut] = iwishrnd(Tau,nu) also returns the transpose of the inverse of the Cholesky factor of Tau.

W = iwishrnd(Tau,nu,DInv) specifies the transpose of the inverse of the Cholesky factor of Tau, such that DInv'*DInv = inv(Tau), where inv is the MATLAB® inverse function.

Examples

collapse all

Generate a random 3-by-3 covariance matrix Sigma that is symmetric and positive definite.

rng(0,"twister") % For reproducibility
n = 3; % Number of dimensions
A = randn(n);
Sigma = A'*A
Sigma = 3×3

    8.7546    4.0020   -7.6878
    4.0020    2.5550   -4.9440
   -7.6878   -4.9440   13.1103

Generate a matrix of random numbers from a Wishart distribution with the covariance parameter Tau = inv(Sigma) and four degrees of freedom. Compute and return DInvOut, which is the transpose of the inverse of the Cholesky factor of Tau.

Tau = inv(Sigma);
[W,DInvOut] = wishrnd(Tau,4)
W = 3×3

    7.7374  -13.7703    0.5726
  -13.7703   25.0777   -0.4004
    0.5726   -0.4004    0.7412

DInvOut = 3×3

    0.6343   -1.0131   -0.0101
         0    1.2034    0.4538
         0         0    0.2762

Use DInvOut to generate another matrix of random numbers from an inverse Wishart distribution that has the same covariance parameter and degrees of freedom.

W2 = wishrnd(Tau,4,DInvOut)
W2 = 3×3

    1.9593   -3.9527   -0.4827
   -3.9527   10.2019    1.7097
   -0.4827    1.7097    0.6420

Input Arguments

collapse all

Covariance parameter, specified as a d-by-d symmetric, positive definite matrix, where d is the dimension of the inverse Wishart distribution. The inverse of W has the Wishart distribution with the covariance matrix Sigma = inv(Tau) and nu degrees of freedom.

Data Types: single | double

Degrees of freedom, specified as a positive scalar.

Data Types: single | double

Transpose of the inverse of the Cholesky factor of Tau, specified as a lower-triangular numeric matrix with the same dimensions as Tau. When you specify this argument, the software uses the value of DInv instead of computing it directly from Tau according to the expression DInv'*DInv = inv(Tau).

Data Types: single | double

Output Arguments

collapse all

Inverse Wishart random numbers, returned as an array of scalar values with the same dimensions as Tau. The expected value of W is equal to Tau/(nu – d – 1), where d is the dimension of Tau.

Transpose of the inverse of the Cholesky factor of Tau, returned as an array of scalar values with the same dimensions as Tau. DInv is defined by DInv'*DInv = inv(Tau), where inv is the MATLAB inverse function.

Version History

Introduced before R2006a