function ttt = mvtpdf_klaus (x,u,vcov,v)
%
%
% PURPOSE: evaluates the multivariate t with location u, scale vcov, and
% dof v at vector x
% this is my own version, since Mlab's mvtpdf uses a mean of zero and a
% correlation matrix
% This follows exactly Gelman's exposition p. 574
%---------------------------------------------------
% INPUTS: 
% where: x = k by 1 vector of t variates
%        u = location vector length k
%        vcov = scale matrix (k by k), must ne pos. def.
%        v = degrees of freedom
%---------------------------------------------------
% OUTPUT:
%        a scalar evaluating the mvt at x      
%
%
% written by:
% Klaus Moeltner
% University of Nevada, Reno


k=length(x);
% 
% ttt=((gamma((v+k)/2))/(gamma(v/2)*(v^k/2)*(pi^k/2)))*...
%     ((det(vcov))^(-1/2))*(1+(1/v)*(x-u)'*inv(vcov)*(x-u))^(-(v+k)/2);

% ttt=exp((gammaln((v+k)/2))-(gammaln(v/2)+log(v^k/2)+log(pi^k/2)))*...
%     ((det(vcov))^(-1/2))*(1+(1/v)*((x-u)'*inv(vcov))*(x-u))^(-(v+k)/2);

%more precise than inv:
ttt=exp((gammaln((v+k)/2))-(gammaln(v/2)+(k/2)*log(v)+(k/2)*log(pi)))*...
    ((det(vcov))^(-1/2))*(1+(1/v)*((x-u)'/(vcov))*(x-u))^(-(v+k)/2);






