% 
% model of a rocket lander
% 
% (c)2013 Regents of the University of Michigan
% This work is licensed under the
% Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
% To view a copy of this license, visit
% http://creativecommons.org/licenses/by-nc-sa/3.0/
% or send a letter to
% Creative Commons,
% 444 Castro Street, Suite 900,
% Mountain View, CA, 94041, USA.
%
function Rocket_Lander()
%--------------------------------------------------------------------------
% configuration variables

% our equation is 
%   v' = -c v - g (1 - step(t-t0)) - a step(t-t0), v(0) = v0
    c = 1/80;
    g = 10;
    a = 1/80;
    v0 = -5;
    
    t0 = 300;
    t = 0:.1:1000;
    
    bg_grey = [ 0.6 0.6 0.6 ];
    
%---------------------------------------------------------------------------
% the solution
    v = v0*exp(-t*c) - (g/c)*(1 - exp(-t*c)) + ...
        (g/c - a/c)*(1 - exp(-(t-t0)*c)).*(t > t0);
    
    pfig = figure();
    pfax = axes( 'Parent', pfig, 'Color', bg_grey );
    hold(pfax);
    
    plot( pfax, t, v, '-b', 'LineWidth', 2 );
    cr = round(1000*c)/1000;
    ar = round(1000*a)/1000;
    title( [ 'Solution to v'' = -' num2str(cr) 'v - ' num2str(g) ...
             '(1 - step(t-' num2str(t0) ')) - ' num2str(ar) ' step(t-' ...
             num2str(t0) '), v(0) = ' num2str(v0) ], 'FontSize', 14 );
    xlabel( 't (s)', 'FontSize', 14 );
    ylabel( 'v (m/s)', 'FontSize', 14 );
    plot( pfax, t, -(a/c)*ones(length(t),1), '--k' );
    legend( 'v', ['asymptotote (=-' num2str(a/c) ')' ], ...
            'Location', 'SouthEast' );
end
% all done
%---------------------------------------------------------------------------