************************************************************************ ************************************************************************ * * Subroutine MATINV * * Function: * Invert 3 x 3 real matrix * * Arguments: * R (i) 3 x 3 matrix to be inverted * Ri (o) 3 x 3 inverse matrix * Errcod (o) error code * errcod = 0 - no error * errcod = 1 - singular matrix * * History: * Written 1989 S. Knight ************************************************************************ subroutine matinv ( r , ri , errcod ) implicit none * Arguments real r( 3,3 ) , ri( 3,3 ) integer errcod * Local variables real det *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= * Initiate error code errcod = 0 * Compute value of determinant det = r(1,1) * ( r(2,2) * r(3,3) - r(2,3) * r(3,2) ) + & r(2,1) * ( r(3,2) * r(1,3) - r(1,2) * r(3,3) ) + & r(3,1) * ( r(1,2) * r(2,3) - r(1,3) * r(2,2) ) * Check matrix not singular if ( abs ( det ) .lt. 0.0000001 ) then errcod = 1 return endif * Compute elements of inverse matrix ri(1,1) = ( r(2,2) * r(3,3) - r(2,3) * r(3,2) ) / det ri(1,2) = - ( r(1,2) * r(3,3) - r(1,3) * r(3,2) ) / det ri(1,3) = ( r(1,2) * r(2,3) - r(1,3) * r(2,2) ) / det ri(2,1) = - ( r(2,1) * r(3,3) - r(3,1) * r(2,3) ) / det ri(2,2) = ( r(1,1) * r(3,3) - r(1,3) * r(3,1) ) / det ri(2,3) = - ( r(1,1) * r(2,3) - r(1,3) * r(2,1) ) / det ri(3,1) = ( r(2,1) * r(3,2) - r(3,1) * r(2,2) ) / det ri(3,2) = - ( r(1,1) * r(3,2) - r(1,2) * r(3,1) ) / det ri(3,3) = ( r(1,1) * r(2,2) - r(1,2) * r(2,1) ) / det return *=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= end