Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

Determinant of a matrix in Fortran

I just learned Fortran recently and I am trying to compute the determinant of a matrix in Fortran. I was able to declare the matrix and print it out in Fortran. I know that if 2x2 matrix determinant would be mat(0,0) * mat(1,1) * mat(0,1) * mat(1,1). And if I want to calculate the determinant for a 3x3 matrix, I can reuse the logic in 2x2 matrix, right? But now I am trying to do a 5x5 matrix. I want to do it in a smart way instead of multiplying every element like "mat(0,0) * mat(1,1)... mat(5,5)"... How should I implement it without recursion?

Code:

program main
    Implicit None
    integer:: mat(5,5) ! Should I use Dimension() here?
    integer::i,j,k

    mat = reshape((/ 8, 9, 5, 4, 6 &
                  ,-3, -2, 2, 1, 3 &
                  , 1, 4, -5, -3, 2 &
                  , 3, 2, 6, 1, 3 &
                  , 4, -1, -2, -3, 5 &
                   /),(/5,5/))

    print , "The Matrix is: "
    do i = 1, 5
        print, (mat(j,i), j = 1, 5)
        write(,)
    end do

    print*, "The determinant of this martrix is: "
    print, det

    function det(mat), result(D)
    double::D

    !I'm still trying to finish it....

end program main
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...