Implementing Generalized Laguerre Polynomials in Fortran

In summary, the conversation discusses implementing a routine in Fortran to calculate generalized Laguerre polynomials. The code provided uses the gamma function for factorial calculations and there is a question about the presence of (l+k)! term and the use of the variable "r" as an array without indexing it like an array. There is also a mention of using recursive relations for numerical implementations and a question about the pros and cons of this approach.
  • #1
d4n1el
3
1
Hi!
Im trying to do some rather easy QM-calculations in Fortran.
To do that i need a routine that calculates the generalized Laguerre polynomials.

I just did the simplest implementation of the equation:
[tex]L^l_n(x)=\sum_{k=0}^n\frac{(n+l)!(-x^2)^k}{(n-k)!k!}[/tex]

I implemented this in the following way:
Code:
      SUBROUTINE LAGUERRE(n,l,r,u,arraylength)
      Implicit none
      INTEGER, INTENT(IN) :: arraylength,n
      real(kind=kind(0.d0)), INTENT(IN) :: l
      REAL(kind=kind(0.d0)), INTENT(IN),DIMENSION(arraylength) :: r
      REAL(kind=kind(0.d0)), INTENT(OUT),DIMENSION(arraylength) :: u
      REAL(kind=kind(0.d0)), DIMENSION(arraylength) :: temp
      Integer :: m
   
      temp=0.d0
      do m=0,n
         temp=temp+gamma(real(n)+l+1.0)*(-r)**m/
     +        (gamma(real(n)-real(m)+1.0)*gamma(l+real(m)+1.0)
     +        *gamma(real(m)+1.0))
      end do
      u=temp
      END SUBROUTINE LAGUERRE

The code is running and i do get results, but when i compare them with the results given in for example Mathematica, they seems quite strange.
So my questions are: Do you see some obvious mistakes? Do you think there are possibilities for numerical errors? (In such a case, do you have any advices on improvments?)

When i have been googling around, it looks like a lot of the numerical implementations are using recursive relations. What are the pro's and con's for doing this kind of calculation in such a manner?
 
Technology news on Phys.org
  • #2
What is gamma? Is it an array, a function, a subroutine?
 
  • #3
SteamKing said:
What is gamma? Is it an array, a function, a subroutine?
It looks like he's using it for factorial so it must the special function gamma (which reduces to factorial for integer values of the argument : gamma(n+1) = n! ).I just did the simplest implementation of the equation:
[tex]L^l_n(x)=\sum_{k=0}^n\frac{(n+l)!(-x^2)^k}{(n-k)!k!}[/tex]

I implemented this in the following way:
Code:
      SUBROUTINE LAGUERRE(n,l,r,u,arraylength)
      Implicit none
      INTEGER, INTENT(IN) :: arraylength,n
      real(kind=kind(0.d0)), INTENT(IN) :: l
      REAL(kind=kind(0.d0)), INTENT(IN),DIMENSION(arraylength) :: r
      REAL(kind=kind(0.d0)), INTENT(OUT),DIMENSION(arraylength) :: u
      REAL(kind=kind(0.d0)), DIMENSION(arraylength) :: temp
      Integer :: m
   
      temp=0.d0
      do m=0,n
         temp=temp+gamma(real(n)+l+1.0)*(-r)**m/
     +        (gamma(real(n)-real(m)+1.0)*gamma(l+real(m)+1.0)
     +        *gamma(real(m)+1.0))
      end do
      u=temp
      END SUBROUTINE LAGUERRE

Do you see some obvious mistakes?

Why are "r" and "u" declared as arrays yet you don't index them like arrays?

Where did the (l+k)! term come from?
Why isn't "r" squared.
 
Last edited:

1. What are Generalized Laguerre Polynomials and how are they used in Fortran?

Generalized Laguerre Polynomials are a set of mathematical functions used in Fortran to solve problems related to quantum mechanics, heat transfer, and other areas of physics and engineering. They are a generalization of the standard Laguerre Polynomials and are used to approximate complex functions and solve differential equations.

2. How do I implement Generalized Laguerre Polynomials in Fortran?

To implement Generalized Laguerre Polynomials in Fortran, you will need to define the appropriate parameters and variables, use the appropriate Fortran functions and subroutines, and follow the proper syntax for your specific problem. It is recommended to consult with a Fortran expert or refer to online resources for specific implementation instructions.

3. Can Generalized Laguerre Polynomials be used in parallel computing?

Yes, Generalized Laguerre Polynomials can be used in parallel computing. Fortran has built-in functions and libraries for parallel computing, such as OpenMP and MPI, which can be used to speed up the computation of Generalized Laguerre Polynomials.

4. What are some common mistakes when implementing Generalized Laguerre Polynomials in Fortran?

Some common mistakes when implementing Generalized Laguerre Polynomials in Fortran include using incorrect variable types, not properly defining the parameters, and not following the appropriate syntax for your specific problem. It is important to carefully check your code for any errors and consult with a Fortran expert if needed.

5. Is there a Fortran library or module for Generalized Laguerre Polynomials?

Yes, there are several Fortran libraries and modules available for Generalized Laguerre Polynomials, such as the GNU Scientific Library (GSL) and the Fortran Library for Approximate Solutions of Differential Equations (FLAPACK). These libraries offer pre-defined functions and subroutines for efficient computation of Generalized Laguerre Polynomials.

Similar threads

  • Programming and Computer Science
Replies
4
Views
588
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top