The triangular distribution has a PDF (probability density function) that is triangular in profile. The base of the triangle ranges from
to
and the PDF has a maximum value of
at
. If
then
with probability 1; otherwise the triangular distribution has PDF:
One of the initialization functions
nag_rand_init_repeat (g05kf) (for a repeatable sequence if computed sequentially) or
nag_rand_init_nonrepeat (g05kg) (for a non-repeatable sequence) must be called prior to the first call to
nag_rand_dist_triangular (g05sp).
None.
Not applicable.
None.
This example prints five pseudorandom numbers from a triangular distribution with parameters
,
and
, generated by a single call to
nag_rand_dist_triangular (g05sp), after initialization by
nag_rand_init_repeat (g05kf).
function g05sp_example
fprintf('g05sp example results\n\n');
seed = [int64(1762543)];
genid = int64(1);
subid = int64(1);
[state, ifail] = g05kf( ...
genid, subid, seed);
n = int64(5);
xmin = -1;
xmed = 0.5;
xmax = 1;
[state, x, ifail] = g05sp( ...
n, xmin, xmed, xmax, state);
disp('Variates');
disp(x);