function[V]=vec_var(x)

% PURPOSE: re-arranges the elements of vector x into a variance matrix according to the following rule: 
% example: V is supposed to be 3 by 3; x was created using chol_vec, and has 6 unique elements
% then: x(1)=V(1,1), x(2) = V(2,1), x(3)=V(2,2), x(4)=V(3,1) etc
%
% SEE ALSO: chol_vec, vec_chol
%
% Written by:
% Klaus Moeltner
% Department of Applied Economics & Statistics
% University of Nevada, Reno
% moeltner@cabnr.unr.edu


l= length(x);
c=0.5*(-1+sqrt(1+8*l)); % dimension of V
V=zeros(c,c);

j=c;
 while j>0;
    V(j,1:j)=x(end-j+1:end)';
    x(end-j+1:end)=[];
    j=j-1;
  end

u=diag(-diag(V));
V=V+u+V';
  




