Does Fortran have a built-in function to calculate the determinant?

In summary, the language Fortran does not have any functions that calculate determinants directly. The functionality is provided by a math library like the IMSL numerical math library and its det() function. Libraries can be shared by programs written in many languages, and they offer more flexibility in the future.
  • #1
Eclair_de_XII
1,083
91
TL;DR Summary
Some Google-searching has led me to believe that Fortran does not have a built-in function for calculating the determinant of a given matrix. I've found only source codes and external libraries that have been written for this purpose. Does Fortran just not have any functions that calculate determinants directly? If it does not, then why not?
Fortran:
program main
! use ! some library that defines the function to calculate the determinant of a given matrix
implicit none
real,dimension(2,2)::A
real::det_val
A(1,1)=1
A(2,2)=1
A(2,1)=0
A(1,2)=0
! det_val=det(A)
print *,det_val ! Should print 1.
end program main
 
Technology news on Phys.org
  • #2
Eclair_de_XII said:
Does Fortran just not have any functions that calculate determinants directly? If it does not, then why not?
The only Fortran 90 matrix intrinsics are; MATMUL, TRANSPOSE, and DOT_PRODUCT.
Other intrinsic functions are not usually needed, and so are better loaded from an external library.
 
  • #3
In general, no FORTRAN does not have that as a built-in. Instead the functionality is provided by a math library like the IMSL numerical math library and its det() function.

https://help.imsl.com/fortran/6.0/math/default.htm?turl=imslfortrannumericalmathlibrary.htm

https://help.imsl.com/fortran/6.0/math/default.htm?turl=imslfortrannumericalmathlibrary.htm

Experienced programmers will tend to use library functions over developing their own as it saves time in debugging and allows one to look at the bigger programming issues of a project.
 
  • #4
Long ago (1960s and 1970s), the FORTRAN programmers used libraries to assist in their numerical calculations. The IBM Scientific Subroutine Package (SSP) was a very well-programmed and documented set of subroutines that was bundled in with their sales packages.
The IMSL (International Mathematics and Statistics Library) for FORTRAN was published in 1970.
Then LINPACK and EISPACK became available for use on supercomputers (of that era).
There are a large variety of specialized needs (huge matrices, sparce matrices, complex matrices, etc) that were addressed by different well-documented libraries using advanced (for that era) numerical techniques.
It is conceivable that modern compilers for a language would have the ability to use the correct technique for a special situation, but I would verify that before I counted on it.
 
  • Informative
  • Like
Likes jedishrfu and berkeman
  • #5
Let me add that LINPACK and EISPACK were merged into LAPACK (Linear Algebra PACKage). The source code (Fortran 90) is available at http://www.netlib.org/lapack/
 
  • Like
Likes jedishrfu and FactChecker
  • #6
DrClaude said:
Let me add that LINPACK and EISPACK were merged into LAPACK (Linear Algebra PACKage). The source code (Fortran 90) is available at http://www.netlib.org/lapack/
DrClaude's example illustrates the kind of flexibility that you want in libraries. If you make the functions intrinsic to the language, you have less future flexibility. That is one reason to keep libraries separate from the programming language.

Another reason is that external libraries can be shared by programs written in many languages.
Python is very popular today, but if you dig into the details of Python packages, you may find external libraries written in C or FORTRAN.
 
  • Like
Likes FactChecker and jedishrfu

1. What is a determinant in Fortran?

A determinant is a numerical value that represents the unique properties of a square matrix in Fortran. It is used to calculate the inverse of a matrix, solve systems of linear equations, and determine if a matrix is invertible.

2. Does Fortran have a built-in function to calculate the determinant?

Yes, Fortran has a built-in function called DET to calculate the determinant of a matrix. It takes in a matrix as input and returns the determinant value as output.

3. How do I use the DET function in Fortran?

To use the DET function, you need to first declare a matrix variable and assign values to it. Then, you can call the DET function and pass the matrix variable as an argument. The function will return the determinant value, which you can store in a variable or use it directly in your code.

4. Can I use the DET function for non-square matrices?

No, the DET function in Fortran can only be used for square matrices. If you try to use it for a non-square matrix, you will get a compilation error.

5. Are there any other ways to calculate the determinant in Fortran?

Yes, there are other ways to calculate the determinant in Fortran, such as using a built-in LAPACK subroutine or implementing your own custom function. However, the DET function is the most commonly used and efficient method for calculating determinants in Fortran.

Similar threads

  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
463
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
6K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
12
Views
2K
Back
Top