- #1

- 14

- 0

Im new here but is anyone familiar with the fortran language? I need to make a program to do the following:

a) read a 3x3 array of REAL NUMBERS

b) calculate the inverse of the 3x3 matrix

c) write out the answer and the original Matrix

d) multiply two 3x3 matrices.

this is what i have so far but i keep gettin an error with it.

DIMENSION A(3,3)

DIMENSION B(3,3)

DIMENSION C(3,3)

CALL INPUTS(A)

CALL OUTPUTS(A)

CALL IN(B)

CALL OUT(B)

CALL ANSWERS(A,B,N,C)

STOP

END

SUBROUTINE INPUTS(A)

DIMENSION A(3,3)

DO 100 IROW=1,3

DO 100 ICOL=1,3

WRITE(*,200) IROW, ICOL

READ(*,*) A(IROW,ICOL)

100 CONTINUE

200 FORMAT('Enter elements of Matrix A (',I1,',',I1,') = ')

RETURN

END

SUBROUTINE OUTPUTS(A)

DIMENSION A(3,3)

WRITE(*,*) 'Matrix A will be'

DO 300 IROW=1,3

WRITE(*,400) (A(IROW,ICOL),ICOL=1,3)

300 CONTINUE

400 FORMAT(3F7.1)

RETURN

END

SUBROUTINE IN(B)

DIMENSION B(3,3)

DO 500 IROW=1,3

DO 500 ICOL=1,3

WRITE(*,600) IROW, ICOL

READ(*,*) B(IROW,ICOL)

500 CONTINUE

600 FORMAT('Enter elements of Matrix B (',I1,',',I1,') = ')

RETURN

END

SUBROUTINE OUT(B)

DIMENSION B(3,3)

WRITE(*,*) 'Matrix B will be'

DO 700 IROW=1,3

WRITE(*,800) (B(IROW,ICOL),ICOL=1,3)

700 CONTINUE

800 FORMAT(3F7.1)

RETURN

END

SUBROUTINE ANSWERS(a,b,n,c)

DIMENSION a(n,n),b(n,n),c(n,n)

C(1,1)= A(1,1)*B(1,1)+A(1,2)*B(2,1)+A(1,3)*B(3,1)

C(1,2)= A(1,1)*B(1,2)+A(1,2)*B(2,2)+A(1,3)*B(3,2)

C(1,3)= A(1,1)*B(1,3)+A(1,2)*B(2,3)+A(1,3)*B(3,3)

C(2,1)= A(2,1)*B(1,1)+A(2,2)*B(2,1)+A(2,3)*B(3,1)

C(2,2)= A(2,1)*B(1,2)+A(2,2)*B(2,2)+A(2,3)*B(3,2)

C(2,3)= A(2,1)*B(1,3)+A(2,2)*B(2,3)+A(2,3)*B(3,3)

C(3,1)= A(3,1)*B(1,1)+A(3,2)*B(2,1)+A(3,3)*B(3,1)

C(3,2)= A(3,1)*B(1,2)+A(3,2)*B(2,2)+A(3,3)*B(3,2)

C(3,3)= A(3,1)*B(1,3)+A(3,2)*B(2,3)+A(3,3)*B(3,3)

WRITE(*,*) 'Matrix C is, the multiplication of matrices A & B'

DO 1000 IROW=1,3

WRITE(*,1100) (C(IROW,ICOL),ICOL=1,3)

1000 CONTINUE

1100 FORMAT(3F7.1)

Stop

END

I have been told it could cut down to this but i also get an error with this:( .

DIMENSION B(3,3)

CALL INPUT1(A,'A')

CALL OUTPUT1(A,'A')

CALL INPUT1(B,'B') ! same subroutine, different arguments

CALL OUTPUT1(B,'B') ! same subroutine, different arguments

STOP

END

SUBROUTINE INPUT1(x,cname)

DIMENSION x(3,3)

DO 100 IROW=1,3

DO 100 ICOL=1,3

WRITE(*,200) IROW, ICOL

READ(*,*) x(IROW,ICOL)

100 CONTINUE

200 FORMAT ('Enter elements of Matrix ',cname,' (',I1,',',I1,') = ')

RETURN

END

SUBROUTINE OUTPUT1(x,cname)

DIMENSION x(3,3)

WRITE(*,*) 'Matrix ',cname,' will be'

DO 700 IROW=1,3

WRITE(*,800) (x(IROW,ICOL),ICOL=1,3)

700 CONTINUE

800 FORMAT(3F7.1)

STOP

END

Hope someone can help im desperate for it :) .. PLease HELP