% Math 3150-1
%
% Demo code for exercise 3.3.5
%
% See the student solutions manual for the expression of b_n and b_n^*.

toprint = 0; % 1 create print quality plots, 0 animate
N=20;        % number of terms to use in the partial sums, increase to get
             % more accurate solutions
c=4;         % velocity

% space variable
x = linspace(0,1);

% time variable will take values in this array
ts=linspace(0,1,21); % 21 equally spaced points from 0 to 1, included
		     % depending on the velocity c you may or may not need
		     % to change this

figure(1); clf;
if (toprint) hold on; end; % do not erase previous plots
for it=1:length(ts), % for every time
 t = ts(it);
 s = zeros(size(x)); %initialize partial sum to zero
 % compute the partial sum
 % (when you know that the sum is composed of just a few terms
 % it is probably easier to NOT use a loop and write directly:
 % s = term1 + term2 + term3 ....
 for n=1:N,
  bn = 8*sin(n*pi/2)/(n*pi)^2;
  % bnstar = SOME EXPRESSION;
  s = s + sin(n*pi*x) * bn * cos(4*n*pi*t); % + bnstar * SOME EXPRESSION
 end;
 plot(x,s); % plot the partial sum
 axis([0 1 -1 1]); % adjust axis so that all plots are on the same scale
 pause; % wait for user input
end;
if (toprint) hold off; end; % erase previous plots
