function y = polyvalm(c,x)
%POLYVALM Evaluate polynomial with matrix argument.
%   POLYVALM(V,X) where V is a vector whose elements are the 
%   coefficients of a polynomial, is the value of the
%   polynomial evaluated with matrix argument X.  X must be a 
%   square matrix. 
%
%   See also POLYVAL, POLYFIT.

%   J.N.Little 4-20-86
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 5.6 $  $Date: 1997/11/21 23:40:59 $

% Polynomial evaluation c(x) using Horner's method 

nc = length(c);
[m,n] = size(x);
if m ~= n
    error('Matrix must be square.')
end

y = zeros(m);
for i=1:nc
    y = x * y + c(i) * eye(m);
end
