Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
double precision, | intent(in), | DIMENSION(:,:) | :: | a |
First matrix |
|
double precision, | intent(in), | DIMENSION(:,:) | :: | b |
Second matrix |
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
double precision, | public, | DIMENSION(SIZE(a(1,:))) | :: | column | |||
integer, | public | :: | i | ||||
integer, | public | :: | j | ||||
integer, | public | :: | n | ||||
double precision, | public, | DIMENSION(SIZE(a(1,:))) | :: | row |
FUNCTION square_matrix_multiplication( a, b ) RESULT( c )
IMPLICIT NONE
DOUBLE PRECISION, DIMENSION(:,:), INTENT(IN):: a
!! First matrix
DOUBLE PRECISION, DIMENSION(:,:), INTENT(IN):: b
!! Second matrix
DOUBLE PRECISION, DIMENSION(SIZE(a(1,:))):: row
DOUBLE PRECISION, DIMENSION(SIZE(a(1,:))):: column
DOUBLE PRECISION, DIMENSION(SIZE(a(1,:)),SIZE(a(1,:))):: c
INTEGER:: i, j, n
n= SIZE(a(1,:))
IF(n /= SIZE(a(:,1)))THEN
PRINT *, "** ERROR! Matrix a is not square!"
PRINT *, " * Number of rows=", SIZE(a(:,1))
PRINT *, " Number of columns=", n
PRINT *, " * Stopping..."
PRINT *
STOP
ENDIF
IF(SIZE(b(1,:)) /= SIZE(b(:,1)))THEN
PRINT *, "** ERROR! Matrix b is not square!"
PRINT *, " * Number of rows=", SIZE(b(:,1))
PRINT *, " Number of columns=", SIZE(b(1,:))
PRINT *, " * Stopping..."
PRINT *
STOP
ENDIF
IF(n /= SIZE(b(:,1)))THEN
PRINT *, "** ERROR! Matrix a and b do not have compatible dimensions!"
PRINT *, " Number of columns of a=", n
PRINT *, " * Number of rows of b=", SIZE(b(:,1))
PRINT *, " * Stopping..."
PRINT *
STOP
ENDIF
DO i= 1, n, 1
DO j= 1, n, 1
row = a(i,:)
column= b(:,j)
c(i,j)= row_by_column(row,column)
ENDDO
ENDDO
END FUNCTION square_matrix_multiplication