function F = triangular_cdf(X, params )
%    F = triangular_cdf(X, [ a, b, c ] )
% 
%    Return the CDF of a triangular distribution with parameters a,b, and c
%    with limits a < X < b, and mode c, which must be scalars.
%
%    Reference:   http://en.wikipedia.org/wiki/Triangular_distribution

 a = params(1);
 b = params(2);
 c = params(3);

 F = zeros(size(X));

 idxA = find(X>a);
 idxB = find(X>b);
 idxC = find(X>c);

 F(idxA) = (X-a).^2/((b-a)*(c-a));
 F(idxC) = 1 - (b-X(idxC)).^2/((b-a)*(b-c));
 F(idxB) = 1;

% triangular_cdf --------------------------------------- 30 March 2011
