     PROGRAM vectors_and_matrices



!  Copyright 1994, Miles Ellis, Ivor Philips and Tom Lahey

!  Copyright 1994, Addison-Wesley Publishers Ltd.

!  Copyright 1994, Addison-Wesley Publishing Company Inc.

!  Permission is granted for the use of this code for the purpose of teaching

!  and/or learning the Fortran 90 language provided that the above copyright

!  notices are included in any copies made.

!  Neither the authors nor the publishers accept any responsibility for

!  any results obtained by use of this code.



        IMPLICIT NONE

        INTEGER, DIMENSION(2,3) :: matrix_a

        INTEGER, DIMENSION(3,2) :: matrix_b

        INTEGER, DIMENSION(2,2) :: matrix_ab

        INTEGER, DIMENSION(2) :: vector_c = (/ 1,2 /)

        INTEGER, DIMENSION(3) :: vector_bc



        ! Initialise matrix_a

        matrix_a(1,1) = 1           ! matrix_a is the matrix:

        matrix_a(1,2) = 2

        matrix_a(1,3) = 3           !   [ 1  2  3 ]

        matrix_a(2,1) = 2           !   [ 2  3  4 ]

        matrix_a(2,2) = 3

        matrix_a(2,3) = 4



        ! Set matrix_b as the transpose of matrix_a

        matrix_b = TRANSPOSE(matrix_a)

        ! matrix_b is now the matrix:   [ 1  2 ]

        !                               [ 2  3 ]

        !                               [ 3  4 ]



        ! Calculate matrix products

        matrix_ab = MATMUL(matrix_a,matrix_b)

        ! matrix_ab is now the matrix:  [ 14  20 ]

        !                               [ 20  29 ]



        vector_bc = MATMUL(matrix_b,vector_c)

        ! vector_bc is now the vector:  [ 5 8 11 ]



     END PROGRAM vectors_and_matrices

