% Two first-order DEQ to solve two equations of motion for the train

function xdot = trainDynamics(t,x)

global A B C

% Define the rate equations
%
% Rate equation tells us the rate of change of
% Each state variable
%
% x(1) = speed (m/s)
% x(2) = position (m)

% xdot(1) = rate of change of speed (m/s-s)
% xdot(2) = rate of change of position (m/s)

xdot(1) = A *  x(1) .^2 + B *x(1) + C ;
xdot(2) = x(1);

xdot = xdot';           % Matlab likes column vectors passed back by the
                                % ODE function - then transpose vector xdot