function [I, C, G, T] = DinInv2R( q, dq, ddq )

global m1 m2 m3 l1 l2 go

r1 = l1/2; r2 = l2/2; 		%-- Massas dos elos colocadas no centro -------------

%-- Matriz de Inércias ---------------------------------------------------------
 J(1,1,:) = m1*r1^2+m2*( l1^2+r2^2+2*l1*r2*cos(q(2,:)) )+m3*( l1^2+l2^2+2*l1*l2*cos(q(2,:)) );
 J(1,2,:) =         m2*(      r2^2+  l1*r2*cos(q(2,:)) )+m3*(      l2^2+  l1*l2*cos(q(2,:)) );
 J(2,1,:) = J(1,2);
 J(2,2,:) = m2*r2^2+m3*l2^2;
 
%-- Termos Coriolis/centrífugos ------------------------------------------------
 C = [ -2*l1*(m2*r2+m3*l2)*sin(q(2,:)).*( dq(1,:).*dq(2,:)+dq(2,:).^2 );
          l1*(m2*r2+m3*l2)*sin(q(2,:)).*dq(1,:).^2 ];
 
%-- Termos Gravitacionais ------------------------------------------------------
 G = go*[ (m1*r1+(m2+m3)*l1)*cos(q(1,:))+(m2*r2+m3*l2)*cos(q(1,:)+q(2,:));
                                         (m2*r2+m3*l2)*cos(q(1,:)+q(2,:)) ];
                                      
%-- Equação do movimento: T = J*ddq+C(q,dq)+G(q) -------------------------------
 for k=1:length(q),
    I(1,k) = J(1,1,k)*ddq(1,k)+J(1,2,k)*ddq(2,k);
    I(2,k) = J(2,1,k)*ddq(1,k)+J(2,2,k)*ddq(2,k);
 end
 T = I + C + G;                                                                                                                
%----------------------------------------------------------------------------end

