next up previous contents
Next: Maximum and Minimum Intrinsics Up: Selected Intrinsic Functions Previous: Random Number Intrinsic

 

Vector and Matrix Multiply Intrinsics

There are two types of intrinsic matrix multiplication these should always be used when appropriate as they will be the most efficient method of calculation:

If A and B are set up as follows,

displaymath22972

and

displaymath22973

then the following program

    PROGRAM DEMO
     INTEGER :: A(2,4)
     INTEGER :: B(4,2)
     A(1,:) = (/1,2,3,4/)
     A(2,:) = (/5,6,7,8/)
     B(:,1) = (/4,3,2,1/)
     B(:,2) = (/8,7,6,5/)
     PRINT*, "DOT_PRODUCT(A(1,:),A(2,:)) = ", DOT_PRODUCT(A(1,:),A(2,:))
     PRINT*, "MATMUL(A,B) = ",MATMUL(A,B)
    END PROGRAM DEMO

gives

    DOT_PRODUCT(A(1,:),A(2,:)) =  70
    MATMUL(A,B) = 20 60 60 164


next up previous contents
Next: Maximum and Minimum Intrinsics Up: Selected Intrinsic Functions Previous: Random Number Intrinsic

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 15:03:35 GMT 1996
Not for commercial use.