function f = triangular_pdf(X,a,b,c)
%    f = triangular_pdf(X,a,b,c)
% 
%    Return the PDF 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

 f = zeros(size(X));

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

 f(idxA) = 2*(X-a)/((b-a)*(c-a));
 f(idxC) = 2*(b-X(idxC))/((b-a)*(b-c));
 f(idxB) = 0;

% ----------------------------------------------------------  triangular_pdf
