function [xls, Pinv_new, q_new ] = rls( Pinv, q, a, y )
% function [xls, Pinv_new, q_new ] = rls( Pinv, a, y )
%
% Recursive least-squares estimator for solving y=Px.
% 'a' is a new row of matrix P, and 'y' is the associated target value.
%
% 'a' should be specified as a column vector.
%
% 'y' may be a row vector, in which case 'xls' will be a matrix.
%
% Two steps:
% Given a matrix P^-1 and a vector a, compute (P+aa')^-1.
% Compute q_new = q + a'*y
%
% Note: this version does not include a forgetting factor.
%
% D. Wingate 5/10/2006
%
tmp = Pinv*a;
c = 1/(1+a'*tmp);
Pinv_new = Pinv - c*tmp*tmp';
q_new = q + a*y;
xls = Pinv_new*q_new;
return;