% Antti Hannukainen
%
% Phase condition for 
%
%

function y = phase_condition(u, u0, t)

N=length(t);

x  = bvp_u2x(u,N);
x0 = bvp_u2x(u0,N);

y = 0;

for i=1:1:(size(x,2)-1)
  y = y + dot( 0.5*( x(:,i) + x(:,i+1) ), ( x0(:,i) - x0(:,i+1)) )*( t(i+1)-t(i) );
end


