inv3.f 1.93 KB
 Markus Betzinger committed Apr 26, 2016 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 `````` MODULE m_inv3 !----------------------------------- ! invert 3x3 matrix !----------------------------------- PRIVATE INTERFACE inv3 MODULE PROCEDURE inv3i,inv3r END INTERFACE PUBLIC :: inv3 CONTAINS SUBROUTINE inv3r(a,b,d) IMPLICIT NONE C .. C .. Arguments .. REAL, INTENT (IN) :: a(3,3) REAL, INTENT (OUT) :: b(3,3) ! inverse matrix REAL, INTENT (OUT) :: d ! determinant C .. d = a(1,1)*a(2,2)*a(3,3) + a(1,2)*a(2,3)*a(3,1) + + a(2,1)*a(3,2)*a(1,3) - a(1,3)*a(2,2)*a(3,1) - + a(2,3)*a(3,2)*a(1,1) - a(2,1)*a(1,2)*a(3,3) b(1,1) = (a(2,2)*a(3,3)-a(2,3)*a(3,2))/d b(1,2) = (a(1,3)*a(3,2)-a(1,2)*a(3,3))/d b(1,3) = (a(1,2)*a(2,3)-a(2,2)*a(1,3))/d b(2,1) = (a(2,3)*a(3,1)-a(2,1)*a(3,3))/d b(2,2) = (a(1,1)*a(3,3)-a(3,1)*a(1,3))/d b(2,3) = (a(1,3)*a(2,1)-a(1,1)*a(2,3))/d b(3,1) = (a(2,1)*a(3,2)-a(2,2)*a(3,1))/d b(3,2) = (a(1,2)*a(3,1)-a(1,1)*a(3,2))/d b(3,3) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))/d END SUBROUTINE inv3r SUBROUTINE inv3i(a,b,d) IMPLICIT NONE C .. C .. Arguments .. INTEGER, INTENT (IN) :: a(3,3) INTEGER, INTENT (OUT) :: b(3,3) ! inverse matrix INTEGER, INTENT (OUT) :: d ! determinant C .. d = a(1,1)*a(2,2)*a(3,3) + a(1,2)*a(2,3)*a(3,1) + + a(2,1)*a(3,2)*a(1,3) - a(1,3)*a(2,2)*a(3,1) - + a(2,3)*a(3,2)*a(1,1) - a(2,1)*a(1,2)*a(3,3) b(1,1) = (a(2,2)*a(3,3)-a(2,3)*a(3,2))/d b(1,2) = (a(1,3)*a(3,2)-a(1,2)*a(3,3))/d b(1,3) = (a(1,2)*a(2,3)-a(2,2)*a(1,3))/d b(2,1) = (a(2,3)*a(3,1)-a(2,1)*a(3,3))/d b(2,2) = (a(1,1)*a(3,3)-a(3,1)*a(1,3))/d b(2,3) = (a(1,3)*a(2,1)-a(1,1)*a(2,3))/d b(3,1) = (a(2,1)*a(3,2)-a(2,2)*a(3,1))/d b(3,2) = (a(1,2)*a(3,1)-a(1,1)*a(3,2))/d b(3,3) = (a(1,1)*a(2,2)-a(1,2)*a(2,1))/d END SUBROUTINE inv3i END MODULE m_inv3``````