function [I, C, G, T] = DinInv3R( q,dq,ddq,L,R,M,go )

 l1 = L(1); l2 = L(2); l3 = L(3);
 r1 = R(1); r2 = R(2); r3 = R(3);
 m1 = M(1); m2 = M(2); m3 = M(3);
 
%-- 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+r3^2+2*l1*l2*cos(q(2,:))+2*l1*r3*cos(q(2,:)+q(3,:))+2*l2*r3*cos(q(3,:)) );
 J(1,2,:) = m2*( r2^2+l1*r2*cos(q(2,:)) )+m3*( l2^2+r3^2+l1*l2*cos(q(2,:))+l1*r3*cos(q(2,:)+q(3,:))+2*l2*r3*cos(q(3,:)) );
 J(1,3,:) = m3*( r3^2+l1*r3*cos(q(2,:)+q(3,:))+l2*r3*cos(q(3,:)) );
 J(2,1,:) = J(1,2);
 J(2,2,:) = m2*r2^2+m3*( l2^2+r3^2+2*l2*r3*cos(q(3,:)) );
 J(2,3,:) = m3*( r3^2+l2*r3*cos(q(3,:)) );
 J(3,1,:) = J(1,3);
 J(3,2,:) = J(2,3);
 J(3,3,:) = m3*( r3^2 );
 
%-- Termos Coriolis/centrífugos ------------------------------------------------
 C = [ (-m2*( 2*l1*r2*sin(q(2,:)) )-m3*( 2*l1*l2*sin(q(2,:))+2*l1*r3*sin(q(2,:)+q(3,:)) )).*dq(1,:).*dq(2,:)+...
       (                           -m3*( 2*l1*r3*sin(q(2,:)+q(3,:))+2*l2*r3*sin(q(3,:)) )).*dq(1,:).*dq(3,:)+...
       (-m2*(   l1*r2*sin(q(2,:)) )-m3*(   l1*l2*sin(q(2,:))+l1*r3*sin(q(2,:)+q(3,:)) )).*dq(2,:).^2+...
       (                           -m3*( 2*l1*r3*sin(q(2,:)+q(3,:))+2*l2*r3*sin(q(3,:)) )).*dq(2,:).*dq(3,:)+...
       (                           -m3*(   l1*r3*sin(q(2,:)+q(3,:))+l2*r3*sin(q(3,:)) )).*dq(3,:).^2;
       ( m2*(   l1*r2*sin(q(2,:)) )+m3*(   l1*l2*sin(q(2,:))+l1*r3*sin(q(2,:)+q(3,:)) )).*dq(1,:).^2+...
       (                           -m3*(                          2*l2*r3*sin(q(3,:)) )).*dq(1,:).*dq(3,:)+...
       (                           -m3*(                          2*l2*r3*sin(q(3,:)) )).*dq(2,:).*dq(3,:)+...
       (                           -m3*(                            l2*r3*sin(q(3,:)) )).*dq(3,:).^2;
       (                            m3*(   l1*r3*sin(q(2,:)+q(3,:))+l2*r3*sin(q(3,:)) )).*dq(1,:).^2+...   
       (                            m3*(                          2*l2*r3*sin(q(3,:)) )).*dq(1,:).*dq(2,:)+...
       (                            m3*(                            l2*r3*sin(q(3,:)) )).*dq(2,:).^2 ];
 
%-- Termos Gravitacionais ------------------------------------------------------
 G = go*[ (m1*r1+(m2+m3)*l1)*cos(q(1,:))+(m2*r2+m3*l2)*cos(q(1,:)+q(2,:))+m3*r3*cos(q(1,:)+q(2,:)+q(3,:));
                                         (m2*r2+m3*l2)*cos(q(1,:)+q(2,:))+m3*r3*cos(q(1,:)+q(2,:)+q(3,:));
                                                                          m3*r3*cos(q(1,:)+q(2,:)+q(3,:)) ];
                                      
%-- Equação do movimento: T = J*ddq+C(q,dq)+G(q) -------------------------------
 for k=1:size(q,2),
    I(1,k) = J(1,1,k)*ddq(1,k)+J(1,2,k)*ddq(2,k)+J(1,3,k)*ddq(3,k);
    I(2,k) = J(2,1,k)*ddq(1,k)+J(2,2,k)*ddq(2,k)+J(2,3,k)*ddq(3,k);
    I(3,k) = J(3,1,k)*ddq(1,k)+J(3,2,k)*ddq(2,k)+J(3,3,k)*ddq(3,k);
 end
 T = I + C + G;                                                                                                                
%----------------------------------------------------------------------------end

