-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-96 Matrix.F95
68 lines (68 loc) · 1.4 KB
/
1-96 Matrix.F95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
program QQQ1
implicit none
integer :: j, i
integer, parameter :: z = 5
double precision :: A(z,z), B(z,z), C(z,z)
DOUBLE PRECISION :: TRA, TRB, TRC
! ----------------------
open(1993,file="M1.txt")
open(1371,file="M2.txt")
! ----------------------
A = 0 .0
B = 0 .0
do i=1,z
read(1993,*) (A(i,j),j=1,z)
read(1371,*) (B(i,j),j=1,z)
end do
! ----------------------
C = 0 .0
Call MultipleMatrix(A,B,C)
! Coded by Ali Farzanehpoor, @[email protected]
! ----------------------
write(*,*) " Multiplication of A and B is C "
write(*,*) " C = "
do i=1,z
write(*,"(100f18.5)") (C(i,j),j=1,z)
end do
! ----------------------
TRA = 0 .0
TRB = 0 .0
TRC = 0 .0
CALL TRACE(A,TRA)
CALL TRACE(B,TRB)
CALL TRACE(C,TRC)
WRITE(*,*) " TRACE OF MATRIX A = ", TRA
WRITE(*,*) " TRACE OF MATRIX B = ", TRB
WRITE(*,*) " TRACE OF MATRIX C = ", TRC
CLOSE(1993)
CLOSE(1371)
stop
end program QQQ1
! ----------------------
Subroutine MultipleMatrix(P,Q,N)
implicit none
integer, parameter :: b = 5
double precision :: P(b,b), Q(b,b), N(b,b)
integer :: i,j,k
! Coded by Ali Farzanehpoor, [email protected]
N = 0 .0
do i=1,b
do j=1,b
do k=1,b
N(i,j) = N(i,j) + P(i,k) * Q(k,j)
end do
end do
end do
Return
end subroutine
SUBROUTINE TRACE(S,TRR)
IMPLICIT NONE
INTEGER, PARAMETER :: Y = 5
DOUBLE PRECISION :: S(y,y), TRR
INTEGER :: I
TRR = 0 .0
DO I=1, Y
TRR = TRR + S(I,I)
END DO
RETURN
END SUBROUTINE TRACE