function [tt,qq]=qss1(f,x0,t0,tf,dq)
  [fi,nSD,SD]=f();
  x=x0;
  q=x0;
  t=t0;
  tnext=zeros(x0);
  tlast=zeros(x0);
  n=length(x0);
  dx=zeros(x0);
  k=1;
  qq=zeros(n,10000);
  tt=zeros(1,10000)
  qq(:,1)=q;
  tt(1)=t0;
  inf=tf;
  for i=1:n
      tlast(i)=t;
      dx(i)=fi(q,t,i);
      if dx(i)<>0 then
          tnext(i)=t+abs(dq/dx(i));
      else
          tnext(i)=inf;
      end
  end
  while t<tf
     [t,i]=min(tnext);
     x(i)=x(i)+(t-tlast(i))*dx(i);
     q(i)=x(i);
     tlast(i)=t;
     tnext(i)=t+abs(dq/dx(i))
     for l=1:nSD(i)
         j=SD(l);
         x(j)=x(j)+(t-tlast(j))*dx(j);
         tlast(j)=t;
         dx(j)=fi(q,t,j);
         if dx(j)>0 then
            tnext(j)=t+(q(j)+dq-x(j))/dx(j);
         elseif dx(j)<0 then
            tnext(j)=t+(x(j)-(q(j)-dq))/(-dx(j));
         else
             tnext(j)=inf;
        end 
        if tnext(j)>inf then 
            tnext(j)=inf;
        end
             
      end  
     k=k+1;             
     qq(:,k)=q;
     tt(k)=t;
  end
  qq=qq(:,1:k);
  tt=tt(1:k);
endfunction
