function v=corrJD(A,Q,kappa,r)
%
% Directly solve the correction equation for JD-method:
%
%   (I-Q*Q') (A-kappa I) (I-Q*Q') v = -r
%
%  Input
%            A      (n-by-n)
%            Q      (n-by-p) vector
%            kappa  scalar shift
%            r      (n-by-1) vector
%
%  Output
%
%            x      (n-by-1) vector
%
%                                            B/L 7/27/2009
%
n=size(A,1); [n,p]=size(Q);
Fx=(A-kappa*eye(n))\[Q r];
C=Q'*Fx(:,1:p); 
b=Q'*Fx(:,p+1);
a=C\b;
v=-Fx(:,p+1)+Fx(:,1:p)*a;

