function [f, xx, uu, M] = solution(x0)
% SOLUTION Solves the SVC problem over a period. 
%          f == 0 <=> periodic solution
%
global m n tt b

if (nargout > 1), uu = []; xx = x0; end;
if (nargout > 3), M  = eye(n); end;
x = x0;
for k = 1:m,
   A = matrix(k-1);
   E = expm(A*(tt(k+1)-tt(k)));
   u = (A-i*eye(n))\b;
   x = E*(x+2*real(u*exp(i*tt(k)))) ...
          - 2*real(u*exp(i*tt(k+1)));
   if (nargout > 1), uu = [uu,u]; xx = [xx,x]; end;
   if (nargout > 3), M  = E*M; end;
end; 
f = x - x0;

% end solution

