function [mean1, var1] = alog_1(data,n)

index1 = cluster(data',n);
[m,n] = size(data);

if m==1
figure
subplot(2,2,1)

for i =1:n
	n_1 = find(index1 ==i);
	plot(data(n_1), zeros(length(n_1)));
end;
end;


%%%%%%%%%%%%%%
if m==2
figure
subplot(2,2,1)

for i =1:n
	n_1 = find(index1 ==i);
	plot(data(1,n_1), data(2, n_1));
	axis([-10 10 -10 10])

end;
end;
%%%%%%%%%%%%%%%%

total =0;

m_1 = zeros(size(index1)); 
m_2 = ones(size(index1));

while ~isequal(m_1,m_2)
    m_1=m_2;
    
    for j=1:n,
        n_1 = find(index1 ==j);
        if length(index1)==1
            mean1(:,j)=data(:,index1');
            var1(:,j)=data(:,index1)'
        else
            mean1(:,j)=mean(data(:,index1)')';
            var1(:,j)=var(data(:,index1)')';
        end;
    end;
    %norm(data(:, index1)-mean1(:,i)*ones(size(index1)))
    errs = distance1(data(:,index1),mean1(:,j));
    sum1(j) = sum((errs.^2));  
end;

sse(total+1) = sum(sum1');

for k=1:n,
    v1 = distance2(mean1, data(:,k));
    [s1,s2]=min(v1);
    index1(k)=s2;
end;

m_2 = index1;
total = total+1;



[x1,x2] = find(index1==1);
r1 = length(x1)/n;
r2=1-r1;


%%%%%%%%%%%%%%%%%%%%%%%%%

if m==2,
    subplot(2,2,2)
    for i=1:n,
       	n_1 = find(index1 ==i);
    	plot(data(1,n_1), data(2,n_1));
        axis([-10 10 -10 10])
    end;
    subplot(2,2,3)
    plot(1:total,sse)
    xlabel('m')
    ylabel('SSE')
end;


if m==1
    subplot(2,2,2)
    for i=1:n,
        n_1 = find(index1 ==i);
    	plot(data(n_1), zeros(length(n_1)));
    end;


subplot(2,2,3)
plot(1:total,sse)
    xlabel('m')
    ylabel('SSE')


end;

