handout7_solutions

handout7_solutions - solutions.txt Fri Apr 30 15:49:45 2004...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: solutions.txt Fri Apr 30 15:49:45 2004 1 PROGRAM main IMPLICIT NONE INTEGER, PARAMETER :: n=4,n2=16 REAL, DIMENSION(n2) :: aa=(/1,2,3,4,5,6,7,8,9,10,& 11,12,13,14,15,16/) REAL, DIMENSION(n,n) :: mat1,mat2 mat1=RESHAPE(aa,(/n,n/)) CALL outmat(mat1) PRINT*,"----------------------------------------" mat2=RESHAPE(aa,(/n,n/),ORDER=(/2,1/)) CALL outmat(mat2) PRINT*,"----------------------------------------" mat1=transmat(mat2) CALL outmat(mat1) CONTAINS ! ******************************************************************** SUBROUTINE outmat(mat) !**** Subroutine to output a matrix to the screen. REAL, DIMENSION(:,:), INTENT(IN) :: mat !*** Dummy declaration INTEGER :: i DO i=1,SIZE(mat,1) PRINT*,mat(i,:) ENDDO END SUBROUTINE outmat ! ******************************************************************** FUNCTION transmat(mat) !**** Dummy arguments REAL, DIMENSION(:,:), INTENT(IN) :: mat INTEGER :: m,n,i,j REAL, DIMENSION(SIZE(mat,2),SIZE(mat,1)) :: transmat !*** Return !**** Find out the no. of rows and cols in the matrix m=SIZE(mat,1) ; n=SIZE(mat,2) !**** Perform the transpose !**** using two DO loops DO i=1,n !*** Loop over rows in mat DO j=1,m !*** Loop over cols in mat transmat(i,j)=mat(j,i)...
View Full Document

Page1 / 2

handout7_solutions - solutions.txt Fri Apr 30 15:49:45 2004...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online