# P73.F90

### Matrix multiplication

```! =====> Program - P141.F90
!
!
!
!
!
REAL M1(3,4),M2(4,2),M3(3,2)
!
PRINT *,'This is Program P73 - Matrix multiplication'
PRINT *,'PROGRAM IS READING DATA INTO ARRAYS'
CALL MATSIN(M1,M2,3,4,4,2)
CALL PRNMAT(M1,3,4)
CALL PRNMAT(M2,4,2)
PRINT *,'NOW MULTIPLYING MATRICES'
CALL MULT(M1,M2,M3,3,4,4,2)
PRINT *,'SOLUTION:'
CALL PRNMAT(M3,3,2)
STOP
END

SUBROUTINE MATSIN(M1,M2,I1,J1,I2,J2)
REAL M1(I1,J1), M2(I2,J2)
!
!     Tell program where data for  READ   is coming from
OPEN(UNIT=5, FILE='P73.DAT')      ! UNIT=5 is the default input
!
!     ONE PER CARD
!
L1:   DO I=1,I1
END DO L1
27   FORMAT(8(F5.2))
!
!     ONE ROW/CARD
!
L1:   DO I=1,I2
END DO L1
RETURN
END
!
!
!
SUBROUTINE MULT(M1,M2,M3,I1,J1,I2,J2)
REAL M1(I1,J1),M2(I2,J2),M3(I1,J2)
!
!      Now, we will multiply the two matrices
!
!
M3=0.0
DO K=1,J2
DO I=1,J1
DO J=1,I1
M3(J,K) = M3(J,K) + M1(J,I) * M2(I,K)
END DO
END DO
END DO
RETURN
END
!
!
!
SUBROUTINE PRNMAT(M3,IMAX,JMAX)
!
REAL M3(IMAX,JMAX)
!
!
L3:   DO I=1,IMAX
PRINT 202, (M3(I,J),J=1,JMAX)
END DO L3
202   FORMAT(8(2X,F8.3))
PRINT *,' '
!
RETURN
END

DATA:
45.3 23.O 63.7 2.1
54.6 3.4 64.6 3.3
75.7 25.3 45.8 74.3
45.7 9.0
2.3 67.2
4.9 23.4
54.2 2.9

OUTPUT:
Program entered
This is Program P73 - Matrix multiplication
PROGRAM IS READING DATA INTO ARRAYS
45.300    23.000    63.700     2.100
54.600     3.400    64.600     3.300
75.700    25.300    45.800    74.300

45.700     9.000
2.300    67.200
4.900    23.400
54.200     2.900

NOW MULTIPLYING MATRICES
SOLUTION:
2549.060  3449.970
2998.440  2241.090
7769.160  3668.650

Fortran-90 STOP
```

Come back to the previous page

Page builder: Charles Boivin