Generates pseudorandom numbers from a multivariate normal distribution.
#include <imsls.h>
float *imsls_f_random_normal_multivariate (int n_vectors, int length, float *covariances, …, 0)
The type double function is imsls_d_random_normal_multivariate.
int n_vectors
(Input)
Number of random multivariate normal vectors to
generate.
int length
(Input)
Length of the multivariate normal vectors.
float
*covariances (Input)
Array of size length × length containing the
variance-covariance matrix.
An array of length n_vectors × length containing the random multivariate normal vectors stored consecutively.
#include <imsls.h>
float
*imsls_f_random_normal_multivariate (int
n_vectors, int length, float *covariances,
IMSLS_RETURN_USER, float
r[],
0)
IMSLS_RETURN_USER, float r[]
(Output)
User-supplied array of length n_vectors × length containing the
random multivariate normal vectors stored consecutively.
Function imsls_f_random_normal_multivariate generates pseudorandom numbers from a multivariate normal distribution with mean vector consisting of all zeros and variance-covariance matrix imsls_f_covariances. First, the Cholesky factor of the variance-covariance matrix is computed. Then, independent random normal deviates with mean 0 and variance 1 are generated, and the matrix containing these deviates is postmultiplied by the Cholesky factor. Because the Cholesky factorization is performed in each invocation, it is best to generate as many random vectors as needed at once.
Deviates from a multivariate normal distribution with means other than 0 can be generated by using imsls_f_random_normal_multivariate and then by adding the vectors of means to each row of the result.
In this example, imsls_f_random_normal_multivariate generates five pseudorandom normal vectors of length 2 with variance-covariance matrix equal to the following:
#include <imsls.h>
int main()
{
int n_vectors = 5;
int length = 2;
float covariances[] = {.5, .375, .375, .5};
float *random;
imsls_random_seed_set (123457);
random = imsls_f_random_normal_multivariate (n_vectors, length,
covariances, 0);
imsls_f_write_matrix ("multivariate normal random deviates",
n_vectors, length, random, 0);
}
multivariate normal random deviates
1 2
1 1.451 1.246
2 0.766 -0.043
3 0.058 -0.669
4 0.903 0.463
5 -0.867 -0.933
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |