function [regen, resid] = pcrregen(a, vc, n)
% PCRREGEN   Calculate short circuit reproduction and residuals for absorbance matrix.
%
%          PCRREGEN caluclates the short ciruit reporduction and
%          residuals for an absorbance matrix based on the number
%          of factors.
%  regen = pcrregen(a, vc, n)    or    [regen, resid] = pcrregen(a, vc, n)
%
% Where:
%
%  regen is the matrix containing the regenerated data
%  resid is the matrix containing the residuals of the regeneration
%  a     is the absorbance matrix
%  vc    is the matrix containing the factors
%  n     is the number of factors to use in the regeneration
%

% Copyright (c) 1989-92 by The MathWorks, Inc.

[t, maxrank] = size(vc);
if n > maxrank, n = maxrank, end;
vc = vc(:, 1:n);
regen = (a' * vc * vc')';
resid = a - regen;
