This program has been developed in a research project at Risklab, Toronto. (c) Benedikt Rudolph, 2012
0001 % This program has been developed in a research project at Risklab, Toronto. 0002 % (c) Benedikt Rudolph, 2012 0003 0004 function M = vector_to_symmetric(v, d) 0005 % Transforms the vector v into the symmetric d x d matrix M 0006 % by interpreting v as the stacked columns of the lower triangular. 0007 % 0008 % It is expected that 0.5*d*(d+1) == length(v), 0009 % otherwise an error will occur. 0010 % 0011 % M = vector_to_symmetric(v, d) 0012 0013 M = zeros(d); % init M 0014 M(logical(tril(ones(d)))) = v; % set lower triangular to v 0015 M = M + tril(M,-1)'; % add upper triangular symmetrically 0016 end