ans_exam

# ans_exam - stud_solutions Fri:04:22 2010 1 QUESTION ONE =...

This preview shows pages 1–3. Sign up to view the full content.

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

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

View Full Document
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 ! ******************************************************************** END MODULE cat_mod ======================================================================== ============ Part (b) ============ ========================================================================
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern