{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

part2_solutions

# part2_solutions - solutions Tue:10:03 2006 1 solutions...

This preview shows page 1. Sign up to view the full content.

solutions.txt Tue Mar 21 16:10:03 2006 1 PROGRAM part2 !*** Program to multiply together two matrices mat1 & mat2 and store !*** the result in mat3. ie "mat3 = mat1 X mat2" where "X" represents !*** matrix multiplication. IMPLICIT NONE INTEGER, PARAMETER :: m=3,n=4,k=3 REAL, DIMENSION(m,n) :: mat1 REAL, DIMENSION(n,k) :: mat2 REAL, DIMENSION(m,k) :: mat3,mat4 !**** Input the two matrices from the keyboard !**** Press return after each row !**** matrix one then matrix two mat1=getmat(m,n) mat2=getmat(n,k) !**** Use our matrix mult. function to calc. mat3 mat3=mulmat(mat1,mat2) !**** Perform the matrix multiplication !**** using Fortran’s MATMUL(A,B) function mat4=MATMUL(mat1,mat2) !**** Print out each matrix to the screen !**** NOTE the use of / to create a blank line PRINT ’(/,"Matrix One",/)’ CALL outmat(mat1) PRINT ’(/,"Matrix Two",/)’ CALL outmat(mat2) PRINT ’(/,"Matrix1 * Matrx2 (My Answer)",/)’ CALL outmat(mat3) PRINT ’(/,"Matrix1 * Matrx2 (Fortran Answer)",/)’ CALL outmat(mat4) CONTAINS ! ******************************************************************** FUNCTION getmat(m,n) !** Read in matrix with "m" rows and "n" columns INTEGER, INTENT(IN) :: m,n !**** Dummy declaration
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}