% checkcspsoln(A,B,lambda,x,d) checks the degree d solution
% x(l) for each value l in lambda. The output maxres is the
% largest value of ||(A - l B) x(l)||_2 over all l in lambda.
% The output column vector res is defined by
% res(i) = ||(A - lambda(i) B) x(lambda(i))||_2. Evaluating
% the vector polynomial x at l is done via a call to the
% helper function evalvecpoly.

function [maxres,res] = checkcspsoln(A,B,lambda,x,d)

nlambda = length(lambda);
res = zeros(nlambda,1);

maxres = -inf;
for i=1:nlambda
  res(i) = norm((A-lambda(i)*B)*evalvecpoly(x,d,lambda(i)));
  if (res(i) > maxres) maxres = res(i); end
end
