ans_exam - stud_solutions.txt Fri Jan 08 13:04:22 2010 1

Info iconThis preview shows pages 1–3. 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: stud_solutions.txt Fri Jan 08 13:04:22 2010 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% QUESTION ONE %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ============ Part (a) ============ ======================================================================== MODULE cat_mod IMPLICIT NONE CONTAINS ! ******************************************************************** FUNCTION getmat(m,n) !**** Function to input a matrix from the keyboard. The number of rows !**** (m) and the number of columns (n) are input arguments to the !**** function INTEGER, INTENT(IN) :: m,n !**** Dummy declaration REAL, DIMENSION(m,n) :: getmat !**** Local Declaration !** Local Declarations INTEGER :: i DO i=1,m PRINT ("Enter matrix row :",i2),i !*** Prompt for row number READ*,getmat(i,:) !*** Read in row ENDDO END FUNCTION getmat ! ******************************************************************** SUBROUTINE outmat(mat) !**** Subroutine to output a matrix to the screen. REAL, DIMENSION(:,:), INTENT(IN) :: mat !*** Dummy declaration !** Local Declarations INTEGER :: i DO i=1,SIZE(mat,1) PRINT*,mat(i,:) ENDDO END SUBROUTINE outmat ! ******************************************************************** FUNCTION hconcat(mat1,mat2) !** Concatenate matrices horrizontally !** Told in class to check for conformity of matrix operations REAL, DIMENSION(:,:), INTENT(IN) :: mat1 REAL, DIMENSION(:,:), INTENT(IN) :: mat2 !** Local Declarations INTEGER :: m,i stud_solutions.txt Fri Jan 08 13:04:22 2010 2 REAL, DIMENSION(SIZE(mat1,1), SIZE(mat1,2)+SIZE(mat2,2)) :: hconcat m=SIZE(mat1,1) IF (m==SIZE(mat2,1)) THEN !** Check matrices conform for this operation DO i=1,m hconcat(i,:)=(/ mat1(i,:), mat2(i,:) /) END DO ELSE PRINT*,"Matrices do not conform for hconcat" ENDIF END FUNCTION hconcat ! ******************************************************************** FUNCTION vconcat(mat1,mat2) !** Concatenate matrices vertically !** Told in class to check for conformity of matrix operations REAL, DIMENSION(:,:), INTENT(IN) :: mat1 REAL, DIMENSION(:,:), INTENT(IN) :: mat2 INTEGER :: n,j REAL, DIMENSION(SIZE(mat1,1)+SIZE(mat2,1), SIZE(mat1,2)) :: vconcat n=SIZE(mat1,2) IF (n==SIZE(mat2,2)) THEN !** Check matrices conform for this operation DO j=1,n vconcat(:,j)=(/ mat1(:,j), mat2(:,j) /) END DO ELSE PRINT*,"Matrices do not conform for hconcat" ENDIF END FUNCTION vconcat ! ********************************************************************!...
View Full Document

Page1 / 7

ans_exam - stud_solutions.txt Fri Jan 08 13:04:22 2010 1

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

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