
function [total] = totaldiff(phistar,B,covX,noexplode);
total = 0; 
for i = 2:5; 
    total = total+(B(i,:)-B(1,:)*phistar^(i-1))*covX*(B(i,:)-B(1,:)*phistar^(i-1))';
end;
if noexplode;
    test = max(abs(eig(phistar))) - 0.999;
    if test > 0; 
        total = total + 100*test;
    end
    %total = total+(B(1,:)*phistar^50)*(B(1,:)*phistar^50)'*10000000; % strong penalty for any eigenvalue >=1
end

