% 
%   fun2_main  Demonstrates use of function file fun2a.m and fun2b.m to plot
%                and study the function f = exp(at)*sin(wt)
%
%   Used as part of Lesson #3 to illustrate function files and the use of
%   conditional tests within Matlab coding.
%
%   Note that 'a' changes in a discrete fashion at t = 5 sec
%     a = -0.2 1/s for t <= 5 sec
%     a = -0.5 1/s for t > 5 sec
%
%   Prepared by J.R White, UMass-Lowell (last update: Sept. 2017)
%

      clear all, close all, nfig = 0;
%
%   set time vector for plots
      Nt = 101;  t = linspace(0,10,Nt);
%
%   Case 1:  using fun2a -- does check within loop over time inside function
      T = 2;   f1 = fun2a(t,T);
%
%   Case 2:  using fun2b -- uses vectorized check inside function
      T = 2;   f2 = fun2b(t,T);
%
%   plot results to show that both approaches give the same result
      nfig = nfig+1; figure(nfig)
      plot(t,f1,'r-',t,f2,'g.','LineWidth',2),grid
      title(['f(t) = exp(at)*sin(wt) for T = ',num2str(T), ...
             ' sec (a changes at t = 5 s)'])
      xlabel('time (sec)'),ylabel('f(t)')
      legend('using fun2a','using fun2b')
%
%   end of program
