% sdot.m: function to give derivaties of body angular velocity vector, w, 
%         and derivatives of rotation matrix, R.
% Date:   Tue 2 May 2006
% Author: Charles P. Coleman

function Sdot = sdot(t,S)
global I1 I2 I3 A1 A2 A3 I

Sdot = zeros(12,1);
% Rotation matrix derivatives
% R_dot = S(w)R
% Sastry 
 Sdot(1) = -S(12)*S(4) + S(11)*S(7) ;
 Sdot(2) = -S(12)*S(5) + S(11)*S(8) ;
 Sdot(3) = -S(12)*S(6) + S(11)*S(9) ;
 Sdot(4) =  S(12)*S(1) - S(10)*S(7) ;
 Sdot(5) =  S(12)*S(2) - S(10)*S(8) ;
 Sdot(6) =  S(12)*S(3) - S(10)*S(9) ;
 Sdot(7) = -S(11)*S(1) + S(10)*S(4) ;
 Sdot(8) = -S(11)*S(2) + S(10)*S(5) ;
 Sdot(9) = -S(11)*S(3) + S(10)*S(6) ;

% Body angular velocity derivatives
% Gyroscopic Equations: Stevens and Lewis (1992), p 32, Eq (1.3-22)
% Euler Equations:      Marsden and Ratiu (1993), p 5, Eq (1.2.1)
 Sdot(10) = ((I2-I3)/I1)*S(11)*S(12);
 Sdot(11) = ((I3-I1)/I2)*S(12)*S(10);
 Sdot(12) = ((I1-I2)/I3)*S(10)*S(11);

% Body angular momentum derivatives
% Marsden and Ratiu (1993), p
% Sdot(13) = A1*S(14)*S(15) ;
% Sdot(14) = A2*S(15)*S(13) ;
% Sdot(15) = A3*S(13)*S(14) ;
