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,

displaymath28056

and

displaymath28057

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

Now try this question gif

Return to corresponding overview page gif


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

©University of Liverpool, 1997
Wed May 28 20:20:27 BST 1997
Not for commercial use.