L e c t

advertisement
FORTRAN 90
Lecturer : Rafel Hekmat Hameed
University of Babylon
Subject : Fortran 90
College of Engineering
Year : Second B.Sc.
Mechanical Engineering Dep.
Determinants
Every square matrix has a value called a determinant,, and only square
matrices
ices have defined determinants.
The determinant of a 2x2 square matrix is the difference of the products of the
diagonals.
The "down"" diagonal is in red and the "up"
" " diagonal is in blue. The up
diagonals are always subtracted from the down diagonals. Matrices that are larger
than a 2 x 2 matrix become a little more complicated when finding the
determinant but the same rules apply. Let's find
When finding the determinant of a 3 x 3 matrix it is helpful to write the first two
columns to the right side of the matrix like so
ϭ
A fortran 90 program to find the determinant of 33 matrix.
Program determinant
;
implicit none
Integer, parameter::n=3, m=5
Integer, dimension (n,m):: a
;
Integer:: i, j, det1, det2, det
Read(*,*) ((a(I,j),j=1,n),i=1,n)
Do i=1,n
;
do j=1,n-1
a(i,n+j)=a(I,j) ;
do i=1,n
enddo ;
;det1=1
enddo
;
det2=1
do j=1,n
det1=det1*a(j,i+j-1) ;
det2=det2*a(j,2*n-j-i+1)
det=det+det1-det2
enddo
;
write(*,6) "determinant=", det
;6 format(2x,a,2x,i8);
;enddo
end
If the matrix has more than three columns, then the determinant be
determined, as illustrated by example below
A=
͵
ቚ
Ͷ
ተ͵
Det A = ቚ
ተ͵
͵
ቚ
ͷ
͸
͵
ቚ ቚ
͹
Ͷ
͸
͵
ቚ ቚ
ͳ
͵
͸
͵
ቚ ቚ
ʹ
ͷ
െ͵
ቚ
െͳͷ
ቮ
െ͵
ቚ
െʹͶ
3
4
3
5
ͺ
͵
ቚ ቚ
͹
Ͷ
ͺ
͵
ቚ ቚ
ͷ
͵
ͺ
͵
ቚ ቚ
Ͷ
ͷ
െͳͳ
െ͵
ቚ ቚ
െͻ
െͳͷ
െͳͳ
െ͵
ቚ ቚ
െʹͺ
െʹͶ
6
7
1
2
8
7
5
4
6
7
2
3
͸
ቚ
͹
െ͵ െͳͳ െ͵
͸ተ
ቚ ֜ อെͳͷ െͻ െͳʹอ ֜
ʹተ
െʹͶ െʹͺ െʹͳ
͸
ቚ
͵
െ͵
ቚ
െͳʹ ቮ ֜ ቚെͳ͵ͺ
െ͵
െͳͺͲ
ቚ
െʹͳ
Det A= (-138*-9) – ( -180*-9) = -378
Ϯ
െͻ
ቚ ֜
െͻ
‫ܣ‬
ฬ ଵଵ
‫ܣ‬ଶଵ
ተ‫ܣ‬
ฬ ଵଵ
‫ܣ‬
ተ ଷଵ
‫ܣ‬
ฬ ଵଵ
‫ܣ‬ସଵ
‫ܣ‬ଵଶ
ฬ
‫ܣ‬ଶଶ
‫ܣ‬ଵଶ
ฬ
‫ܣ‬ଷଶ
‫ܣ‬ଵଶ
ฬ
‫ܣ‬ସଶ
‫ܣ‬ଵଷ
‫ܣ‬
ฬ ฬ ଵଵ
‫ܣ‬ଶଷ
‫ܣ‬ଶଵ
‫ܣ‬ଵଷ
‫ܣ‬
ฬ ฬ ଵଵ
‫ܣ‬ଷଷ
‫ܣ‬ଷଵ
‫ܣ‬ଵଷ
‫ܣ‬
ฬ ฬ ଵଵ
‫ܣ‬ସଷ
‫ܣ‬ସଵ
‫ܣ‬
ฬ ଵଵ
‫ܣ‬ଶଵ
‫ܣ‬
ฬ ଵଵ
‫ܣ‬ଷଵ
‫ܣ‬
ฬ ଵଵ
‫ܣ‬ସଵ
IMPLICIT NONE
INTEGER ,DIMENSION (4,4)::A
INTEGER,DIMENSION (1:3,1:3)::B
INTEGER::I, J, N
DATA A/3,4,3,5,6,7,1,2,8,7,5,4,6,7,2,3/
DO N=4, 2 ,-1
DO I=1, N-1
DO J=1,N-1
B(I,J)=A(1,1)*A(I+1,J+1)-A(1,J+1)*A(I+1,1)
ENDDO ; ENDDO
DO I=1,N-1
DO J=1,N-1
A(I,J)=B(I,J)
ENDDO;ENDDO
DO I=1,N-1
PRINT*,(B(I,J),J=1,N-1)
ENDDO
PRINT *, ' ******************************************* '
ENDDO
END
ϯ
‫ܣ‬ଵସ
ฬ
‫ܣ‬ଶସ
‫ܣ‬ଵସ ተ
ฬ
‫ܣ‬ଷସ
ተ
‫ܣ‬ଵସ
ฬ
‫ܣ‬ସସ
Singular and Non-Singular
Singular Matrices
An n square matrix A is called singular if det A=0 ; if det A ##0, A is called
non-singular.
Example
Given that
Determine whether this matrix is singular or non-singular.
non
Solution
Therefore, matrix A is singuular
ϰ
Download