function mom_thrd=mom_thrd(YY)   
%function mom_thrd=mom_thrd(YY)   
% Calculates the third moment of stochastic coefficients E[YiYjYk] from Monte-
% Carlo samples. 
%
% INPUTS:
%	YY: 	   Array with Monte Carlo Samples size(YY) = [MC,NS], where
%                   MC is the number of Monte-Carlo samples and NS is the size of
%                   stochastic dimension. 
% OUTPUTS:
%	mom_thrd:  3D array containing the third moments. 
%	            E[YiYjYk] = mom_thd(i,j,k)
%
% Author: Themis Sapsis, Matt Ueckermann

NS=size(YY,2);
MC=size(YY,1);
mom_thrd = zeros(NS,NS,NS);
for j1=1:NS
    for j2=1:NS
        for j3=1:NS
            mom_thrd(j1,j2,j3)=sum(YY(:,j1).*YY(:,j2).*(YY(:,j3)))/MC;            
        end
    end
end
