function xdot = motorodefun(t,x)

% State variable definitions
i = x(1);               % current
theta = x(2);           % motor angle
theta_dot = x(3);       % motor angular velocity

% Parameters
L = 0.309 * 10^-3;      % coil inductance in Henries
Rc = 6.46;              % coil resistance in Ohms
Kv = 1/448*60/2/pi;     % motor voltage constant in Volts per (radians per second)
Kt = 21.3 * 10^-3;      % motor torque constant in Newton meters per Ampere
J = (4.24+0.4) * 10^-7; % combined motor and gearbox inertia in Kilogram squared meters
b = 0;                  % damping constant in Newton meters per (radians per second)
% i_nom = 9.03e-3;        % no-load current in Amperes
% theta_dot_nom = 3920/60*2*pi;   % no-load speed in radians per second
% b = Kt*i_nom/theta_dot_nom;     % damping estimated from motor parameters
Rg = 1;                 % gearbox ratio
nug = 0.7;              % gearbox efficiency

% Applied voltage
Va = voltagefun(t,x);

% Applied (or reaction) torque
Ta = torquefun(t,x);

% State derivative equations
xdot(1,1) =     % current dynamics
xdot(2,1) =     % trivial equation of 2nd order mechanical system
xdot(3,1) =     % physical dynamics

return