functiony=SinCosSeries(sinp,sinx,cosx,c)%SINSCOSERIES Evaluate a sine or cosine series using Clenshaw summation%% y = SINCOSSERIES(sinp, sinx, cosx, c) evaluate% y = sum(c[i] * sin( 2*i * x), i, 1, n), if sinp% y = sum(c[i] * cos((2*i-1) * x), i, 1, n), if ~sinp%% where n is the size of c. x is given via its sine and cosine in sinx% and cosx. sinp is a scalar. sinx, cosx, and y are K x 1 arrays. c is% a K x N array.ifisempty(sinx),y=sinx;return,endn=size(c,2);ar=2*(cosx-sinx).*(cosx+sinx);y1=zeros(length(sinx),1);ifmod(n,2)y0=c(:,n);n=n-1;elsey0=y1;endfork=n:-2:1y1=ar.*y0-y1+c(:,k);y0=ar.*y1-y0+c(:,k-1);endifsinpy=2*sinx.*cosx.*y0;elsey=cosx.*(y0-y1);endend