function bn=b(n,funcname)
% this function computes the Fourier coefficient 'bn' for sin(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)+..
%   
% 'bn' depends on n and the function 'funcname' to be approximated.
%  
% Its value is:
% 	bn = Integral from -pi to pi of funcname(x)*sin(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 sin(3x) by 
% typing:
% 	c = b(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='sin';

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