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). % n = length(b); if (length(a) ~= n+1) error('incorrect vector lengths'); 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