FORTRAN 90

advertisement
FORTRAN 90
Lecturer : Rafel Hekmat Hameed
University of Babylon
Subject : Fortran 90
College of Engineering
Year : Second B.Sc.
Mechanical Engineering Dep.



With this method, the objective is to eliminate one unknown at a time.
This can be done by multiplying the terms of any of the equations of the system
by a number such that we can add (or subtract) this equation to another equation
in the system so that one of the unknowns will be eliminated.


Find the solution of the following set of simultaneous equations by using
Gauss-Elimination method.
2.37x + 3.06y - 4.28z =1.76
1.46x - 0.78y + 3.75z =4.69
-3.69x + 5.13y + 1.06z =5.74
The augmented matrix is
ʹǤ͵͹
͵ǤͲ͸ െͶǤʹͺ ͳǤ͹͸
൥ ͳǤͶ͸ െͲǤ͹ͺ
͵Ǥ͹ͷ ͶǤ͸ͻ൩
െ͵Ǥ͸ͻ ͷǤͳ͵
ͳǤͲ͸
ͷǤ͹Ͷ
First step:
New Row2=Row2-Row1*
ଵǤସ଺
New Row3=Row3-Row1*
ିଷǤ଺ଽ
ଶǤଷ଻
ଶǤଷ଻
ʹǤ͵͹
͵ǤͲ͸
െͶǤʹͺ
ͳǤ͹͸
൥ Ͳ
െʹǤ͸͸ͷͲ
͸Ǥ͵ͺ͸ͷ ͵Ǥ͸Ͳͷͺ൩
Ͳ
ͻǤͺͻͶͶ െͷǤ͸ͲͶͲ
ͺǤͶͺͲ͵
ϭ
Second step:
New Row3=Row3-Row2*
ଽǤ଼ଽସସ
ିଶǤ଺଺ହ଴
ʹǤ͵͹
͵ǤͲ͸
െͶǤʹͺ
ͳǤ͹͸
൥ Ͳ
െʹǤ͸͸ͷͲ
͸Ǥ͵ͺ͸ͷ ͵Ǥ͸Ͳͷͺ ൩
Ͳ
Ͳ
ͳͺǤͳͲ͹ʹ ʹͳǤͺ͸͹͸
Last step:
Back substitution
x=0.9337 , y=1.5412 , z=1.2077
program gaussian_elemination
implicit none
integer,parameter::n=3
real,dimension(n,n+1)::a
real,dimension(n)::x
integer::i,j,k,jj,ip
real::f ,c
read(*,*)((a(i,j),j=1,n+1),i=1,n)
i=1
2 if(abs(a(i,i)).ne.0.0) goto 4
j=i+1
do ip=j,n
if(abs(a(ip,i)).ne.0.0) goto 10
enddo
14 print*,"system has no solution"
stop
10 do jj=1,n+1
c=a(i,jj)
Ϯ
a(i,jj)=a(ip,jj)
a(ip,jj)=c
enddo
i=1+1
if(i.lt.n)goto 2
if( abs (a(n,n)).lt.1.0e-10)goto 14
! the elimination
4 write(*,*) "start the elimination"
do j=1,n-1
do i=j+1,n
f=a(i,j)/a(j,j)
do k=1,n+1
a(i,k)=a(i,k)-f*a(j,k)
enddo;enddo;enddo
do i=1,n
print 50,(a(i,j),j=1,n+1)
50 format(4(2x,f6.2))
enddo
!back substitution
do i=n,1,-1
x(i)=a(i,n+1)/a(i,i)
do j=1,i-1
a(j,n+1)=a(j,n+1)-x(i)*a(j,i)
enddo;enddo
print*,"the solution is"
print 70,(x(i),i=1,n)
70 format(3(2x,f6.2))
;
end
ϯ
Download