function retval = trigeval(a,b,x)
% usage: y = trigeval(a,b,x)
% description: given vectors of trig coefficients a, b
% of length n+1 and n, respectively, and argument vector
% x, this function returns the value of the trig series
% p(x) = a(n+1)/2 + sum(a(j)*cos(j*x)+b(j)*sin(j*x),j=1..n).
% It is assumed that  a_0 is last entry of a

% programmer: t. shores
% last rev.: 2/8/16

% Octave and Matlab compatible file
n = length(b);
if (length(a) ~= n+1)
  disp('Incorrect vector lengths');
  return;
end
retval = a(n+1)/2*ones(size(x));
for j = 1:n
  retval = retval + a(j)*cos(j*x)+b(j)*sin(j*x);
end

end
