FORTRAN 90 L e c

advertisement
FORTRAN 90
Lecturer : Rafel Hekmat Hameed
University of Babylon
Subject : Fortran 90
College of Engineering
Year : Second B.Sc.
Mechanical Engineering Dept.
Q/GA
tƌŝƚĞ Ă ĨŽƌƚƌĂŶ ϵϬ ƉƌŽŐƌĂŵ ƚŽ ĮŶĚ ƚŚĞ ĚĞƚĞƌŵŝŶĂŶƚ ŽĨ ŵĂƚƌŝdž ďLJ ƵƐŝŶŐ
subroutine program.
૚
૟
૚ૠ
૚૝ ૢ
૚ૢ
૞൩
૜
A=൥ ૡ
Program aa
Implicit none
;
Integer, parameter::n=3
Integer,dimension(n,2*n-1)::a
Integer::i,j,det
read(*,*) ((a(i,j),j=1,n),i=1,n)
Call determinant(a,det)
Write(*,6) "determinant=",det
6 format(3x,a,1x,i8)
;
end
subroutine determinant (a,det)
implicit none
;
integer,parameter::n=3
integer,dimension(n,2*n-1)::a
integer::i,j ,d1,d2,det
do i=1,n
;
do j=1,n-1
a(i,n+j)=a(i,j)
;
do i=1,n
d1=1;d2=1
;
enddo
;
;
enddo
do j=1,n
d1=d1*a(j,i+j-1)
;
d2=d2*a(j,2*n-i-j+1)
det=det+d1-d2
;
enddo
;
;
end
enddo
Q/GB
You have two matrices A&B, A is identity matrix with shape (/3,3/) and, B is a matrix
with rank 2 and shape (/3,3/) as shown below:
૚
B=൥ૡ
૝
૟
૜
ૢ
ૠ
૞൩
૜
D0 THE FOLLOEING:
C=A+B
Construct D which is a diagonal matrix of C
Construct E which is a scalar matrix with C(1,1)
Can we say that C asymmetric matrix? Do this branch by subroutine program.
IMPLICIT NONE
INTEGER,PARAMETER::N=3
INTEGER,DIMENSION(N,N)::A,B,C,D,E,F
INTEGER::I,J
READ(*,*)((A(I,J),J=1,N),I=1,N)
READ(*,*)((B(I,J),J=1,N),I=1,N)
WRITE(*,7)((A(I,J),J=1,N),I=1,N)
;
WRITE(*,*)"********************"
WRITE(*,7)((B(I,J),J=1,N),I=1,N)
;
WRITE(*,*)"********************"
;
WRITE(*,*)"********************"
C=A+B
WRITE(*,7)((C(I,J),J=1,N),I=1,N)
DO I=1,N
DO J=1,N
IF(I==J)THEN
D(I,J)=C(I,J)
ELSE
D(I,J)=0
ENDIF ;
ENDDO
WRITE(*,7)((D(I,J),J=1,N),I=1,N)
DO I=1,N
DO J=1,N
IF(I==J)THEN
;
;
ENDDO
WRITE(*,*)"********************"
E(I,J)=C(1,1)
;
ELSE ;
E(I,J)=0
ENDIF
;
ENDDO
;
ENDDO
WRITE(*,7)((E(I,J),J=1,N),I=1,N)
;
WRITE(*,*)"********************"
CALL SY(C,F)
7 FORMAT(3(2X,I6))
END
SUBROUTINE SY(C,F)
INTEGER,PARAMETER::N=3
INTEGER,DIMENSION(N,N)::C,F
INTEGER::I,J
DO I=1,N
DO J=1,N
F(I,J)=C(I,J)
;
ENDDO
;
ENDDO
DO I=1,N
DO J=1,N
IF(F(I,J).NE.F(J,I)) EXIT
PRINT*, " C is not symmetric "
END
;
ENDDO
;
ENDDO
Download