function [out1, out2, out3]=rossler(t,X,flag,param)
%
%  Rossler's equation 
%
%               dx/dt = -y-z
%               dy/dt = x+a*y
%               dz/dt= b+z*(x-c)
%
% a = 0.2;
% b = 0.2;
% c = 5.7;

a=param(1);
b=param(2);
c=param(3);

x=X(1);y=X(2);z=X(3);

if nargin < 3 || isempty(flag)
out1 = [-y-z;
        x+a*y;
        b+z*(x-c)];
else
   switch(flag)
   case 'init'
     out1 = [0; 1];
     out2 = [0 0 0];
     out3 = []; 
     case 'events' 
     sec1 = -y-z; 
     sec2 = x+a*y;
     sec3 = b+z*(x-c);
     out1 = [sec2];
     out2 = [0];
     out3 = [1];
   otherwise
      error(['Unknown flag ''' flag ''.']);
   end

end
