%
%  Function to evaluate the Riccati equation 
%     dS = A^TS + SA - SBR^{-1}B^TS + Q
%  as a vector function.
%
function dSv = ricf(t,S,par)
   global Ah Qh Rh
   
   n = size(Ah,1);
   Sm = rtri(S,n);
   Sm = Sm + (Sm-diag(diag(Sm))).';   
   dS = Ah.'*Sm + Sm*Ah - Sm*Rh*Sm + Qh;
   dSv = vtri(dS);
end
