function a=symunpck(p,n)
%function a=symunpck(p,[n])
% reforms first lower diag matrix a from vector	in p
% then full symmetric matrix
% p contains cols of original a without zeros on upper triangle
% n is order of a, p must contain full lower triangle as a vector
% If n not given it is calculated from length of p=n(n+1)/2

%Arthur Jutan 
%Dept of Chemical and Biochemical Enginering
%Univ of Western Ontario
%London Ontario Canada, N6A 5B9

if nargin==1,n=(-1 + sqrt(1+ 8.* (length(p))))/2;,end
for i=1:n
a(:,i)=[zeros(i-1,1);p(1:n-i+1)];
p(1:n-i+1)=[]; %  cut of retreived part
end
% a is now lower diag. Can form full symmetric a as:
c=a+a';% c is almost full symm but diag valuels 2* true values
d=diag(diag(c)); % gives diag matrix with 2*diagonal values
a=c-d/2;
return
