I have written a Fortran 90 main program that reads in a matrix from an input file and calls MatrixInvert() to invert the matrix:
PROGRAM Main IMPLICIT NONE integer i, j, N REAL, DIMENSION(:, :), ALLOCATABLE :: A, B INTERFACE SUBROUTINE Print( A ) REAL, DIMENSION(:,:) :: A END SUBROUTINE END INTERFACE INCLUDE 'pj6interface.h' !! You must provide this file READ *, N !! Read size of matrix ALLOCATE(A(N, N)) !! Allocate source ALLOCATE(B(N, N)) !! Allocate destination DO i = 1, N READ *, A(i,:) !! Read in input matrix END DO CALL Print( A ) !! Print input matrix B = MatrixInvert(A) !! You must write this function (in another file) print *, "The inverse matrix is:" CALL Print( B ) !! Print result END
The main program includes a file named pj6interface.h which must contain an interface that describe the function MatrixInvert You must define the interface and store the definition in the file pj6interface.h (please do NOT change the pj6.f90 file that you must download for this project) Without this interface, the program will not compile.
In addition to the pj6interface.h file, you must write the function MatrixInvert and put that in another file - this file must have an extension ".f90" to be compiled by the Fortran compiler.
You can obtain the main program pj6.f90 for this project through this link: click here
Save a copy in your cs561 project directory.
Run the program with the following command:
main < pj6.dataYour program should invert the matrix
3 2 5 9 1 7 3 7 0 -9 1 8 9 8 3 1The structure of the input file is
N a11 a12 .... a1N a21 a22 .... a2N ... aN1 aN2 .... aNNTry with other matrices to test your project thoroughly.
/home/cs561000/turnin Makefile pj6
/home/cs561000/turnin pj6interface.h pj6a
/home/cs561000/turnin yourFileName.f90 pj6b