Sets up table to generate pseudorandom numbers from a general continuous distribution.
void imsls_f_continuous_table_setup (float cdf(), int iopt, int ndata, float *table, ..., 0)
The type double function is imsls_d_continuous_table_setup.
float cdf(float x)
(Input)
User-supplied function to compute the cumulative distribution function. The argument
to the function is the point at which the distribution function is to be
evaluated
int iopt
(Input)
Indicator of the extent to which table is initialized prior to calling imsls_f_continuous_table_setup.
0 imsls_f_continuous_table_setup fills the last four columns of table. The user inputs the points at which the CDF is to be evaluated in the first column of table. These must be in ascending order.
1 imsls_f_continuous_table_setup fills the last three columns of table. The user supplied function cdf is not used and may be a dummy function; instead, the cumulative distribution function is specified in the first two columns of table. The abscissas (in the first column) must be in ascending order and the function must be strictly monotonically increasing.
int ndata
(Input)
Number of points at which the CDF is
evaluated for interpolation. ndata must be greater than or equal to 4.
float *table
(Input/Ouput)
ndata by 5 table to be used for interpolation of the cumulative
distribution function.
The first column of table contains abscissas of the cumulative distribution function
in ascending order, the second column contains the values of the CDF (which must
be strictly increasing), and the remaining columns contain values used in
interpolation. The first row of table corresponds to the left limit of the support of the
distribution and the
last row corresponds to the right limit of the support;
that is,
table[0][1] = 0.0 and table[ndata-1][ 1] = 1.0.
void
imsls_f_continuous_table_setup (float
cdf(), int
iopt,
int ndata, float
table[],
IMSLS_TABLE_COL_DIM,
IMSLS_FCN_W_DATA,
float cdf(), void
*data,
0)
IMSLS_TABLE_COL_DIM, int
table_col_dim (Intput)
Column
dimension of the array table.
Default:
table_col_dim = 5
IMSLS_FCN_W_DATA, float cdf(float x), void *data,
(Input)
User-supplied function to compute the cumulative distribution function, which also accepts
a pointer to data that is supplied by the user. data is a pointer to
the data to be passed to the user-supplied function. See the
Introduction, Passing Data to User-Supplied Functions at the beginning of
this manual for more details.
Routine imsls_f_continuous_table_setup sets up a table that routine imsls_f_random_general_continuous can use to generate pseudorandom deviates from a continuous distribution. The distribution is specified by its cumulative distribution function, which can be supplied either in tabular form in table or by a function cdf. See the documentation for the routine imsls_f_random_general_continuous for a description of the method.
In this example, imsls_f_continuous_table_setup is used to set up a
table to generate pseudorandom
variates from a beta distribution. This example
is continued in the
documentation for routine imsls_f_random_general_continuous to generate the random variates.
imsls_f_continuous_table_setup(cdf, iopt, ndata, table);
printf("The first few values from the table:\n");
for (i=0;i<10;i++) printf("%4.2f\t%8.4f\n", table[i][0], table[i][1]);
return imsls_f_beta_cdf(x, 3., 2.);
*** WARNING Error from imsls_f_continuous_table_setup. The values of the
*** CDF in the second column of table did not begin at 0.0 and end
*** at 1.0, but they have been adjusted. Prior to adjustment,
*** table[0][1] = 0.000000e+00 and table[ndata-1][1]= 9.994079e-01.
The first few values from the table:
Visual Numerics, Inc. PHONE: 713.784.3131 FAX:713.781.9260 |