function [kcal, k] = kmatrix(a, c)
% KMATRIX  Calculate K-matrix calibration coefficients.
% 	KMATRIX calculates K-matrix calibration coefficients
%             for a given set of calibration mixtures.
%
%  kcal = kmatrix(a, c)    or    [kcal, k] = kmatrix(a, c)
%
% Where:
%
%  kcal is the calibration matrix
%  k    is the matrix containing estimated pure component spectra
%  a    is the absorbance matrix
%  c    is the concentration matrix
%
% The concentrations of components in unknown spectra can be calculated
% if the unknown absorbances are set up as a vector (for 1
% unknown) or a matrix (for multiple unknowns).  The unknown matrix 
% can have any available name.  For example call it "u".  The 
% unknown concentrations are then given by kcal * u.
%
% For more details, refer to pages 139 through 141 of the ASTM
% publication "Computerized Quantitative Infrared Analysis".
%

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

k = a * c' * inv(c * c');
kcal = inv(k' * k) * k';
