function [abserr,relerr] = ricchk(beta,A,B,Q,R,W,p)
%RICCHK  Check on solution to Riccati matrix equation.
%        error=ricchk(p) calculates the error in computing p from:
%        
%        p= beta*A'*p*A + Q -(beta*A'*p*B+W)*(R+beta*B'*p*B)^{-1} ..
%                                               *(beta*B'*p*A+W')    
%

%        Ellen R. McGrattan, 11-30-88
%        
C=beta*B'*p*A+W';
abserr=beta*A'*p*A + Q -C'*((R+beta*B'*p*B)\C) -p;
relerr=abserr./(1+abs(p));
