function [speed, distance, acceleration]= speedDistanceCalculator(k1,k2,t,Vo,So)

% Function to estimate the velocity and distance traveled by a vehicle with
% linearly decreasing acceleration function
% This problems evaluates the analytic solution to the first order model
% presented below (a first order differential equation)

% dV/dt = k1 - k2 * V
%
% where:
%
% dV/dt = acceleration (m/s-s)
% V = speed = vehicle speed (m/s) 
% S = distance = distance traveled (m)
% k1 = maximum acceleration (m/s-s)
% k2 = slope of dV/dt vs V profile (1/s)

% Programmer: T. Trani
% Date: 10/15/2013 

    speed = k1/k2 * (1 - exp(-k2 .* t)) + Vo .* exp(-k2 .* t);
    
    % Calculate distance as a function of time
   distance = So + k1/k2 * t - k1/(k2^2) * (1 - exp(-k2 .* t)) ...
        + Vo/k2 .* (1-exp(-k2 .* t));
    
    % calculate teh acceelration as a function of time
    acceleration = (k1 - k2 * Vo) * exp(-k2 .* t);

end

