function out = tnormpdf(mu,sig,l,r,x)
%
%
% PURPOSE: returns the density of a truncated normal
% distribution with mean (vector) u, standard deviation sig, and 
% left and right truncation points (or vectors) l and r, at point "x".
%---------------------------------------------------
% INPUTS: 
% where: mu = mean or mean vector of the (untruncated) normal
%        sig = standard deviation (can be a vector if sig is unequal across
%        observations)
%        l = left trunction point or vector (must be of same length as mu)
%        r = right truncation point or vector (must be of same length as
%        mu)
%        x = value of random variable (or vector of RVs) for which the density is sought
%        (must be the same length of mu)
%---------------------------------------------------
% OUTPUT:
% the value of the density (or vector of values)   
%
%
% written by:
% Klaus Moeltner
% University of Nevada, Reno

out= normpdf(x,mu,sig)./(normcdf(r,mu,sig)-normcdf(l,mu,sig)); % truncated density
  
  
  
  