Code covered by the BSD License  

Highlights from
Generation of Random Variates

image thumbnail

Generation of Random Variates

by

James Huntley (view profile)

 

generates random variates from over 870 univariate distributions

trap_cdf(x, a, b, c, d)
% trap_cdf.m - evaluates a Cumulative Trapazoidal Distribution.
%   See "Dataplot Reference Manual, TRACDF", NIST, 2/3/4.
%
%  Created by Jim Huntley,  8/2/4
%
%

function [cdf] = trap_cdf(x, a, b, c, d)

u = 2/(d+c-b-a);
if(x < a)
    cdf = 0;
elseif(x >= a & x < b)
    %cdf = ((b-a)/u)*((x-a)/(b-a))^2;
    cdf = 0.5 * u * (x-a)^2 / (b-a);
elseif(x >= b & x < c)
    %cdf = ((b-a) + 2*(x-b))/u;
    cdf =  u * (x - 0.5*b - 0.5*a);
elseif(x >= c & x < d)
    %cdf = 1 - ((d-c)/u)*((d-x)/(d-c))^2;
    cdf = u * (c - 0.5*b + 0.5*a + 0.5*(2*d*x - 2*d*c - x^2 + c^2)/(d-c));
elseif(x >= d)
    cdf = 1;
end

return

Contact us