function an=a(n,funcname)
% this function computes the Fourier coefficient 'an' for cos(nx) in the 
% Fourier approximation to function 'funcname':
%
% S(n,x) = 1/2(a0) + (a1)cos(x) + (b1)sin(x) + (a2)cos(2x) + (a3)sin(2x)+..
%   
% 'an' depends on n and the function 'funcname' to be approximated.
%  
% Its value is:
% 	an = Integral from -pi to pi of funcname(x)*cos(nx)
%
% funcname must be given in single quotes.  e.g., if you have a function
% called myfunc.m you want to approximate (which is stored in file myfunc.m), 
% you can set a variable c equal to the Fourier coefficient for cos(3x) by 
% typing:
% 	c = a(3,'myfunc');

% declare global variables
global M;
global FUNC_NAME;
global TRIG_NAME;

% set global variables that proj.m needs to be able to use.
% NOTE: since proj.m is being integrated by quad8, the function can
% only have one input parameter.  That's why we have to use global 
% variables for everything else.
M=n;
FUNC_NAME=funcname;
TRIG_NAME='cos';

% integrate proj(x) from -pi to pi, then divide by pi. 
an=(quad8('proj',-pi,pi)./pi);
