% script M-file: spyro.m

% Welcome message
Welcome = sprintf('\t\t\tWelcome to spyro\n\n\t\tPlots x(t) = A*exp((a+j*2*pi*f)*t)\n');
disp(Welcome)

% do the following until user indicates quit, then ToDo becomes 0
ToDo = 1;
while(ToDo ~= 0)
   % prompt for parameters
   A = input('Enter amplitude A (real): ');
   if(imag(A) ~= 0)
       error('A must be real');
   end
   
   a = input('Enter damping constant a (real): ');
   if(imag(a) ~= 0)
       error('a must be real');
   end
   
   freq = input('Enter frequency f (real, positive): ');
   if(imag(freq) ~= 0 | freq <= 0)
       error('freq must be real and positive');
   end
   
   % Time range: 1000 samples between Start and End
   Start = input('Starting value of time range: ');
   End = input('Ending value of time range: ');
  
   tt = linspace(Start, End, 1000);
   
   % construct signal
   xx = A*exp((a+j*2*pi*freq)*tt);
   
   % construct title for plots
   Title = sprintf('x(t) = %2.1f exp((%2.1f + j 2 \\pi %2.1f )t)', A, a, freq);
   
   % Ready to plot: prompt for choice
   disp(['                                '
         'Plot:                           '
         '   real vs. imaginary        (1)'
         '   real vs. time             (2)'
         '   imaginary vs. time        (3)'
         '                                '
         'Quit                         (0)']);
    ToDo = input('Select from menu above (0-3): ');
    
    % proceed according to choice
    switch ToDo
        case 1,      % plot real vs. imaginary
            figure(1)
            plot(xx)
            axis('square')  % ensure that circles are round
            grid
            xlabel('Real')
            ylabel('Imag')
            title(Title)
        case 2,      % plot real vs. time
            figure(1)
            plot(tt, real(xx))
            xlabel('Time (s)')
            title(Title)
            grid
        case 3,      % plot imag vs. time
            figure(1)
            plot(tt, imag(xx))
            xlabel('Time (s)')
            title(Title)
            grid
        case 0,
            close all; % close plot window
            disp('Good Bye');
        otherwise
            warning('Bad Choice: starting over');
    end
      
end
