fortran 90 - جامعة بابل | university of babylon 90 lecturer : rafel hekmat hameed...

3
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ƌŝƚĞ Ă ĨŽƌƚƌĂŶ ϵϬ ƉƌŽŐƌĂŵ ƚŽ find the solution of the following system of equations by Cramer’s rule. Calculate the determinant by subroutine program. 2x 1 + x 2 + x 3 = 3 x 1 x 2 x 3 = 0 x 1 + 2x 2 + x 3 = 0 program cramer_rule implicit none integer::i,j,d1,d2,d3 ,det integer,parameter::n=3 real,dimension(n,2*n-1)::a,a1,a2,a3 real,dimension(n)::b real::x1,x2,x3 data b/3,0,0/ read(*,*)((a(i,j),j=1,n),i=1,n) call determinant (a,det) a1=a;a2=a;a3=a do i=1,n a1(i,1)=b(i) enddo call determinant (a1,d1) x1=d1/det do i=1,n a2(i,2)=b(i) enddo call determinant (a2,d2)

Upload: trananh

Post on 20-Apr-2018

312 views

Category:

Documents


27 download

TRANSCRIPT

  • FORTRAN 90

    LLeeccttuurreerr :: RRaaffeell HHeekkmmaatt HHaammeeeedd UUnniivveerrssiittyy ooff BBaabbyylloonn

    SSuubbjjeecctt :: FFoorrttrraann 9900 CCoolllleeggee ooff EEnnggiinneeeerriinngg

    YYeeaarr :: SSeeccoonndd BB..SScc.. MMeecchhaanniiccaall EEnnggiinneeeerriinngg DDeepptt..

    Q /GA

    t find the solution of the following system of equations by

    Cramer's rule. Calculate the determinant by subroutine program.

    2x1 + x2 + x3 = 3 x1 x2 x3 = 0 x1 + 2x2 + x3 = 0

    program cramer_rule

    implicit none

    integer::i,j,d1,d2,d3 ,det

    integer,parameter::n=3

    real,dimension(n,2*n-1)::a,a1,a2,a3

    real,dimension(n)::b

    real::x1,x2,x3

    data b/3,0,0/

    read(*,*)((a(i,j),j=1,n),i=1,n)

    call determinant (a,det)

    a1=a;a2=a;a3=a

    do i=1,n

    a1(i,1)=b(i)

    enddo

    call determinant (a1,d1)

    x1=d1/det

    do i=1,n

    a2(i,2)=b(i)

    enddo

    call determinant (a2,d2)

  • x2=d2/det

    do i=1,n

    a3(i,3)=b(i)

    enddo

    call determinant (a3,d3)

    x3=d3/det

    print*,"x1=",x1 ,"x2=" ,x2 , "x3=",x3 ; end

    subroutine determinant (a,det)

    implicit none

    integer,parameter::n=3

    real,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)

    enddo ; enddo

    do i=1,n; d1=1;d2=1

    do j=1,n

    d1=d1*a(j,i+j-1)

    d2=d2*a(j,2*n-i-j+1)

    enddo

    det=det+d1-d2 ; enddo

    end

    Q /GB

    t

    A= IMPLICIT NONE

    /Ed'Z/DE^/KE

    /Ed'Z/DE^/KE

  • INTEGER::i, j, N

    DATA

    KE-

    call dd(n,a,b)

    -

    write(*,*) -

    enddo ; print*,"****************"

    enddo ; end

    SUBROUTINE dd(n,a,b)

    IMPLICIT NONE

    /Ed'Z/DE^/KE

    /Ed'Z/DE^/KE

    INTEGER::i, j, N

    DO iE-

    DO jE-

    B(i,jij-ji

    ENDDO ; ENDDO

    DO iE-

    DO jE-

    A(i,j)=B(i,j)

    ENDDO ; ENDDO ; END