% OUTPUT:
%
% A (nX2) matrix.  The first column contains the 
% values for a random variable that comes from a 
% a mixture of three normals.  Its density is given 
% by (9/20)N(-6/5,9/25) + (9/20) N(6/5,9/25)+2/20 N(0,1/16).  The first moment
% of this density is 0 =(9/20) (-6/5) + (9/20)(6/5)+(2/20)+(2/20)*(0) and the second
% raw moment is (9/20) mu_{1,2} +(9/20) mu_{2,2}+(2/20)mu_{3,2}, where 
% mu_{i,2} is the second raw moment of the ith normal.


function [tm f_tm] = mixnormtrimodal(n)
    
x1   = -6/5 + (3/5)*randn(n,1);
x2   = 6/5  + (3/5)*randn(n,1);
x3   =        (1/4)*randn(n,1);
u = rand(n,1);

i_1 = (u < 9/20);
i_2 = (9/20 <= u ) & (u < 18/20);
i_3 = (u>=18/20);
tm   = i_1.*x1 + i_2.*x2+ i_3.*x3;
f_tm =  (9/20)*(  sqrt(2*pi)*(3/5)  )^(-1).*exp( -0.5*( (tm-(-6/5)).^2/(9/25)  ))+ (9/20)*(  sqrt(2*pi)*(3/5)  )^(-1).*exp( -0.5*( (tm-( 6/5)).^2/(9/25)  ))+ (2/20)*(  sqrt(2*pi)*(1/4)  )^(-1).*exp( -0.5*( (tm).^2/(1/16)  ));






